forked from ant-design/antd-mobile-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
83 lines (77 loc) · 2.83 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
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.
];
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: {
modulesDirectories: ['node_modules', path.join(__dirname, '../node_modules')],
extensions: ['', '.web.js', '.jsx', '.js', '.json'],
},
module: {
noParse: [/moment.js/],
loaders: [
{
test: /\.jsx$/, exclude: /node_modules/, loader: 'babel',
query: {
plugins: [
'external-helpers', // why not work?
["transform-runtime", { polyfill: false }],
["import", [{ "style": "css", "libraryName": "antd-mobile" }]]
],
presets: ['es2015', 'stage-0', 'react']
}
},
{ test: /\.(jpg|png)$/, loader: "url?limit=8192" },
// svg-sprite for [email protected]
{ test: /\.(svg)$/i, loader: 'svg-sprite', include: [
require.resolve('antd-mobile').replace(/warn\.js$/, ''), // 1. 属于 antd-mobile 内置 svg 文件
// path.resolve(__dirname, 'src/my-project-svg-foler'), // 自己私人的 svg 存放目录
]},
// { test: /\.css$/, loader: 'style!css' }, // 把css处理成内联style,动态插入到页面
{ test: /\.less$/i, loader: ExtractTextPlugin.extract('style', 'css!postcss!less') },
{ test: /\.css$/i, loader: ExtractTextPlugin.extract('style', 'css!postcss') }
]
},
postcss: [
autoprefixer({
browsers: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 8', 'iOS >= 8', 'Android >= 4'],
}),
pxtorem({ rootValue: 100, propWhiteList: [] })
],
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
plugins: [
// new webpack.optimize.CommonsChunkPlugin('shared.js'),
new webpack.optimize.CommonsChunkPlugin({
// minChunks: 2,
name: 'shared',
filename: 'shared.js'
}),
new ExtractTextPlugin('[name].css', { allChunks: true }),
...otherPlugins
]
}