我很难想象我如何利用Webpack的DllPlugin/DllReferencePlugin,同时也使用Grunt的建筑。对于那些不知情的人,DllPlugin创建了一个单独的包,可以与其他包共享。它还创建一个清单文件(重要)来帮助链接。然后,DllReferencePlugin在构建时被另一个包使用,以获取先前制作的DllPlugin包。为此,需要前面创建的清单文件。
在Grunt中,这需要在咕噜甚至运行之前创建清单文件,不是吗?下面是一个简化的代码示例:
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
// 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')
})
]
};如果您查看第二节,webpack.app.js,我已经评论了所有的事情似乎都失败了。为了使DllReferencePlugin工作,它需要来自DllPlugin的清单文件,但是在Grunt工作流中,grunt将在grunt本身初始化时加载这两种配置,从而导致manifest: require('./bundles/my_dll-manifest.json')行失败,因为构建webpack.dll.js的上一步manifest: require('./bundles/my_dll-manifest.json')尚未完成,这意味着清单还不存在。
发布于 2016-08-04 09:24:43
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')
})
]
};https://stackoverflow.com/questions/36971436
复制相似问题