-
Notifications
You must be signed in to change notification settings - Fork 27
/
webpack.config.js
144 lines (138 loc) · 3.36 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const webpack = require('webpack')
const ENV = process.env.NODE_ENV || 'development'
const HtmlwebpackPlugin = require('html-webpack-plugin')
const OpenBrowserPlugin = require('open-browser-webpack-plugin')
const sourcePath = './static/src/'
const buildPath = './static/dist/'
const proxys = {
'/mis_test/': {
target: 'http://mis_test.xuebadev.com/',
changeOrigin: true,
host: 'mis_test.xuebadev.com',
secure: false
}
}
const debugList = [
'question_bank',
'teacher',
'account',
'validate',
'manageCourse',
'courseware',
'homework',
'teacherPc',
'config',
'student'
]
debugList.forEach((item) => {
proxys[`/${item}/`] = {
target: 'http://teacher-qa.xuebadev.com/',
changeOrigin: true,
host: 'teacher-qa.xuebadev.com',
secure: false
}
})
module.exports = {
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,
port: 8080,
proxy: {
'/app/': {
target: 'http://localhost:8000',
changeOrigin: true,
host: 'localhost:8000',
secure: false
}
}
},
entry: {
bundle: sourcePath + 'entry/index.jsx'
},
output: {
path: buildPath,
filename: ENV === 'production' ? '[name].[hash:8].js' : '[name].js',
chunkFilename: ENV === 'production' ? '[id].[chunkhash:8].js' : '[id].js'
},
watch: true,
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel!eslint'
}, {
test: /\.less$/,
loader: 'style!css!less'
}, {
test: /\.css$/,
loader: 'style!css'
}, {
test: /\.(png|jpg|jpeg|gif)(\?v=\d+\.\d+\.\d+)?$/i,
loader: 'url-loader?limit=10192'
}, {
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url?limit=10000&minetype=application/font-woff'
}, {
test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url?limit=10000&minetype=application/font-woff'
}, {
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url?limit=10000&minetype=application/octet-stream'
}, {
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file'
}, {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url?limit=10000&minetype=image/svg+xml'
}, {
test: /\.json$/,
loader: 'json'
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
imageWebpackLoader: {
progressive: true,
optimizationLevel: 7,
interlaced: false,
pngquant: {
quality: '65-90',
speed: 4
}
},
eslint: {
formatter: require('eslint-friendly-formatter')
},
plugins: [
new HtmlwebpackPlugin({
title: '学霸君中后台框架React实现',
template: sourcePath + 'page.ejs',
minify: {
collapseWhitespace: true
}
}),
new webpack.DefinePlugin({
_DEV_: ENV !== 'production',
_DEBUG_: ENV === 'debug'
})
].concat(
ENV === 'production' ? [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.CommonsChunkPlugin('common.js')
] : [
new webpack.HotModuleReplacementPlugin(),
new OpenBrowserPlugin({
url: 'http://localhost:8080'
})
]
)
}