我们正在尝试构建html化妆。我们有下一个文件:
资源/资产/ htmlSrc / example.html的:
<html lang="en">
<body>
<%= "test" %>
@require('partial/header.html')
<div>Body</div>
</body>
</html>
资源/资产/ htmlSrc /部分/ header.html中:
<div>test header</div>
我们的 webpack.mix.js :
const {mix} = require('laravel-mix');
var HtmlWebpackPlugin = require('html-webpack-plugin')
var CleanWebpackPlugin = require('clean-webpack-plugin')
var path = require('path')
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.browserSync('http://myhost');
webpackConfig = {
module: {
loaders: [
{
test: /\.html$/,
loader: 'underscore-template-loader'
}
]
},
plugins: [
new CleanWebpackPlugin(path.join(__dirname, 'resources/assets/htmlResult'))
]
};
/**
* Mackup rendering
*/
webpackConfig.plugins.push(new HtmlWebpackPlugin({
filename: path.join(__dirname, 'resources/assets/htmlResult/example.html'),
template: './resources/assets/htmlSrc/example.html'
}));
mix.webpackConfig(webpackConfig);
但结果文件资源/资产/ htmlResult / example.html:看起来并不像预期的那样:
<html lang="en"><head><link href="/css/app.css" rel="stylesheet"></head>
<body>
<%= "test" %>
@require('partial/header.html')
<div>Body</div>
<script type="text/javascript" src="/js/app.js"></script></body>
</html>
看起来跳过了loaders
部分。有什么问题?
答案 0 :(得分:0)
使用rules
代替loaders
:
webpackConfig = {
module: {
rules: [
{
test: /\.html$/,
loader: 'underscore-template-loader'
}
]
},
plugins: [
new CleanWebpackPlugin(path.join(__dirname, 'resources/assets/htmlResult'))
]
};