-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
102 lines (98 loc) · 2.19 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
var webpack = require("webpack");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
const theme = require('./package.json').theme;
module.exports = {
name: "production",
entry: {
index: "./src/index.js",
//添加要打包在vendors里面的库
vendor: ['react', 'react-dom']
},
plugins: [
new HtmlWebpackPlugin({
hash: true,
template: './index.html',
cache: true,
minify: {
removeComments: true,//去注释
collapseWhitespace: true//去空格
},//压缩
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false,
drop_debugger: true,
drop_console: true
}
}),
new webpack.optimize.OccurrenceOrderPlugin(true),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new ExtractTextPlugin({
filename: "css/[name].css",
disable: false,
allChunks: true
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: "./js/vendor.js",
minChunks: 3
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
],
devServer: {
host: 'localhost',
port: '8080',
proxy: {
'/': {
target: 'https://xxxx.com',
changeOrigin: true,
},
}
},
//配置;打包之后的文件信息
output: {
path: __dirname + "/dist/",
filename: "js/[name].js",
chunkFilename: "js/[name].js",
},
//配置source-map
devtool: "source-map",
//配置loader
module: {
loaders: [
//配置哪些文件需要通过babel来进行转换
{
test: /\.html$/,
loader: 'html-loader'
}, {
test: /\.js|\.jsx$/,
exclude: /node_modules|server|dao|routes/,
loader: "babel-loader"
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({ fallback: "style-loader", use: ["css-loader"] }),
}, {
test: /\.less$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
{ loader: 'less-loader', options: { javascriptEnabled: true, modifyVars: theme } },
]
}, {
test: /\.scss$/,
loaders: 'style-loader!css-loader!sass-loader'
}, {
test: /\.(png|jpe?g|eot|svg|ttf|woff2?)$/,
loader: 'url-loader?limit=8192'
}
]
}
}