V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
a1248499257

webpack5 配置引入一些 node polyfill 模块时,最终打包出来的 umd 代码用不了

  •  
  •   a1248499257 · May 23, 2022 · 1116 views
    This topic created in 1447 days ago, the information mentioned may be changed or developed.

    因为项目中引用的一些库有用到 node 的 path 模块,所以我根据 webpack5 的文档说明做了如下操作:

      resolve: {
        extensions: ['.js', '.jsx',......],
        fallback: {
          stream: false,
          crypto: false,
          path: require.resolve('path-browserify'),
        },
      },
    

    这是打包的 output 代码:

     output: {
        filename,
        library,
        path: path.resolve(moduleDir, 'umd'),
        libraryTarget: 'umd',
      }
    

    打包的页面是 react 代码,我在 index 的入口文件中输出了一个这样的东西:

    const Component = () => {xxx};
    
    export default Component;
    

    在去除掉包含 path 模块的库时是可以正常使用,加上之后就报错了,求路过的大佬指点迷津

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3451 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 10:42 · PVG 18:42 · LAX 03:42 · JFK 06:42
    ♥ Do have faith in what you're doing.