forked from react-love/react-latest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
81 lines (76 loc) · 2.2 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
80
81
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var precss = require('precss');
//判断当前运行环境是开发模式还是生产模式
const nodeEnv = process.env.NODE_ENV || 'development';
const isPro = nodeEnv === 'production';
console.log("当前运行环境:", isPro)
var plugins = []
if (isPro) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify(nodeEnv)
}
})
)
} else {
plugins.push(
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify(nodeEnv)
},
BASE_URL: JSON.stringify('http://localhost:9009'),
}),
new webpack.HotModuleReplacementPlugin()
)
}
module.exports = {
devtool: false,
entry: {
app: [
'webpack-hot-middleware/client?path=http://localhost:3011/__webpack_hmr&reload=true&noInfo=false&quiet=false',
'babel-polyfill',
'./src/index'
]
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'build'),
publicPath: 'http://localhost:3011/build/',
chunkFilename: '[name].js'
},
// BASE_URL是全局的api接口访问地址
plugins,
// alias是配置全局的路径入口名称,只要涉及到下面配置的文件路径,可以直接用定义的单个字母表示整个路径
resolve: {
extensions: ['.js', '.jsx', '.less', '.scss', '.css'],
modules: [
path.resolve(__dirname, 'node_modules'),
path.join(__dirname, './src')
]
},
module: {
rules: [{
test: /\.(js|jsx)$/,
use: ['babel-loader'],
exclude: /node_modules/,
include: path.join(__dirname, 'src')
}, {
test: /\.(less|css)$/,
use: ["style-loader", "css-loader", "less-loader", "postcss-loader"]
}, {
test: /\.(png|jpg|gif|md)$/,
use: ['file-loader?limit=10000&name=[md5:hash:base64:10].[ext]']
}, {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: ['url-loader?limit=10000&mimetype=image/svg+xml']
}],
}
};