简体   繁体   English

Webpack 编译多个 JS 库时将 JS 留在缓存文件中

[英]Webpack leaves JS in cache file when compiling multiple JS libraries

I'm trying to configure Webpack so that it compiles multiple JS files.我正在尝试配置 Webpack,以便它编译多个 JS 文件。 But when I do this the majority of JS is left in a cache file, the contents of which isn't included in my files.但是当我这样做时,大部分 JS 都留在缓存文件中,其内容不包含在我的文件中。

Generated files:生成的文件:

js
-- theme--01.js (134kb)
-- theme--02.js (134kb)
-- theme--03.js (134kb)
-- theme--04.js (134kb)
-- themevendors-lib_common_scripts_global_libraries_js-lib_common_scripts_global_smoothscroll_min_js--8bace3.js (753kb)

When I generate one file it works correctly:当我生成一个文件时,它可以正常工作:

js
-- theme--01.js (879kb)

How my entry points are configured:我的入口点是如何配置的:

entry: {
        "--01": path.resolve(process.cwd(), 'src', 'theme--01.ts'),
        "--02": path.resolve(process.cwd(), 'src', 'theme--02.ts'),
        "--03": path.resolve(process.cwd(), 'src', 'theme--03.ts'),
        "--04": path.resolve(process.cwd(), 'src', 'theme--04.ts'),
    },

Here's my complete Webpack config on JSfiddle as StackOverflow won't let me paste the whole thing here: https://jsfiddle.net/charlievaughan/rpeztbLj/这是我在 JSfiddle 上的完整 Webpack 配置,因为 StackOverflow 不允许我在这里粘贴整个内容: https ://jsfiddle.net/charlievaughan/rpeztbLj/

I need to generate multiple files from the same codebase for different locales and to optimise page-load speeds / Lighthouse scores.我需要从相同的代码库为不同的语言环境生成多个文件,并优化页面加载速度/灯塔分数。

Using Webpack v5.62.1使用 Webpack v5.62.1

I fixed this issue by removing the following from my Webpack config:我通过从我的 Webpack 配置中删除以下内容解决了这个问题:

splitChunks: {
  chunks: 'all'
}

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

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