1 | require('@babel/register');
|
2 |
|
3 | const path = require('path');
|
4 | const webpack = require('webpack');
|
5 |
|
6 | const custom = require('../webpack.config').default;
|
7 | const env = require('../config/env');
|
8 | const endpoint = require('../config/endpoint');
|
9 |
|
10 | const modifyRelativePath = fixPath => path.join(__dirname, '..', path.basename(fixPath));
|
11 |
|
12 | module.exports = async ({ config }) => {
|
13 | return {
|
14 | ...config,
|
15 | module: {
|
16 | ...config.module,
|
17 | rules: [
|
18 | ...config.module.rules.filter(rule => !rule.test.test('.css') && !rule.test.test('.svg')),
|
19 | ...custom.module.rules.map(rule => {
|
20 | const newRule = {
|
21 | ...rule,
|
22 | include: Array.isArray(rule.include)
|
23 | ? rule.include.map(includePath => modifyRelativePath(includePath))
|
24 | : modifyRelativePath(rule.include),
|
25 | };
|
26 |
|
27 | if (newRule.loader === 'babel-loader') {
|
28 | newRule.options.plugins[1][1].root = ['../src'];
|
29 | }
|
30 |
|
31 | return newRule;
|
32 | }),
|
33 | ],
|
34 | },
|
35 | plugins: [
|
36 | ...config.plugins,
|
37 | new webpack.DefinePlugin({
|
38 | 'process.env': { ...env, ...endpoint },
|
39 | }),
|
40 | ],
|
41 | externals: {
|
42 | ...config.externals,
|
43 | jsdom: 'window',
|
44 | cheerio: 'window',
|
45 | 'react/lib/ExecutionEnvironment': true,
|
46 | 'react/lib/ReactContext': 'window',
|
47 | 'react/addons': true,
|
48 | },
|
49 | resolve: {
|
50 | alias: {
|
51 | 'react-dom': '@hot-loader/react-dom',
|
52 | },
|
53 | },
|
54 | };
|
55 | };
|