|
1 | 1 | // This config is for building dist files
|
2 | 2 | const getWebpackConfig = require('./antd-tools/getWebpackConfig');
|
| 3 | +const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin'); |
| 4 | +const darkVars = require('./scripts/dark-vars'); |
3 | 5 | const { webpack } = getWebpackConfig;
|
4 | 6 | // noParse still leave `require('./locale' + name)` in dist files
|
5 | 7 | // ignore is better
|
@@ -36,4 +38,34 @@ if (process.env.RUN_ENV === 'PRODUCTION') {
|
36 | 38 | });
|
37 | 39 | }
|
38 | 40 |
|
39 |
| -module.exports = webpackConfig; |
| 41 | +const webpackDarkConfig = getWebpackConfig(false); |
| 42 | + |
| 43 | +webpackDarkConfig.forEach(config => { |
| 44 | + ignoreMomentLocale(config); |
| 45 | + externalMoment(config); |
| 46 | + |
| 47 | + // rename default entry to ${theme} entry |
| 48 | + Object.keys(config.entry).forEach(entryName => { |
| 49 | + config.entry[entryName.replace('antd', `antd.dark`)] = config.entry[entryName]; |
| 50 | + delete config.entry[entryName]; |
| 51 | + }); |
| 52 | + |
| 53 | + // apply ${theme} less variables |
| 54 | + config.module.rules.forEach(rule => { |
| 55 | + // filter less rule |
| 56 | + if (rule.test instanceof RegExp && rule.test.test('.less')) { |
| 57 | + const lessRule = rule.use[rule.use.length - 1]; |
| 58 | + if (lessRule.options.lessOptions) { |
| 59 | + lessRule.options.lessOptions.modifyVars = darkVars; |
| 60 | + } else { |
| 61 | + lessRule.options.modifyVars = darkVars; |
| 62 | + } |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | + const themeReg = new RegExp(`dark(.min)?\\.js(\\.map)?`); |
| 67 | + // ignore emit ${theme} entry js & js.map file |
| 68 | + config.plugins.push(new IgnoreEmitPlugin(themeReg)); |
| 69 | +}); |
| 70 | + |
| 71 | +module.exports = webpackConfig.concat(webpackDarkConfig); |
0 commit comments