-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
42 lines (42 loc) · 1.48 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var { CleanWebpackPlugin } = require('clean-webpack-plugin');// 用于删除/清理构建文件夹的 webpack 插件。 默认情况下,此插件将output.path在每次成功重建后删除 webpack目录中的所有文件,以及所有未使用的 webpack 资产。
var friendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin'); // 友好提示
module.exports = {
entry: [
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
path.resolve(__dirname, './src/index.js'),
],
output: {
path: path.resolve(__dirname, './build'),
filename: '[name].bundle.js',
publicPath: '/',
},
mode: 'development',
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
devtool: 'inline-source-map', // 配置source-map
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './public/index.html'),
filename: 'index.html'
}),
new CleanWebpackPlugin(),
new friendlyErrorsWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(), // 启动HMR
new webpack.NoEmitOnErrorsPlugin() // 在编译出现错误时,使用 NoEmitOnErrorsPlugin 来跳过输出阶段。这样可以确保输出资源不会包含错误。
]
}