简体   繁体   English

从 webpack4 -> webpack5 迁移,捆绑文件在被请求时会有错误的 url?

[英]Migration from webpack4 -> webpack5, bundled file will have a faulty url when it gets requested?

I'm currently working on a migration from webpack4 to webpack5.我目前正在从 webpack4 迁移到 webpack5。 I have problems with the URL to the bundled JS (in my case client.js).我对捆绑的 JS(在我的例子中是 client.js)的 URL 有问题。

错误的 url 到 client.js 文件

This request should be two different ones.这个请求应该是两个不同的请求。 Here is an image from how it was with webpack4:这是使用 webpack4 的图像: 在此处输入图像描述

This is the entry for the client:这是客户端的条目:


// ...

name: 'client',
target: 'web',
devtool: 'source-map',
entry: {
  client: ['@babel/polyfill', './src/client.js'],
},

// ...

This is the output:这是输出:

// ...

output: {
  path: resolvePath(BUILD_DIR, 'public/assets'),
  publicPath: '/assets/',
  pathinfo: isVerbose,
  filename: isDebug ? '[name].js' : '[name].[chunkhash:8].js',
  chunkFilename: isDebug ? '[name].chunk.js' : '[name].[chunkhash:8].chunk.js',
},

// ...

I have also set organization.splitChunks.cacheGroups as follows:我还设置了organization.splitChunks.cacheGroups如下:

optimization: {
  splitChunks: {
    cacheGroups: {
      commons: {
        chunks: 'initial',
        test: /[\\/]node_modules[\\/]/,
        name: 'vendors',
      },
    },
  },
},

Since I was not the person who initially did this config file it's kind of hard to debug, I'm shooting wild here.由于我不是最初执行此配置文件的人,因此很难调试,因此我在这里狂奔。 And the file is fairly large, I've just pasted the bits I believe are important.而且文件相当大,我刚刚粘贴了我认为很重要的部分。 If you think the issue could be because of another configuration property, feel free to share.如果您认为问题可能是由于另一个配置属性,请随时分享。

Anyone know why this is happening and why this happens?任何人都知道为什么会发生这种情况以及为什么会发生这种情况?

Thanks in advance!提前致谢!

@AKX ( Migration from webpack4 -> webpack5, bundled file will have a faulty url when it gets requested? ) @AKX( 从 webpack4 -> webpack5 迁移,捆绑文件在被请求时会有错误的 url?

You certainly guided me to the problem here.你当然引导我解决这里的问题。 After fixing this error I accidentally created a nested array in chunk-manifest.json .修复此错误后,我不小心在chunk-manifest.json中创建了一个嵌套数组。 The content should be:内容应该是:

{
  "client": [
    "/assets/vendors.chunk.js",
    "/assets/client.js"
  ]
}

Instead I screwed up while converting the Set to an array (to be able to run filter on it) so the content was instead:相反,我在将Set转换为数组(以便能够在其上运行filter )时搞砸了,所以内容改为:

{
  "client": [
    [
      "/assets/vendors.chunk.js",
      "/assets/client.js"
    ]
  ]
}

The nested array resulted in this concatenation so the URL went with a comma instead as two different sources.嵌套数组导致了这种连接,因此 URL 以逗号作为两个不同的来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM