我正在创建两个webpack包:vendors.dll.js和client.js.
供应商是使用webpack.DllPlugin创建的.它包括所有前端模块node_modules/.这很有效.
客户包括我的应用代码.它使用webpack.DllReferencePlugin委托给供应商的DLL.这很有效.
客户端运行所有的JavaScript通过babel-loader.我正在使用babel-plugin-transform-runtime插件,这会导致整个core-js内容被编译到我的客户端包中.我更喜欢将这些东西移到DLL中,因为它不会像应用程序那样频繁地改变.
AFAIK你不能只包含babel-runtime在DLL中(我试过这个).从我可以告诉核心-js的东西加载更直接,而babel-runtime甚至没有main我能说的东西.
Babel:6.x Webpack:1.x
如果需要解决问题,很高兴提供实际配置.
您可以扫描所需的目录并包含所有文件,如下所示。
const readDir = dir => {
const result = [];
fs.readdirSync(dir).map(file => {
if (file.match(/\.js$/)) result.push(`${dir.replace('./node_modules/', '')}/${file}`);
else if (fs.lstatSync(dir + '/' + file).isDirectory()) result.push(...readDir(dir + '/' + file));
});
return result
}
const babelRuntimeHelpers = readDir('./node_modules/babel-runtime/helpers');
const babelRuntimeCoreJs = readDir('./node_modules/babel-runtime/core-js');
Run Code Online (Sandbox Code Playgroud)
然后将它们添加到您的供应商数组中:
vendor: [
...babelRuntimeHelpers,
...babelRuntimeCoreJs,
...rest
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
562 次 |
| 最近记录: |