-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathwebpack.server.js
111 lines (104 loc) · 2.67 KB
/
webpack.server.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
const webpack = require('webpack');
const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
require('./mockServer/server.js');
module.exports = {
entry:{
app: path.resolve(__dirname, 'app/index.jsx'),
// 将 第三方依赖 单独打包
vendor: [
'react',
'react-dom',
'react-redux',
'react-router-dom',
'redux',
'es6-promise',
'whatwg-fetch',
'prismjs',
'fastclick'
]
},
output:{
path:__dirname+"./public",
filename: "script/[name].[hash:8].js",
publicPath: "/",
chunkFilename: "script/[name].[chunkhash:8].js"
},
resolve:{
extensions:['.js','.jsx']
},
module:{
loaders:[
{
test:/\.(js|jsx)$/,
exclude:/node_modules/,
loader:'babel-loader',
query:{
"presets":['react','es2015']
}
},
{
test: /\.less$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract({
fallback:'style-loader',
use:'css-loader?modules&localIdentName=[local]-[hash:base64:8]!resolve-url-loader!postcss-loader!less-loader'
})
},
{
test: /\.css$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract({
fallback:'style-loader',
use:'css-loadermodules&localIdentName=[local]-[hash:base64:8]!resolve-url-loader!postcss-loader'
})
},
{
test:/\.(png|gif|jpg|jpeg|bmp)$/,
loader:'url-loader?limit=1&name=images/[name].[hash:8].[ext]'
}, // 限制大小5kb
{
test:/\.(woff|woff2|svg|ttf|eot)($|\?)/,
loader:'file-loader?name=fonts/[name].[hash:8].[ext]'
} // 限制大小小于5k
]
},
plugins:[
new htmlWebpackPlugin({
favicon:'./app/static/images/favicon.jpg',
template:'./app/index.html'
}),
new webpack.LoaderOptionsPlugin({
options:{
postcss:()=>{
return [
require('autoprefixer')({
browsers: ['last 10 versions','ie>=8','>1% in CN']
})
]
}
}
}),
// 分离CSS
new ExtractTextPlugin('style/[name].[chunkhash:8].css'),
new webpack.HotModuleReplacementPlugin(),
// 提供公共代码
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'script/[name].[hash:8].js'
})
],
devServer:{
proxy:{
'/api':{
target:"http://localhost:3000",
secure:false
}
},
contentBase:'./public',
historyApiFallback:true,
inline:true,
hot:true
}
}