使用 HTML Webpack 插件的 Pug 模板
Pug templates with the HTML Webpack Plugin
我目前正在尝试获取 Pug 模板 运行 HTML Webpack Plugin。我按照他们的说明使用自定义模板引擎,例如 Handlebars,或者在我的例子中是 Pug。当我执行它时,出现此错误:
ERROR in ./~/html-webpack-plugin/lib/loader.js!./src/index.pug
Module build failed: Error: Cannot find module 'pug'
我当前的配置如下所示:
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: {
global: './src/assets/scripts/global.js',
index: './src/assets/scripts/index.js',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist/js'),
publicPath: '/assets/js/',
},
module: {
rules: [
{test: /\.pug$/, use: 'pug-loader'},
],
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.pug',
filename: 'index.html',
chunks: ['global', 'index'],
}),
],
};
有什么建议吗?
我必须自己手动安装 pug
包。
你必须这样做。如果需要,您可以添加块。
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(__dirname, './src/index.pug')
});
我目前正在尝试获取 Pug 模板 运行 HTML Webpack Plugin。我按照他们的说明使用自定义模板引擎,例如 Handlebars,或者在我的例子中是 Pug。当我执行它时,出现此错误:
ERROR in ./~/html-webpack-plugin/lib/loader.js!./src/index.pug
Module build failed: Error: Cannot find module 'pug'
我当前的配置如下所示:
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: {
global: './src/assets/scripts/global.js',
index: './src/assets/scripts/index.js',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist/js'),
publicPath: '/assets/js/',
},
module: {
rules: [
{test: /\.pug$/, use: 'pug-loader'},
],
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.pug',
filename: 'index.html',
chunks: ['global', 'index'],
}),
],
};
有什么建议吗?
我必须自己手动安装 pug
包。
你必须这样做。如果需要,您可以添加块。
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(__dirname, './src/index.pug')
});