1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const path = require("path");
|
4 | const _ = require("lodash");
|
5 | const Config = require("webpack-chain");
|
6 | const webpack_merge_1 = require("webpack-merge");
|
7 | const loaders_1 = require("./loaders/loaders");
|
8 | const plugins_1 = require("./plugins/plugins");
|
9 | const optimization_1 = require("./optimization/optimization");
|
10 | const utils_1 = require("./utils/utils");
|
11 | const cacheConfig_1 = require("./config/cacheConfig");
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function default_1(sweetConfig, sweetOptions) {
|
18 | const config = new Config();
|
19 | const sweetConfigCopy = _.isPlainObject(sweetConfig) ? _.omit({ ...sweetConfig }, [
|
20 | 'serverRender',
|
21 | 'serverEntry',
|
22 | 'serverOutput',
|
23 | 'serverExternals',
|
24 | 'serverDevtool',
|
25 | 'serverChainWebpack'
|
26 | ]) : {};
|
27 | const { mode, entry, output, externals, resolve, rules, noParse, plugins, devtool, chainWebpack, js, webpackLog = 'progress' } = sweetConfigCopy;
|
28 | const ecmascript = js === null || js === void 0 ? void 0 : js.ecmascript;
|
29 | const isDevelopment = mode === 'development';
|
30 |
|
31 | const filename = isDevelopment ? '[name].js' : '[name]_[chunkhash:15].js';
|
32 |
|
33 | const mergeConfig = {
|
34 | mode,
|
35 | devtool: devtool !== null && devtool !== void 0 ? devtool : (isDevelopment ? 'eval-source-map' : false),
|
36 | resolve: { extensions: utils_1.extensions },
|
37 | target: ['web', ecmascript ? 'es2020' : 'es5'],
|
38 | performance: { hints: false }
|
39 | };
|
40 |
|
41 | if (isDevelopment) {
|
42 | mergeConfig.cache = {
|
43 | type: 'filesystem',
|
44 | cacheDirectory: path.join(sweetOptions.basicPath, cacheConfig_1.webpackCache)
|
45 | };
|
46 | }
|
47 |
|
48 | if (webpackLog === 'progress') {
|
49 | mergeConfig.infrastructureLogging = { level: 'warn' };
|
50 | }
|
51 | config.merge(mergeConfig);
|
52 |
|
53 | config
|
54 | .output
|
55 | .publicPath('')
|
56 | .path(path.join(sweetOptions.basicPath, 'dist'))
|
57 | .filename(filename)
|
58 | .globalObject('this');
|
59 |
|
60 | loaders_1.default(sweetConfigCopy, sweetOptions, config);
|
61 |
|
62 | plugins_1.default(sweetConfigCopy, sweetOptions, config);
|
63 |
|
64 | optimization_1.default(sweetConfigCopy, sweetOptions, config, false);
|
65 |
|
66 | if (chainWebpack) {
|
67 | chainWebpack(config);
|
68 | }
|
69 | const mergeConfiguration = {
|
70 | entry,
|
71 | output,
|
72 | externals,
|
73 | resolve,
|
74 |
|
75 | module: {
|
76 | noParse,
|
77 | rules
|
78 | },
|
79 |
|
80 | plugins,
|
81 | experiments: {
|
82 | topLevelAwait: true
|
83 | }
|
84 | };
|
85 |
|
86 | return webpack_merge_1.merge(config.toConfig(), mergeConfiguration);
|
87 | }
|
88 | exports.default = default_1;
|