哈巴狗 + webpack-dev-server
Pug + webpack-dev-server
我正在使用 webpack v4,我正在尝试将 Pug
与 webpack-dev-server
一起使用,但是当我 运行 webpack-dev-server --mode development
它不提供编译 Pug
。请帮忙。我不知道该怎么办。感谢您的回复。这是我的配置:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/js/main.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.pug$/,
use: {
loader: 'pug-loader',
options: {
pretty: true
}
}
}
]
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
hot: true,
open: true,
progress: true
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/templates/pages/index.pug'),
inject: false
})
]
};
你好,你必须在 HtmlWebpackPlugin 上指定文件名,这样你才能拥有你的
html 服务于 localhost:3000 或 localhost:3000/index.html
devServer: {
...,
port: 3000
}
...
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/templates/pages/index.pug'),
filename: 'index.html'
})
]
我正在使用 webpack v4,我正在尝试将 Pug
与 webpack-dev-server
一起使用,但是当我 运行 webpack-dev-server --mode development
它不提供编译 Pug
。请帮忙。我不知道该怎么办。感谢您的回复。这是我的配置:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/js/main.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.pug$/,
use: {
loader: 'pug-loader',
options: {
pretty: true
}
}
}
]
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
hot: true,
open: true,
progress: true
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/templates/pages/index.pug'),
inject: false
})
]
};
你好,你必须在 HtmlWebpackPlugin 上指定文件名,这样你才能拥有你的 html 服务于 localhost:3000 或 localhost:3000/index.html
devServer: {
...,
port: 3000
}
...
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/templates/pages/index.pug'),
filename: 'index.html'
})
]