1 | const path = require('path');
|
2 | const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | module.exports = (options = {}) => {
|
22 |
|
23 |
|
24 | const { globalObjectKey, appRoot, typeFunc } = require('./constants.js');
|
25 |
|
26 | let { port, host, friendly, moduleScope, mode, buildProd } = (global[
|
27 | globalObjectKey
|
28 | ] = o = require('./helpers/parse-config')(options));
|
29 |
|
30 | let { applyPlugins, applyRules } = options;
|
31 |
|
32 | let plugins = require('./plugins');
|
33 | let rules = require('./rules');
|
34 |
|
35 | if (typeof applyPlugins === typeFunc) {
|
36 | plugins = applyPlugins(plugins);
|
37 | }
|
38 |
|
39 | if (typeof applyRules === typeFunc) {
|
40 | rules = applyRules(rules);
|
41 | }
|
42 | return {
|
43 | mode,
|
44 | context: appRoot,
|
45 | entry: o.entry,
|
46 | output: require('./helpers/output-name')(options.output),
|
47 |
|
48 | optimization: require('./helpers/optimization')(),
|
49 | module: {
|
50 |
|
51 | strictExportPresence: true,
|
52 | rules
|
53 | },
|
54 | plugins,
|
55 | resolve: {
|
56 | extensions: require('./helpers/get-resolve-extensions'),
|
57 |
|
58 | alias: o.alias,
|
59 | plugins: [new ModuleScopePlugin(moduleScope)]
|
60 | },
|
61 | externals: options.externals,
|
62 | devServer: Object.assign(
|
63 | {
|
64 | port: port,
|
65 | host: host,
|
66 | hot: true,
|
67 | contentBase: path.resolve(appRoot, 'dist/'),
|
68 | publicPath: '/',
|
69 | headers: { 'Access-Control-Allow-Origin': '*' },
|
70 | quiet: friendly,
|
71 | disableHostCheck: !buildProd
|
72 | },
|
73 | options.devServer
|
74 | ),
|
75 | target: 'web',
|
76 | node: {
|
77 | setImmediate: false,
|
78 | dgram: 'empty',
|
79 | fs: 'empty',
|
80 | net: 'empty',
|
81 | tls: 'empty',
|
82 | child_process: 'empty'
|
83 | },
|
84 | devtool: buildProd ? 'source-map' : 'cheap-source-map'
|
85 | };
|
86 | };
|