-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathwebpack.config.js
69 lines (65 loc) · 2.38 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const path = require('path')
const webpack = require('webpack')
module.exports = {
entry: [
'react-hot-loader/patch', // 开启 React 代码的模块热替换(HMR)
'webpack-hot-middleware/client', // 当发生热更新时控制台会有提示
path.join(__dirname, '../src/index.js')// 入口文件
],
output: {
filename: 'bundle.js', // 打包后的文件名
chunkFilename: '[name].[chunkhash:5].js',
path: path.join(__dirname, '/'), // 打包后的文件存储位置
publicPath: '/'
},
resolve: {
modules: [path.join(__dirname, '../node_modules')], // 优化webpack文件搜索范围
extensions: ['.web.js', '.jsx', '.js', '.json']
},
devtool: 'cheap-module-eval-source-map', // 开启生成source-map文件功能便于代码调试
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader?cacheDirectory'], // 开启编译缓存
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader?modules&localIdentName=[local]-[hash:base64:5]', // 编译css文件的loader并开启css-modules功能
],
exclude: /node_modules/
},
{
test: /\.less$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader?&modules&localIdentName=[local]-[hash:base64:5]', // 编译less文件的loader并开启css-modules功能
'less-loader'
],
},
{
test: /\.(jpe?g|png|gif|mp4|webm|otf|webp)$/,
use: ['url-loader?limit=10240']
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: 'url-loader?limit=10000'
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: 'file-loader'
}
],
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),//报错时不退出webpack进程
new webpack.HotModuleReplacementPlugin(),//代码热替换
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"'//用于区分开发和生产环境
})
],
}