-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
129 lines (112 loc) · 3.87 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//webpack config
var webpack = require('webpack'),
path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var EXCLUDE_PATH = /node_modules/,
OUTPUT_PATH = path.join(__dirname, 'dist'),
PUBLIC_PATH = '/dist/',
NODE_MODULE_PATH = '/node_modules/';
var isDev = process.env.NODE_ENV === "development";
var exportConfig;
/**
* development config
*/
var devConfig = {
devtool: 'source-map', //模块资源调试地图 ,同时css或less的loader要加上参数?sourceMap,js的loader不用加
entry: { //编译的入口文件
index: ['webpack-hot-middleware/client', './src/index']
},
output: { //输出配置
path: OUTPUT_PATH,
filename: '[name].js',
publicPath: PUBLIC_PATH
},
resolve: {
extensions: ['', '.js', '.jsx', '.scss', '.css'], // resolve 指定可以被 import 的文件后缀
alias: [] //指定包路径,这样能够减少webpack搜索硬盘文件的时间
},
module: {
loaders: [
{
test: /\.js/,
loader: 'react-hot!babel',
exclude: EXCLUDE_PATH //不包括此文件夹内的文件
},{
test: /\.css/,
//loader: ExtractTextPlugin.extract("style", "css"),
loader: 'style!css', //?modules&localIdentName=[name]__[local]-[hash:base64:5]
exclude: EXCLUDE_PATH
},{
test: /\.(jpe?g|png|gif)/,
loaders: [
'url?limit=4000&name=images/[name][hash:8].[ext]',
/*'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}'*/
]
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.CommonsChunkPlugin( 'common.js'),
new ExtractTextPlugin('style.css')
]
}
/**
* production config
*/
var prodConfig = {
entry: { //编译的入口文件
index: ['./src/index']
},
output: { //输出配置
path: OUTPUT_PATH,
filename: '[name].js',
publicPath: PUBLIC_PATH
},
resolve: {
extensions: ['', '.js', '.jsx', '.scss', '.css'], // resolve 指定可以被 import 的文件后缀
alias: [] //指定包路径,这样能够减少webpack搜索硬盘文件的时间
},
module: {
loaders: [
{
test: /\.js/,
loader: 'babel',
exclude: EXCLUDE_PATH //不包括此文件夹内的文件
},{
test: /\.css/,
loader: ExtractTextPlugin.extract("style", "css"),
//loader: 'style!css',
exclude: EXCLUDE_PATH
},{
test: /\.(jpe?g|png|gif)/,
loaders: [
'url?limit=4000&name=images/[name][hash:8].[ext]',
'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}'
]
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.CommonsChunkPlugin( 'common.js'),
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('style.css')
]
}
if(!isDev) {
var CleanPlugin = require('clean-webpack-plugin'); //清理文件夹
prodConfig.plugins.unshift(new CleanPlugin(['dist'], {
"root": path.resolve(__dirname, '../'),
verbose: true,
dry: false
}));
}
exportConfig = isDev ? devConfig: prodConfig;
module.exports = exportConfig;