Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 网页包-html网页包插件-一个文件名-多重插入_Webpack_Html Webpack Plugin - Fatal编程技术网

Webpack 网页包-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

是否可以使用html网页包插件在头部和身体中分别编写一些块?

这是我的html网页包插件配置:

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') {
   ...
 }