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 | 'hot'
|
21 | ]) : {};
|
22 | const { mode, serverEntry, serverOutput, serverExternals, resolve, rules, noParse, plugins, serverDevtool, serverChainWebpack } = sweetConfigCopy;
|
23 | const isDevelopment = mode === 'development';
|
24 |
|
25 | if (sweetConfigCopy.js && _.isPlainObject(sweetConfigCopy.js)) {
|
26 | sweetConfigCopy.js.ecmascript = true;
|
27 | }
|
28 | else {
|
29 | sweetConfigCopy.js = { ecmascript: true };
|
30 | }
|
31 |
|
32 | config
|
33 | .merge({
|
34 | mode,
|
35 | devtool: serverDevtool !== null && serverDevtool !== void 0 ? serverDevtool : (isDevelopment ? 'eval-source-map' : 'source-map'),
|
36 | resolve: { extensions: utils_1.extensions },
|
37 | target: ['node', 'node10'],
|
38 | performance: { hints: false },
|
39 | node: {
|
40 | __filename: true,
|
41 | __dirname: true
|
42 | },
|
43 |
|
44 | cache: isDevelopment ? {
|
45 | type: 'filesystem',
|
46 | cacheDirectory: path.join(sweetOptions.basicPath, cacheConfig_1.webpackServerCache)
|
47 | } : false
|
48 | });
|
49 |
|
50 | config
|
51 | .output
|
52 | .path(path.join(sweetOptions.basicPath, 'dist-server'))
|
53 | .publicPath('')
|
54 | .filename('[name].js')
|
55 | .library('[name]')
|
56 | .libraryTarget('umd')
|
57 | .globalObject('this');
|
58 |
|
59 | loaders_1.default(sweetConfigCopy, sweetOptions, config);
|
60 |
|
61 | plugins_1.default(sweetConfigCopy, sweetOptions, config);
|
62 |
|
63 | optimization_1.default(sweetConfigCopy, sweetOptions, config, true);
|
64 |
|
65 | if (serverChainWebpack) {
|
66 | serverChainWebpack(config);
|
67 | }
|
68 | const mergeConfiguration = {
|
69 | entry: serverEntry,
|
70 | output: serverOutput,
|
71 | externals: serverExternals,
|
72 | resolve,
|
73 |
|
74 | module: {
|
75 | noParse,
|
76 | rules
|
77 | },
|
78 |
|
79 | plugins,
|
80 | experiments: {
|
81 | topLevelAwait: true
|
82 | }
|
83 | };
|
84 |
|
85 | return webpack_merge_1.merge(config.toConfig(), mergeConfiguration);
|
86 | }
|
87 | exports.default = default_1;
|