V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
a1248499257
V2EX  ›  前端开发

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

  •  
  •   a1248499257 · 2022-05-23 17:57:11 +08:00 · 672 次点击
    这是一个创建于 717 天前的主题,其中的信息可能已经有所发展或是发生改变。

    因为项目中引用的一些库有用到 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 模块的库时是可以正常使用,加上之后就报错了,求路过的大佬指点迷津

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3307 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:47 · PVG 21:47 · LAX 06:47 · JFK 09:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.