【发布时间】:2018-04-16 12:46:11
【问题描述】:
我正在使用 Webpack-4。当前的行为是,当 webpack-dev-server 运行时,/build 下的文件根本不会更新,而是显示文件目录。
如果我删除 /build 下的文件,webpack-dev-server 将无法获取 /。我想,它应该从内存中加载它们。
const HtmlWebPackPlugin = require("html-webpack-plugin");
const htmlPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
});
const path = require('path');
module.exports = {
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build/'),
},
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["env","react"]
}
}
},
{
test: /\.html$/,
use: [{
loader: "html-loader",
options: {
minimize: true
}
}]
}
]
},
plugins: [
htmlPlugin
],
devServer: {
contentBase: "./build/",
port: 5555
}
}
【问题讨论】:
-
请在module.exports(输出配置上方)中定义入口点(入口:'./main.js',)
-
Webpack 4 有一个默认入口 /src/index.js
标签: webpack webpack-dev-server