-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
60 lines (55 loc) · 1.61 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
const path = require('path')
const pck = require('./package')
const HTMLPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const getWebpackConfig = require('rcm-tools/lib/getWebpackConfig')
const { removeFiles } = require('rcm-tools/lib/utils/buildHelper')
const run_env = process.env.RUN_ENV
const webpackConfig = getWebpackConfig({
styleGlobal: pck.styleGlobal
})
if (run_env) {
switch (run_env) {
case 'DEMO': // 演示打包
removeFiles('./site')
webpackConfig.mode = 'production'
webpackConfig.entry = {
index: './example/index.jsx'
}
webpackConfig.output = {
path: path.resolve('./demo'),
filename: '[name].js'
}
webpackConfig.plugins.push(
new HTMLPlugin({
template: './example/index.html',
hash: false,
inject: true
}),
// fixme: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/73
new MiniCssExtractPlugin({
filename: '[name].css'
})
)
break
default: // 组件打包
webpackConfig.forEach(config => {
// 排除其它一些外部依赖
['x-tools', 'classnames']
.forEach(node => externalRCM(config, node))
})
}
}
else {
// fixme: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/73
webpackConfig.plugins.push(new MiniCssExtractPlugin({ filename: '[name].css' }))
}
module.exports = webpackConfig
function externalRCM(config, rcm) {
config.externals[rcm] = {
root: rcm,
commonjs2: rcm,
commonjs: rcm,
amd: rcm
}
}