我正在一个项目中使用pugjs作为模板引擎。
和Webpack4作为bundler。
当我改变
.pug
我必须手动重新运行编译器的文件。
关于如何设置它以便编译器在编辑文件后运行,有什么帮助吗?.
web包.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
entry: {
main: './src/index.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[chunkhash].js'
},
module: {
rules: [
{
test: /\.scss$/,
use: ['style-loader', MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
exclude: [/images/],
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './assets/fonts/'
}
}]
},
{
test: /\.(png|svg|jpg|gif)$/,
exclude: [/fonts/],
use: {
loader: 'file-loader',
options: {
outputPath: './assets/images/',
name: '[name].[ext]',
}
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.pug$/,
use: ['html-loader?interpolate', 'pug-html-loader']
}
]
},
plugins: [
new CleanWebpackPlugin('dist', {}),
new MiniCssExtractPlugin({
filename: 'style.[contenthash].css',
}),
new HtmlWebpackPlugin({
// inject: false,
hash: true,
template: './src/index.pug',
filename: 'index.html',
title:'home'
}),
new HtmlWebpackPlugin({
filename: 'contact.html',
hash: true,
template: './src/contact.pug',
// inject: false,
title: 'contact'
}),
new WebpackMd5Hash()
]
};
更新1
我用的时候它很好用
webpack
命令,但它不会为sue创建dev服务器
但当我使用
webpack-dev-server
它创建了服务器,但没有在终端中创建dist文件夹而没有错误!