无法集成 Laravel 与 underscore-template-loader 混合
Cant integrate Laravel Mix with underscore-template-loader
我们正在努力打造 html 妆容。我们有下一个文件:
resources/assets/htmlSrc/example.html:
<html lang="en">
<body>
<%= "test" %>
@require('partial/header.html')
<div>Body</div>
</body>
</html>
resources/assets/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
节。怎么了?
使用 rules
而不是 loaders
工作:
webpackConfig = {
module: {
rules: [
{
test: /\.html$/,
loader: 'underscore-template-loader'
}
]
},
plugins: [
new CleanWebpackPlugin(path.join(__dirname, 'resources/assets/htmlResult'))
]
};
我们正在努力打造 html 妆容。我们有下一个文件:
resources/assets/htmlSrc/example.html:
<html lang="en">
<body>
<%= "test" %>
@require('partial/header.html')
<div>Body</div>
</body>
</html>
resources/assets/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
节。怎么了?
使用 rules
而不是 loaders
工作:
webpackConfig = {
module: {
rules: [
{
test: /\.html$/,
loader: 'underscore-template-loader'
}
]
},
plugins: [
new CleanWebpackPlugin(path.join(__dirname, 'resources/assets/htmlResult'))
]
};