-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
125 lines (121 loc) · 3.59 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
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const entry = {
vendor: ['babel-polyfill', 'react', 'react-dom'],
index: path.join(__dirname, 'public/js/pages/index.js'),
setting: path.join(__dirname, 'public/js/pages/setting.js'),
editor: path.join(__dirname, 'public/js/pages/editor.js'),
userspace: path.join(__dirname, 'public/js/pages/userspace.js'),
story: path.join(__dirname, 'public/js/pages/story.js'),
question: path.join(__dirname, 'public/js/pages/question.js'),
profile: path.join(__dirname, 'public/js/pages/profile.js'),
'admin-system': path.join(__dirname, 'public/js/pages/admin-system.js'),
preview: path.join(__dirname, 'public/js/pages/preview.js')
};
const DEBUG = process.env.NODE_ENV === 'development';
const hash = DEBUG ? '' : '.[chunkhash:8]';
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'js/common.min' + hash + '.js'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
];
if(!DEBUG) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
minimize: true
}),
new ExtractTextPlugin({
filename: 'css/[name].min.[contenthash:8].css',
allChunks: true
}),
new webpack.HashedModuleIdsPlugin()
);
} else {
plugins.push(
new ExtractTextPlugin({
filename: 'css/[name].min.css',
allChunks: true
})
)
}
module.exports = {
entry,
output: {
filename: 'js/[name].min' + hash + '.js',
path: path.join(__dirname, 'assets'),
publicPath: require('./config/config.local.json').localPath,
chunkFilename: 'js/[name].min' + hash + '.js'
},
module: {
rules: [
{ test: /\.css$/, use: ['css-loader', 'style-loader'] },
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: [
require.resolve('babel-preset-es2015'),
require.resolve('babel-preset-stage-0'),
require.resolve('babel-preset-react')
]
},
exclude: /node_modules/
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: ['file-loader', 'image-webpack-loader', {
loader: 'url-loader',
options: {
limit: 10240,
name: 'images/[name].[ext]'
}
}]
}
]
},
devServer: {
port: 3300,
disableHostCheck: true,
hot: false,
inline: false,
host: '0.0.0.0',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
}
},
plugins,
resolve: {
alias: {
images: path.resolve(__dirname, 'public/img'),
scss: path.resolve(__dirname, 'public/scss'),
components: path.resolve(__dirname, 'public/js/components'),
containers: path.resolve(__dirname, 'public/js/containers'),
constants: path.resolve(__dirname, 'public/js/constants'),
lib: path.resolve(__dirname, 'public/js/lib'),
store: path.resolve(__dirname, 'public/js/store'),
router: path.resolve(__dirname, 'public/js/router'),
strings: path.resolve(__dirname, 'public/js/strings.js')
}
}
};