[英]Grunt, Webpack, and the DllPlugin
I'm having trouble visualizing how I can leverage the DllPlugin/DllReferencePlugin
with Webpack while also using Grunt for the building.我无法想象如何在
DllPlugin/DllReferencePlugin
利用DllPlugin/DllReferencePlugin
,同时还使用 Grunt 进行构建。 For those without knowledge, the DllPlugin
creates a separate bundle that can be shared with other bundles.对于那些不知道的人,
DllPlugin
创建了一个单独的包,可以与其他包共享。 It also creates a manifest file (important) to help with the linking.它还创建一个清单文件(重要)以帮助进行链接。 Then, the
DllReferencePlugin
is used by another bundle when building to grab the previous made DllPlugin Bundle .然后,另一个包在构建时使用
DllReferencePlugin
来获取先前制作的DllPlugin Bundle 。 To do this, it requires the manifest file created previously.为此,它需要先前创建的清单文件。
In Grunt, this would require the manifest file created before grunt even runs, no?在 Grunt 中,这需要在 grunt 运行之前创建清单文件,不是吗? Heres a simplified code example:
这是一个简化的代码示例:
webpack.dll.js webpack.dll.js
// My Dll Bundles, which creates
// - ./bundles/my_dll.js
// - ./bundles/my_dll-manifest.json
module.exports = {
entry: {
my_dll : './dll.js'
},
// where to send final bundle
output: {
path: './bundles',
filename: "[name].js"
},
// CREATES THE MANIFEST
plugins: [
new webpack.DllPlugin({
path: "./bundles/[name]-manifest.json",
name: "[name]_lib"
})
]
};
webpack.app.js webpack.app.js
// My Referencing Bundle, which includes
// - ./bundles/app.js
module.exports = {
entry: {
my_app : './app.js'
},
// where to send final bundle
output: {
path: './bundles',
filename: "[name].js"
},
// SETS UP THE REFERENCE TO THE DLL
plugins: [
new webpack.DllReferencePlugin({
context: '.',
// IMPORTANT LINE, AND WHERE EVERYTHING SEEMS TO FAIL
manifest: require('./bundles/my_dll-manifest.json')
})
]
};
If you look in the second section, webpack.app.js , I've commented where everything would seem to fail in grunt.如果您查看第二部分webpack.app.js ,我已经评论过一切似乎都在咕噜声中失败的地方。 For the DllReferencePlugin to work, it needs the manifest file from the DllPlugin, but in a Grunt workflow, grunt will load both of these configurations on initialization of grunt itself, causing the
manifest: require('./bundles/my_dll-manifest.json')
line to fail, because the previous grunt step that builds webpack.dll.js
has not completed, meaning manifest does not yet exist.为了让 DllReferencePlugin 工作,它需要来自 DllPlugin 的清单文件,但在 Grunt 工作流中,grunt 将在 grunt 自身初始化时加载这两个配置,导致
manifest: require('./bundles/my_dll-manifest.json')
行失败,因为之前构建webpack.dll.js
grunt 步骤尚未完成,这意味着清单尚不存在。
var path = require("path");
var util = require('util')
var webpack = require("webpack");
var MyDllReferencePlugin = function(options){
webpack.DllReferencePlugin.call(this, options);
}
MyDllReferencePlugin.prototype.apply = function(compiler) {
if (typeof this.options.manifest == 'string') {
this.options.manifest = require(this.options.manifest);
}
webpack.DllReferencePlugin.prototype.apply.call(this, compiler);
};
// My Referencing Bundle, which includes
// - ./bundles/app.js
module.exports = {
entry: {
my_app : './app.js'
},
// where to send final bundle
output: {
path: './bundles',
filename: "[name].js"
},
// SETS UP THE REFERENCE TO THE DLL
plugins: [
new MyDllReferencePlugin({
context: '.',
// IMPORTANT LINE, AND WHERE EVERYTHING SEEMS TO FAIL
manifest: path.resolve('./bundles/my_dll-manifest.json')
})
]
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.