我无法让 webpack 开发服务器正常工作。我认为问题是它在内存中生成的编译代码没有清除。我不知道我哪里错了。
我的配置文件是:
var path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: ['babel-polyfill', './src/js/index.js'],
output: {
path: path.join(__dirname, 'dist'),
publicPath: "/",
filename: 'js/index.js'
},
devServer: {
contentBase: '/dist'
},
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader']
},
{
test: /\.scss$/,
use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/styles.css',
}),
new HtmlWebpackPlugin({
inject: false,
hash: true,
template: './src/index.html',
filename: 'index.html'
})
]
}
我的脚本:
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
我想要的是 webpack 开发服务器允许我在工作时实时重新加载,然后使用 build 来实际编译我的代码。 问题是,一旦我使用 dev 或 build,并且创建了 dist 文件,webpack dev 服务器就会停止工作 - 即使我删除了 dist 文件。我根本不知道如何让它发挥作用。非常感谢任何帮助。
谢谢,R
也许您没有在监视模式下运行 webpack 捆绑器(不是 webpack-dev-server)
使用观看模式
{
watch: true
}
并同时安装软件包
npm i-D 同时进行更新您的
start
脚本
{
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"dev:server": "webpack-dev-server",
"start": "concurrently \"npm:dev\" \"npm:dev:server\""
}