我正在使用 webpack:5.71.0 webpack-cli:4.9.2 webpack-dev-server 4.8.1
在我的 webpack.config.js 中
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/index.js',
mode: 'development',
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
options: { presets: ["@babel/env"] }
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
resolve: { extensions: ['*', '.js', '.jsx'] },
output: {
path: path.resolve(__dirname, 'dist/'),
publicPath: '/dist/',
filename: './bundle.js'
},
devServer: {
static: path.join(__dirname, 'public/'),
publicPath: 'http://localhost:3000/dist/',
port: 3000,
hot: "only"
},
plugins: [new webpack.HotModuleReplacementPlugin()] …Run Code Online (Sandbox Code Playgroud)