-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathwebpack.config.js
101 lines (100 loc) · 3.13 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
var path = require('path');
var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CleanPlugin = require('clean-webpack-plugin');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var prod = process.env.NODE_ENV === 'production' ? true : false;
module.exports = {
entry: { index: './src/index.js' },
output: {
path: path.resolve(__dirname, prod ? "./dist" : "./build"), //静态资源会再这目录下
filename: prod ? "js/[name].[hash].min.js" : "js/[name].[hash].js",
chunkFilename: 'js/[name].[hash].chunk.js',
publicPath: prod ? "" : ""//html里面的引用路径会变成这个
},
resolve: {
extensions: ['', '.js', '.less', '.css', '.png', '.jpg'],//第一个是空字符串! 对应不需要后缀的情况.
root: './src',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel?presets[]=es2015&presets[]=react'
},
{
test: /\.css$/,
exclude: /node_modules/,
/*loader: "style!css!less",*/
loader: ExtractTextPlugin.extract('style', 'css')
},
{
test: /\.less$/,
exclude: /node_modules/,
/*loader: "style!css!less",*/
loader: ExtractTextPlugin.extract('style', 'css!less')
},
{
test: /\.(png|jpg|jpeg|gif)$/,
exclude: /node_modules/,
loader: 'url?limit=10000&name=img/[name].[hash].[ext]'
},
{
test : /\.woff|\.woff2|\.svg|.eot|\.ttf/,
exclude: /node_modules/,
loader : 'url?prefix=font/&limit=10000&name=font/[name].[ext]'
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './index.html'
}),
new webpack.HotModuleReplacementPlugin(),
/* new ExtractTextPlugin('[name].css', {
allChunks: true
}),*/
new webpack.NoErrorsPlugin(),
new CommonsChunkPlugin({
name: 'common',
minChunks: Infinity
}),
new ExtractTextPlugin('[name].[hash].css', {
allChunks: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
//new webpack.HotModuleReplacementPlugin()
],
devServer : {
port: 7070,
hot: true,
historyApiFallback: true,
publicPath: "",
stats: {
colors: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
}
}
if (prod) {
module.exports.plugins = (module.exports.plugins || [])
.concat([
//new CleanPlugin(['dist/js']),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),//按引用频度来排序 ID,以便达到减少文件大小的效果
]);
module.exports.devtool = 'source-map';
}else{
//module.exports.devtool = 'source-map';
}