forked from ihaolin/antares-tower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
131 lines (126 loc) · 3.25 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
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebPackPlugin = require('html-webpack-plugin')
const apiMocker = require('mocker-api');
const webpack = require('webpack')
const path = require('path')
const dev = process.env.NODE_ENV !== 'production'
var cssOption = {
modules: false,
importLoaders: 1,
localIdentName: '[name]_[local]_[hash:base64]',
sourceMap: true,
minimize: true
}
module.exports = {
output: {
path: path.resolve(__dirname, 'dist'),
filename: dev ? '[name].js' : '[name].[hash:6].js',
chunkFilename: dev ? '[id].js' : '[id].[hash:6].js',
publicPath: '/'
},
// see https://webpack.github.io/docs/webpack-dev-server.html
devServer: {
noInfo: false,
quiet: false,
port: 3000,
hot: true,
// #https://github.com/webpack/webpack-dev-server/issues/882
disableHostCheck: true,
/* api mock
before (app) {
apiMocker(app, path.resolve('./mocker.js'), {
proxy: {
'/api/*': 'https://api.github.com/'
},
changeHost: true
})
},
*/
// api proxy redirect
proxy: {
'/api': {
target: 'http://127.0.0.1:22111'
// pathRewrite: {'^/api' : ''}
}
},
inline: true,
historyApiFallback: true,
contentBase: '/public',
publicPath: '/'
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
type: 'javascript/auto',
use: [{
loader: 'url-loader',
options: {
limit: 8192
}
}]
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
type: 'javascript/auto',
use: [{
loader: 'url-loader',
options: {
limit: 10000
}
}]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
plugins: [
['import', {'libraryName': 'antd', 'libraryDirectory': 'es', 'style': true}] ,
'react-hot-loader/babel'
]
}
}
},
{
test: /\.(le|c)ss$/,
use: [
dev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: cssOption
},
{
loader: 'less-loader',
options: {
...cssOption,
javascriptEnabled: true,
modifyVars: {
'border-radius-base': '3px',
'primary-color': '#af1f39',
'link-color': '#af1f39'
}
}
}
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: dev ? '[name].css' : '[name].[hash:6].css',
chunkFilename: dev ? '[id].css' : '[id].[hash:6].css'
}),
new HtmlWebPackPlugin({
template: 'public/index.html',
favicon: 'public/favicon.ico'
})
]
}