forked from weui/react-weui
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.doc.js
188 lines (182 loc) · 4.91 KB
/
webpack.config.doc.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const nodeEnv = process.env.NODE_ENV || 'development';
const isProduction = process.argv.indexOf('-p') !== -1;
//const isProduction = nodeEnv === 'production';
const jsSourcePath = path.join(__dirname, 'docs');
const buildPath = path.join(__dirname, 'build/demo/docs');
const sourcePath = path.join(__dirname, 'docs');
// Common plugins
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor-[hash].js',
minChunks(module) {
const context = module.context;
return context && context.indexOf('node_modules') >= 0;
},
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development'),
},
}),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template: path.join(sourcePath, 'index.html'),
path: buildPath,
filename: 'index.html',
})
];
// Common rules
const rules = [
{
test: /\.(js|jsx)$/,
oneOf: [
{
include: [path.resolve(__dirname, 'docs'), path.resolve(__dirname, 'example')],
exclude: [/node_modules/, path.resolve(__dirname, 'src')],
use: [
'babel-loader',
]
},
{
include: path.resolve(__dirname, 'src'),
exclude: [/node_modules/, path.resolve(__dirname, 'docs')],
use: [
'raw-loader',
]
},
],
}, {
test: /\.css/,
loader: [
'style-loader',
{ loader: 'css-loader', options: { sourceMap: !isProduction, importLoaders: 1 } },
{
loader: 'postcss-loader',
options: {
sourceMap: !isProduction,
plugins: (loader) => [
autoprefixer({
browsers: [
'last 3 version',
'ie >= 10',
],
})
]
}
}]
}, {
test: /\.less$/,
exclude: /node_modules/,
use: [
'style-loader',
// Using source maps breaks urls in the CSS loader
// https://github.com/webpack/css-loader/issues/232
// This comment solves it, but breaks testing from a local network
// https://github.com/webpack/css-loader/issues/232#issuecomment-240449998
// 'css-loader?sourceMap',
{ loader: 'css-loader', options: { sourceMap: !isProduction, importLoaders: 2 } },
{
loader: 'postcss-loader',
options: {
sourceMap: !isProduction,
plugins: (loader) => [
autoprefixer({
browsers: [
'last 3 version',
'ie >= 10',
],
})
]
}
},
{
loader: 'less-loader',
options: {
sourceMap: !isProduction
}
}
],
},
{
test: /\.(png|gif|jpg|svg)$/,
use: 'url-loader?limit=20480&name=assets/[name]-[hash].[ext]',
}
];
if (!isProduction) {
plugins.push(
new webpack.HotModuleReplacementPlugin()
);
} else {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
},
output: {
comments: false,
},
})
);
}
module.exports = {
devtool: isProduction ? false : 'source-map',
context: jsSourcePath,
entry: {
js: './app.js',
},
output: {
path: buildPath,
publicPath: '',
filename: 'app-[hash].js',
},
module: {
rules,
},
resolve: {
extensions: ['.webpack-loader.js', '.web-loader.js', '.loader.js', '.js', '.jsx', '.less'],
modules: [
path.resolve(__dirname, 'node_modules'),
jsSourcePath,
],
},
plugins,
devServer: {
contentBase: isProduction ? buildPath : sourcePath,
historyApiFallback: true,
port: 3000,
compress: isProduction,
inline: !isProduction,
hot: !isProduction,
host: '0.0.0.0',
disableHostCheck: true,
stats: {
assets: true,
children: false,
chunks: false,
hash: false,
modules: false,
publicPath: false,
timings: true,
version: false,
warnings: true,
colors: {
green: '\u001b[32m',
},
},
},
};