-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
96 lines (92 loc) · 3.2 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
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');
const Visualizer = require('webpack-visualizer-plugin'); // remove it in production environment.
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // remove it in production environment.
const otherPlugins = process.argv[1].indexOf('webpack-dev-server') >= 0 ? [] : [
new Visualizer(), // remove it in production environment.
new BundleAnalyzerPlugin({
defaultSizes: 'parsed',
// generateStatsFile: true,
statsOptions: { source: false }
}), // remove it in production environment.
];
const postcssOpts = {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: () => [
autoprefixer({
browsers: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 8', 'iOS >= 8', 'Android >= 4'],
}),
// pxtorem({ rootValue: 100, propWhiteList: [] })
],
};
module.exports = {
devtool: 'source-map', // or 'inline-source-map'
devServer: {
disableHostCheck: true
},
entry: { "index": path.resolve(__dirname, 'src/index') },
output: {
filename: '[name].js',
chunkFilename: '[id].chunk.js',
path: path.join(__dirname, '/dist'),
publicPath: '/dist/'
},
resolve: {
modules: [path.resolve(__dirname, 'node_modules'), path.join(__dirname, 'src')],
extensions: ['.web.js', '.jsx', '.js', '.json'],
},
module: {
rules: [
{
test: /\.jsx$/, exclude: /node_modules/, loader: 'babel-loader',
options: {
plugins: [
'external-helpers', // why not work?
["transform-runtime", { polyfill: false }],
["import", [{ "style": "css", "libraryName": "antd-mobile" }]]
],
presets: ['es2015', 'stage-0', 'react']
// presets: [['es2015', { modules: false }], 'stage-0', 'react'] // tree-shaking
}
},
{ test: /\.(jpg|png)$/, loader: "url-loader?limit=8192" },
// 注意:如下不使用 ExtractTextPlugin 的写法,不能单独 build 出 css 文件
// { test: /\.less$/i, loaders: ['style-loader', 'css-loader', 'less-loader'] },
// { test: /\.css$/i, loaders: ['style-loader', 'css-loader'] },
{
test: /\.less$/i, use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader', { loader: 'postcss-loader', options: postcssOpts }, 'less-loader'
]
})
},
{
test: /\.css$/i, use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader', { loader: 'postcss-loader', options: postcssOpts }
]
})
}
]
},
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
// new webpack.optimize.CommonsChunkPlugin('shared.js'),
new webpack.optimize.CommonsChunkPlugin({
// minChunks: 2,
name: 'shared',
filename: 'shared.js'
}),
new ExtractTextPlugin({ filename: '[name].css', allChunks: true }),
...otherPlugins
]
}