2016-12-13 32 views
0
new webpack.ProvidePlugin({ 
     util: path.join(src, 'util.js'), 
     API: path.join(src, 'api.js') 
    }) 

webpack编译后,有很多chunksdist我的项目目录。Webpack,DedupePlugin不支持代码拆分和ProvidePlugin?

每个chunk使用APIUtil并且每个chunk具有APIUtil代码。看来DedupePlugin无法正常工作。

我想将APIUtil解压缩到一个单一chunk或添加条目bundle文件。

我该怎么办?非常感谢。

回答

0

听起来像是你正在寻找的CommonsChunkPlugin

entry: { 
api: path.join(src, 'api.js'), 
utils: path.join(src, 'util.js'), 
app: "./entry" 
} 

... 

new CommonsChunkPlugin({ 
    name: "commons", 
    // (the commons chunk name) 

    filename: "commons.js", 
    // (the filename of the commons chunk) 

    chunks: ["api", "util"], 
    // (Only use these entries) 
}) 

只要确保你的主应用程序

<script src="commons.js" charset="utf-8"></script> 
<script src="entry.bundle.js" charset="utf-8"></script> 
+0

呀,谢谢你之前装入普通块。但是我想用'ProvidePlugin'来提供全局模块变量。 而且不想把'api'和'util'输入。 – novaline

+0

我认为有unneccssary使用'CommonsChunkPlugin',只需设置这样的:'条目:{公地: 'API', 'UTIL']}',但我的情况下,''CommonsChunkPlugin'可以options.chunks'是'''1.chunk','2.chunk','3.chunk'....]'。 – novaline