-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
110 lines (103 loc) · 2.66 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
const webpack = require('webpack')
const OpenBrowserPlugin = require('open-browser-webpack-plugin')
const configSys = require('./build/dev-config')
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin')
const pack = require('./package.json')
const today = new Date().toISOString().substr(0, 10)
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const extractTextPlugin = new ExtractTextPlugin('css/[name].styles.css')
let config = {
entry: {
app: './src/index.js'
},
output: {
path: __dirname + '/public/', //输出文件目录
filename: 'js/[name].min.js', //输出文件名
libraryTarget: 'var',
publicPath: '/'
},
watch: true,
externals: {
'react': 'React',
'react-dom': 'ReactDOM'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.styl$/,
loader: ExtractTextPlugin.extract('style-loader', 'css!stylus')
},
]
},
devtool: '#eval-source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new OpenBrowserPlugin({ url: 'http://localhost:' + configSys.port }),
extractTextPlugin
],
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
},
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
watch: true,
port: configSys.port,
proxy: {
'*': {
target: 'http://localhost:' + configSys.devServerPort,
secure: false,
ws: false,
bypass: function (req, res, opt) {
if (
/(\.json)$/.test(req.path) ||
/\.bundle\.js/.test(req.path)
) {
console.log('bypass', req.path)
return req.path
}
}
}
}
},
}
if (process.env.NODE_ENV === 'production') {
config.plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': "'production'"
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
}
}),
new UnminifiedWebpackPlugin(),
extractTextPlugin,
new webpack.BannerPlugin(
`
/**
* ${pack.name}
* @version v${pack.version} - ${today}
* @link ${pack.homepage}
* @author ${pack.author.name} (${pack.author.email})
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
`
, { raw: true })
]
config.devtool = 'source-map'
}
module.exports = config