1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.dllConfig = exports.serverRenderConfig = exports.config = exports.callback = exports.callbackOnlyError = void 0;
|
4 | const process = require("process");
|
5 | const _ = require("lodash");
|
6 | const config_1 = require("./config");
|
7 | const server_1 = require("./server");
|
8 | const dll_1 = require("./dll");
|
9 | const configFile_1 = require("./utils/configFile");
|
10 |
|
11 | const sweetOptions = {
|
12 | basicPath: process.cwd(),
|
13 | environment: 'client'
|
14 | };
|
15 |
|
16 | function getConfig(environment, sweetConfig) {
|
17 | if (typeof sweetConfig === 'string') {
|
18 | const config = configFile_1.default(sweetOptions, sweetConfig);
|
19 | return typeof config === 'function' ? config({ environment }) : config;
|
20 | }
|
21 | else if (_.isPlainObject(sweetConfig)) {
|
22 | return sweetConfig;
|
23 | }
|
24 | else {
|
25 | const config = configFile_1.default(sweetOptions);
|
26 | return typeof config === 'function' ? config({ environment }) : config;
|
27 | }
|
28 | }
|
29 |
|
30 | function callbackOnlyError(err, stats) {
|
31 | if (err) {
|
32 | console.error(err);
|
33 | }
|
34 | else {
|
35 | console.log(stats.toString({
|
36 | colors: true,
|
37 | assets: false,
|
38 | entrypoints: false,
|
39 | builtAt: false,
|
40 | hash: false,
|
41 | modules: false,
|
42 | version: false,
|
43 | timings: false
|
44 | }));
|
45 | }
|
46 | }
|
47 | exports.callbackOnlyError = callbackOnlyError;
|
48 |
|
49 | function callback(err, stats) {
|
50 | if (err) {
|
51 | console.error(err);
|
52 | }
|
53 | else {
|
54 | console.log(stats.toString({
|
55 | colors: true
|
56 | }));
|
57 | }
|
58 | }
|
59 | exports.callback = callback;
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | function config(args = {}) {
|
68 | const { sweetConfig, mode, webpackLog, hot } = args;
|
69 | const config = getConfig('client', sweetConfig);
|
70 | if (config) {
|
71 | if (mode) {
|
72 | config.mode = mode;
|
73 | }
|
74 | if (webpackLog) {
|
75 | config.webpackLog = webpackLog;
|
76 | }
|
77 | if (hot) {
|
78 | config.hot = hot;
|
79 | }
|
80 | }
|
81 | return config_1.default(config, sweetOptions);
|
82 | }
|
83 | exports.config = config;
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | function serverRenderConfig(args = {}) {
|
91 | const { sweetConfig, mode, webpackLog } = args;
|
92 | const config = getConfig('server', sweetConfig);
|
93 | sweetOptions.environment = 'server';
|
94 | if (config) {
|
95 | if (mode) {
|
96 | config.mode = mode;
|
97 | }
|
98 | if (webpackLog) {
|
99 | config.webpackLog = webpackLog;
|
100 | }
|
101 | }
|
102 | return server_1.default(config, sweetOptions);
|
103 | }
|
104 | exports.serverRenderConfig = serverRenderConfig;
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | function dllConfig(args = {}) {
|
111 | const { sweetConfig, webpackLog } = args;
|
112 | const config = getConfig('dll', sweetConfig);
|
113 | sweetOptions.environment = 'dll';
|
114 | if (config && webpackLog) {
|
115 | config.webpackLog = webpackLog;
|
116 | }
|
117 | return dll_1.default(config, sweetOptions);
|
118 | }
|
119 | exports.dllConfig = dllConfig;
|
120 | exports.default = {
|
121 | callbackOnlyError,
|
122 | callback,
|
123 | config,
|
124 | serverRenderConfig,
|
125 | dllConfig
|
126 | };
|