0

我们试图构建 html 化妆。我们有下一个文件:

资源/资产/htmlSrc/example.html

<html lang="en">
<body>
    <%= "test" %>
    @require('partial/header.html')
    <div>Body</div>
</body>
</html>

资源/资产/htmlSrc/partial/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);

但是结果文件resources/assets/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被跳过了。怎么了?

4

1 回答 1

0

使用rules而不是loaders

webpackConfig = {
    module: {
        rules: [
            {
                test: /\.html$/,
                loader: 'underscore-template-loader'
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(path.join(__dirname, 'resources/assets/htmlResult'))
    ]
};
于 2017-05-03T06:23:52.003 回答