如何在html-webpack-plugin中获取块{scripts}

时间:2019-09-16 03:43:13

标签: angular webpack html-webpack-plugin

我遇到了一个问题。我需要用角度构建自定义index.html文件。我决定使用angular-builders和html-webpack-plugin。它工作正常,但html-webpack-plugin结果中不包含一个块。

有我的配置: custom-webpack.config.js

000

angular.json

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    plugins: [
        new HtmlWebpackPlugin({
          inject: false,
          template: '../Views/Documents/_LoaderTemplate.cshtml',
          filename: '../../../Views/Documents/_AngularLoader.cshtml'
        })
      ]
};

我有html-webpack-plugin模板

      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "path": "./custom-webpack.config.js"
            },
            ...
            "scripts": [
              "src/app/division/division-draw/lines.js",
              "src/app/division/division-draw/mouse_control.js",
              "src/app/division/division-draw/Screen.js"
              ]
          },
          ...

构建结果不包含scripts.js,但是构建结果脚本具有该脚本。

<%= JSON.stringify(htmlWebpackPlugin) %>

<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>

我像这样使用package.json

chunk {main} main.js, main.js.map (main) 175 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 338 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 33.1 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 169 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 6.78 MB [initial] [rendered]

我想将所有构建的脚本(通过angular-cli)包括到我的结果输出文件 "html-webpack-plugin": "^3.2.0", "@angular-devkit/build-angular": "0.13.9", "@angular-builders/custom-webpack": "7.5.2", "@angular/cli": "~7.0.3", "@angular/compiler-cli": "~7.0.0", "@angular/common": "^7.0.0", "@angular/compiler": "^7.0.0", "@angular/core": "^7.0.0", "@angular/forms": "^7.0.0", "@angular/http": "~7.0.0", "webpack": "^4.40.0", "webpack-cli": "^3.3.8"

1 个答案:

答案 0 :(得分:0)

尝试使用<%= htmlWebpackPlugin.tags.bodyTags%>