Webpack 网页包-html网页包插件-一个文件名-多重插入
是否可以使用html网页包插件在头部和身体中分别编写一些块? 这是我的html网页包插件配置:Webpack 网页包-html网页包插件-一个文件名-多重插入,webpack,html-webpack-plugin,Webpack,Html Webpack Plugin,是否可以使用html网页包插件在头部和身体中分别编写一些块? 这是我的html网页包插件配置: var HtmlWebpackPluginConfigIndex = { template: path.join(__dirname, 'src/core/server/views', 'index.dust'), filename: 'core/server/views/index.dust', hash: true, chunksSortMode: 'none' // chun
var HtmlWebpackPluginConfigIndex = {
template: path.join(__dirname, 'src/core/server/views', 'index.dust'),
filename: 'core/server/views/index.dust',
hash: true,
chunksSortMode: 'none'
// chunks: ['core/public/js/vendor']
};
当我将copy与此配置一起使用但与更改的块一起使用时:
var HtmlWebpackPluginConfigIndex = {
template: path.join(__dirname, 'src/core/server/views', 'index.dust'),
filename: 'core/server/views/index.dust',
hash: true,
inject: 'head',
chunksSortMode: 'none'
chunks: ['core/public/js/vendor']
};
var HtmlWebpackPluginConfigIndex2 = {
template: path.join(__dirname, 'src/core/server/views', 'index.dust'),
filename: 'core/server/views/index.dust',
hash: true,
inject: 'body',
chunksSortMode: 'none'
chunks: ['core/public/js/app']
};
....
new HtmlWebpackPlugin(HtmlWebpackPluginConfigIndex);
new HtmlWebpackPlugin(HtmlWebpackPluginConfigIndex2);
Webpack只为html Webpack插件应用最后一个块。您可以尝试分叉项目,然后像这样修改代码:
html网页包插件索引.js:
HtmlWebpackPlugin.prototype.generateAssetTags = function (assets) {
...
// Add scripts to body or head
// <<< You would add this bit >>>
if (!! this.options.headScripts) {
var hScripts = this.options.headScripts;
head = head.concat(scripts.filter((s) => {
var src = s.attributes.src;
return hScripts.indexOf(src) > -1;
}));
body = body.concat(scripts.filter((s) => {
var src = s.attributes.src;
return hScripts.indexOf(src) < 0;
}));
// <<< to here (and the following "else" in front of the if) >>>
else if (this.options.inject === 'head') {
...
}
您可以尝试分叉项目,然后像这样修改代码:
html网页包插件索引.js:
HtmlWebpackPlugin.prototype.generateAssetTags = function (assets) {
...
// Add scripts to body or head
// <<< You would add this bit >>>
if (!! this.options.headScripts) {
var hScripts = this.options.headScripts;
head = head.concat(scripts.filter((s) => {
var src = s.attributes.src;
return hScripts.indexOf(src) > -1;
}));
body = body.concat(scripts.filter((s) => {
var src = s.attributes.src;
return hScripts.indexOf(src) < 0;
}));
// <<< to here (and the following "else" in front of the if) >>>
else if (this.options.inject === 'head') {
...
}