admin管理员组文章数量:1304820
I have a problem with the way webpack bundles my files.
Consider the following files:
// utils/index.js
export const funcA = () => {
return "funcA in CompA";
};
export const funcB = () => {
return "funcB in CompB";
};
// components/ComponentA.js
import { funcA } from "@/utils";
export const ComponentA = () => {
return funcA();
};
// components/ComponentB.js
import { funcB } from "@/utils";
export const ComponentB = () => {
return funcB();
};
Also ComponentA
is in one page and ComponentB
is in another page.
You would expect webpack to place funcA
in ComponentA
chunk and funcB
in ComponentB
chunk however this isn't what happening. Instead the whole utils file is placed in both ComponentA
and ComponentB
chunk although the other function is not used.
I have placed "sideEffects": false
in my package.json
file. Also i have added this webpack configs:
const nextConfig = {
webpack: (config, { isServer }) => {
config.optimization.splitChunks.chunks = "all";
return config;
},
};
None of this has helped. Can anyone please guide me what is the problem and how can i fix it?
版权声明:本文标题:javascript - How to configure Webpack in Next.js to avoid chunk duplication for shared files? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741783083a2397423.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论