我遇到了一个问题。我需要使用angular构建自定义index.html文件。我决定使用angular-builders和html-webpack-plugin。它运行良好,但有一块不包括在html-webpack-plugin结果中。
下面是我的配置: custom-webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: '../Views/Documents/_LoaderTemplate.cshtml',
filename: '../../../Views/Documents/_AngularLoader.cshtml'
})
]
};angular.json
"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"
]
},
...我有模板的html-webpack-插件
<%= JSON.stringify(htmlWebpackPlugin) %>
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>构建的结果不包含scripts.js,但构建的结果脚本包含它。
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]我像这样使用package.json
"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"我希望将所有构建的脚本(通过angular-cli)包含到我的结果输出文件filename: '../../../Views/Documents/_AngularLoader.cshtml'中
发布于 2020-05-07 10:09:07
尝试使用<%= htmlWebpackPlugin.tags.bodyTags %>
https://stackoverflow.com/questions/57950109
复制相似问题