forked from caize/backend-by-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
79 lines (75 loc) · 2.31 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
70
71
72
73
74
75
76
77
78
79
const path = require('path')
const webpack = require('webpack')
const autoprefixer = require('autoprefixer')
const themeConfig = require('./src/theme')
module.exports = {
entry: [
'webpack-hot-middleware/client',//当发生热更新时控制台会有提示,生成的bundle.js存储在内存中
'./src/index.js'//入口文件
],
output: {
filename: 'bundle.js',//打包后的文件名
chunkFilename: '[name].[chunkhash:5].js',
path: path.join(__dirname, 'dist'),//打包后的文件存储位置
publicPath: '/dist/'
},
resolve: {
modules: [path.resolve(__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功能
'postcss-loader'
],
},
{
test: /\.less$/,
include: /node_modules/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
`less-loader?{"modifyVars":${JSON.stringify(themeConfig)}}`//定制antd主题样式
],
},
{
test: /\.less$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader?modules&localIdentName=[local]-[hash:base64:5]',//编译less文件的loader并开启css-modules功能
'postcss-loader',
'less-loader'
],
},
{
test: /\.(jpe?g|png|gif|mp4|webm|woff|otf|webp|svg)$/,
use: 'url-loader'
}
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),//代码热替换
new webpack.NoEmitOnErrorsPlugin(),//报错时不退出webpack进程
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')//用于区分开发和生产环境
}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: () => [autoprefixer],//css样式及设备适配处理
url: { limit: 10240 }
}
})
],
}