@doracli/webpack-react 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +770 -358
- package/lib/esm/index.js +764 -361
- package/lib/type/index.d.ts +20 -9
- package/package.json +10 -9
package/lib/esm/index.js
CHANGED
|
@@ -1,107 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { obj } from '@cclr/lang';
|
|
2
|
+
import { getFilename } from '@dorabag/file-pro';
|
|
3
|
+
import { configCtxWorkflow, GenerateConfigHtml, cLog, EnvEnum, ConfigCtx, collectBaseConfigMw, collectPackageJsonMw, collectTsconfigJsonMw, collectDoraConfigMw, collectCdnConfigMw, wholeDoraConfigMw, wholeDoraInoutMw, clearMw, DynamicHtml } from '@doracli/helper';
|
|
4
|
+
import { Ctx, envParamsMw, webpackPlainMw, webpackEntryWholeMw, webpackOutputMw, webpackDevtoolMw, webpackExternalsMw, webpackResolveLoaderMw, webpackResolveMw, webpackReactModuleMw, webpackReactPluginMw, webpackHtmlPluginMw, webpackMultipleReactPluginMw, webpackLogLevelMw, collectAssetUrls, Compiler, webpackDevServerMw, multipleToInOutMw, splitDoraConfig } from '@doracli/webpack';
|
|
5
|
+
import { uri } from '@cclr/utils';
|
|
6
|
+
import { portGetter } from '@dorabag/srv-tool';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var externals = getExternals(userExternals);
|
|
24
|
-
ctx.updateWebpackConfig({
|
|
25
|
-
externals: externals
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
var updateEntry = function updateEntry(ctx) {
|
|
30
|
-
var entry = getEntry(ctx.envParams);
|
|
31
|
-
ctx.updateWebpackConfig({
|
|
32
|
-
entry: entry
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
var updateMode = function updateMode(ctx) {
|
|
37
|
-
var mode = getMode(ctx.envParams);
|
|
38
|
-
ctx.updateWebpackConfig({
|
|
39
|
-
mode: mode
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
var updateModule = function updateModule(ctx) {
|
|
44
|
-
return new Promise(function ($return, $error) {
|
|
45
|
-
var module = getReactModulePreset(ctx.envParams);
|
|
46
|
-
ctx.updateWebpackConfig({
|
|
47
|
-
module: module
|
|
48
|
-
});
|
|
49
|
-
return $return();
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
var updateOptimization = function updateOptimization(ctx) {
|
|
54
|
-
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
55
|
-
minimize = _ctx$getDoraConfig.minimize;
|
|
56
|
-
var optimization = getOptimization({
|
|
57
|
-
minimize: minimize
|
|
58
|
-
});
|
|
59
|
-
ctx.updateWebpackConfig({
|
|
60
|
-
optimization: optimization
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
var updateOutput = function updateOutput(ctx) {
|
|
65
|
-
var output = getOutput(ctx.envParams);
|
|
66
|
-
ctx.updateWebpackConfig({
|
|
67
|
-
output: output
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
var ActionMap = {
|
|
72
|
-
build: EnvEnum.prod,
|
|
73
|
-
server: EnvEnum.dev,
|
|
74
|
-
lib: EnvEnum.prod
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
var updatePlugins = function updatePlugins(ctx) {
|
|
78
|
-
return new Promise(function ($return, $error) {
|
|
79
|
-
var cdnConfig, _ctx$getDoraConfig, minimize, plugins;
|
|
80
|
-
return Promise.resolve(parseCdnConfig(ctx.configCtx.getCdnConfig(), ActionMap[ctx.envParams.action])).then(function ($await_1) {
|
|
81
|
-
try {
|
|
82
|
-
cdnConfig = $await_1;
|
|
83
|
-
_ctx$getDoraConfig = ctx.getDoraConfig(), minimize = _ctx$getDoraConfig.minimize;
|
|
84
|
-
plugins = getReactPluginsPreset(ctx.envParams, {
|
|
85
|
-
HtmlWebpackPluginOptions: cdnConfig,
|
|
86
|
-
minimize: minimize
|
|
87
|
-
});
|
|
88
|
-
return $return(ctx.updateWebpackConfig({
|
|
89
|
-
plugins: plugins
|
|
90
|
-
}));
|
|
91
|
-
} catch ($boundEx) {
|
|
92
|
-
return $error($boundEx);
|
|
8
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
9
|
+
try {
|
|
10
|
+
var i = n[a](c),
|
|
11
|
+
u = i.value;
|
|
12
|
+
} catch (n) {
|
|
13
|
+
return void e(n);
|
|
14
|
+
}
|
|
15
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
16
|
+
}
|
|
17
|
+
function _asyncToGenerator(n) {
|
|
18
|
+
return function () {
|
|
19
|
+
var t = this,
|
|
20
|
+
e = arguments;
|
|
21
|
+
return new Promise(function (r, o) {
|
|
22
|
+
var a = n.apply(t, e);
|
|
23
|
+
function _next(n) {
|
|
24
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
93
25
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
26
|
+
function _throw(n) {
|
|
27
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
28
|
+
}
|
|
29
|
+
_next(void 0);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function _classCallCheck(a, n) {
|
|
34
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
102
35
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
36
|
+
function _defineProperties(e, r) {
|
|
37
|
+
for (var t = 0; t < r.length; t++) {
|
|
38
|
+
var o = r[t];
|
|
39
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function _createClass(e, r, t) {
|
|
43
|
+
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
44
|
+
writable: false
|
|
45
|
+
}), e;
|
|
105
46
|
}
|
|
106
47
|
function _defineProperty(e, r, t) {
|
|
107
48
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
@@ -111,12 +52,6 @@ function _defineProperty(e, r, t) {
|
|
|
111
52
|
writable: true
|
|
112
53
|
}) : e[r] = t, e;
|
|
113
54
|
}
|
|
114
|
-
function _iterableToArray(r) {
|
|
115
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
116
|
-
}
|
|
117
|
-
function _nonIterableSpread() {
|
|
118
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
119
|
-
}
|
|
120
55
|
function ownKeys(e, r) {
|
|
121
56
|
var t = Object.keys(e);
|
|
122
57
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -138,8 +73,113 @@ function _objectSpread2(e) {
|
|
|
138
73
|
}
|
|
139
74
|
return e;
|
|
140
75
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
76
|
+
function _regenerator() {
|
|
77
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
78
|
+
var e,
|
|
79
|
+
t,
|
|
80
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
81
|
+
n = r.iterator || "@@iterator",
|
|
82
|
+
o = r.toStringTag || "@@toStringTag";
|
|
83
|
+
function i(r, n, o, i) {
|
|
84
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
85
|
+
u = Object.create(c.prototype);
|
|
86
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
87
|
+
var i,
|
|
88
|
+
c,
|
|
89
|
+
u,
|
|
90
|
+
f = 0,
|
|
91
|
+
p = o || [],
|
|
92
|
+
y = false,
|
|
93
|
+
G = {
|
|
94
|
+
p: 0,
|
|
95
|
+
n: 0,
|
|
96
|
+
v: e,
|
|
97
|
+
a: d,
|
|
98
|
+
f: d.bind(e, 4),
|
|
99
|
+
d: function (t, r) {
|
|
100
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
function d(r, n) {
|
|
104
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
105
|
+
var o,
|
|
106
|
+
i = p[t],
|
|
107
|
+
d = G.p,
|
|
108
|
+
l = i[2];
|
|
109
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
110
|
+
}
|
|
111
|
+
if (o || r > 1) return a;
|
|
112
|
+
throw y = true, n;
|
|
113
|
+
}
|
|
114
|
+
return function (o, p, l) {
|
|
115
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
116
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
117
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
118
|
+
try {
|
|
119
|
+
if (f = 2, i) {
|
|
120
|
+
if (c || (o = "next"), t = i[o]) {
|
|
121
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
122
|
+
if (!t.done) return t;
|
|
123
|
+
u = t.value, c < 2 && (c = 0);
|
|
124
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
125
|
+
i = e;
|
|
126
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
127
|
+
} catch (t) {
|
|
128
|
+
i = e, c = 1, u = t;
|
|
129
|
+
} finally {
|
|
130
|
+
f = 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
value: t,
|
|
135
|
+
done: y
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
}(r, o, i), true), u;
|
|
139
|
+
}
|
|
140
|
+
var a = {};
|
|
141
|
+
function Generator() {}
|
|
142
|
+
function GeneratorFunction() {}
|
|
143
|
+
function GeneratorFunctionPrototype() {}
|
|
144
|
+
t = Object.getPrototypeOf;
|
|
145
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
146
|
+
return this;
|
|
147
|
+
}), t),
|
|
148
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
149
|
+
function f(e) {
|
|
150
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
151
|
+
}
|
|
152
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
153
|
+
return this;
|
|
154
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
155
|
+
return "[object Generator]";
|
|
156
|
+
}), (_regenerator = function () {
|
|
157
|
+
return {
|
|
158
|
+
w: i,
|
|
159
|
+
m: f
|
|
160
|
+
};
|
|
161
|
+
})();
|
|
162
|
+
}
|
|
163
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
164
|
+
var i = Object.defineProperty;
|
|
165
|
+
try {
|
|
166
|
+
i({}, "", {});
|
|
167
|
+
} catch (e) {
|
|
168
|
+
i = 0;
|
|
169
|
+
}
|
|
170
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
171
|
+
function o(r, n) {
|
|
172
|
+
_regeneratorDefine(e, r, function (e) {
|
|
173
|
+
return this._invoke(r, n, e);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
r ? i ? i(e, r, {
|
|
177
|
+
value: n,
|
|
178
|
+
enumerable: !t,
|
|
179
|
+
configurable: !t,
|
|
180
|
+
writable: !t
|
|
181
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
182
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
143
183
|
}
|
|
144
184
|
function _toPrimitive(t, r) {
|
|
145
185
|
if ("object" != typeof t || !t) return t;
|
|
@@ -155,164 +195,370 @@ function _toPropertyKey(t) {
|
|
|
155
195
|
var i = _toPrimitive(t, "string");
|
|
156
196
|
return "symbol" == typeof i ? i : i + "";
|
|
157
197
|
}
|
|
158
|
-
function _unsupportedIterableToArray(r, a) {
|
|
159
|
-
if (r) {
|
|
160
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
161
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
162
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
198
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
199
|
+
var getBuildCtx = function getBuildCtx(configCtx, envParams) {
|
|
200
|
+
var workflow = configCtxWorkflow(new Ctx(configCtx));
|
|
201
|
+
workflow.use(envParamsMw(envParams));
|
|
202
|
+
workflow.use(webpackPlainMw());
|
|
203
|
+
workflow.use(webpackEntryWholeMw());
|
|
204
|
+
workflow.use(webpackOutputMw());
|
|
205
|
+
workflow.use(webpackDevtoolMw());
|
|
206
|
+
workflow.use(webpackExternalsMw());
|
|
207
|
+
workflow.use(webpackResolveLoaderMw());
|
|
208
|
+
workflow.use(webpackResolveMw());
|
|
209
|
+
workflow.use(webpackReactModuleMw());
|
|
210
|
+
workflow.use(webpackReactPluginMw());
|
|
211
|
+
workflow.use(webpackHtmlPluginMw());
|
|
212
|
+
return workflow.getResult();
|
|
213
|
+
};
|
|
214
|
+
var buildBase = /*#__PURE__*/function () {
|
|
215
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ctx) {
|
|
216
|
+
var compiler, timeEnd, res;
|
|
217
|
+
return _regenerator().w(function (_context) {
|
|
218
|
+
while (1) switch (_context.n) {
|
|
219
|
+
case 0:
|
|
220
|
+
compiler = new Compiler(ctx.webpackConfig);
|
|
221
|
+
timeEnd = cLog.time('build');
|
|
222
|
+
_context.n = 1;
|
|
223
|
+
return compiler.build({});
|
|
224
|
+
case 1:
|
|
225
|
+
res = _context.v;
|
|
226
|
+
timeEnd();
|
|
227
|
+
return _context.a(2, res);
|
|
228
|
+
}
|
|
229
|
+
}, _callee);
|
|
230
|
+
}));
|
|
231
|
+
return function buildBase(_x) {
|
|
232
|
+
return _ref.apply(this, arguments);
|
|
184
233
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
234
|
+
}();
|
|
235
|
+
var builderBaseWorkfolw = function builderBaseWorkfolw(workflow) {
|
|
236
|
+
workflow.use(webpackPlainMw());
|
|
237
|
+
workflow.use(webpackDevtoolMw());
|
|
238
|
+
workflow.use(webpackExternalsMw());
|
|
239
|
+
workflow.use(webpackResolveLoaderMw());
|
|
240
|
+
workflow.use(webpackResolveMw());
|
|
241
|
+
workflow.use(webpackReactModuleMw());
|
|
242
|
+
workflow.use(webpackMultipleReactPluginMw());
|
|
243
|
+
workflow.use(webpackLogLevelMw('warn'));
|
|
188
244
|
};
|
|
245
|
+
var buildMultipleBase = /*#__PURE__*/function () {
|
|
246
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(ctx) {
|
|
247
|
+
var context, generateConfigHtml, assetAllMap;
|
|
248
|
+
return _regenerator().w(function (_context3) {
|
|
249
|
+
while (1) switch (_context3.n) {
|
|
250
|
+
case 0:
|
|
251
|
+
_context3.n = 1;
|
|
252
|
+
return new Compiler(ctx.webpackConfig).context({});
|
|
253
|
+
case 1:
|
|
254
|
+
context = _context3.v;
|
|
255
|
+
generateConfigHtml = new GenerateConfigHtml(ctx.configCtx);
|
|
256
|
+
_context3.n = 2;
|
|
257
|
+
return generateConfigHtml.init();
|
|
258
|
+
case 2:
|
|
259
|
+
generateConfigHtml.addConfigCdn();
|
|
260
|
+
assetAllMap = {};
|
|
261
|
+
collectAssetUrls(context.compiler, function (assetMap) {
|
|
262
|
+
obj.extend(assetAllMap, assetMap);
|
|
263
|
+
});
|
|
264
|
+
_context3.n = 3;
|
|
265
|
+
return context.rebuild();
|
|
266
|
+
case 3:
|
|
267
|
+
_context3.n = 4;
|
|
268
|
+
return obj.forEachAsync(assetAllMap, /*#__PURE__*/function () {
|
|
269
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(asset) {
|
|
270
|
+
var _ctx$webpackConfig$ou;
|
|
271
|
+
var name, scripts, styles;
|
|
272
|
+
return _regenerator().w(function (_context2) {
|
|
273
|
+
while (1) switch (_context2.n) {
|
|
274
|
+
case 0:
|
|
275
|
+
name = asset.name, scripts = asset.scripts, styles = asset.styles;
|
|
276
|
+
_context2.n = 1;
|
|
277
|
+
return generateConfigHtml.copy().addBodyScripts(scripts.map(function (script) {
|
|
278
|
+
return "/".concat(name, "/").concat(getFilename(script), ".js");
|
|
279
|
+
})).addHeadStyles(styles.map(function (script) {
|
|
280
|
+
return "/".concat(name, "/").concat(getFilename(script), ".css");
|
|
281
|
+
})).writeToFile("".concat((_ctx$webpackConfig$ou = ctx.webpackConfig.output) === null || _ctx$webpackConfig$ou === void 0 ? void 0 : _ctx$webpackConfig$ou.path, "/").concat(name, "/index.html"));
|
|
282
|
+
case 1:
|
|
283
|
+
return _context2.a(2);
|
|
284
|
+
}
|
|
285
|
+
}, _callee2);
|
|
286
|
+
}));
|
|
287
|
+
return function (_x3) {
|
|
288
|
+
return _ref3.apply(this, arguments);
|
|
289
|
+
};
|
|
290
|
+
}());
|
|
291
|
+
case 4:
|
|
292
|
+
return _context3.a(2);
|
|
293
|
+
}
|
|
294
|
+
}, _callee3);
|
|
295
|
+
}));
|
|
296
|
+
return function buildMultipleBase(_x2) {
|
|
297
|
+
return _ref2.apply(this, arguments);
|
|
298
|
+
};
|
|
299
|
+
}();
|
|
189
300
|
|
|
190
|
-
var
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
301
|
+
var ActionMap = {
|
|
302
|
+
build: EnvEnum.prod,
|
|
303
|
+
server: EnvEnum.dev,
|
|
304
|
+
lib: EnvEnum.prod,
|
|
305
|
+
dev: EnvEnum.dev
|
|
195
306
|
};
|
|
196
307
|
|
|
197
|
-
var
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
308
|
+
var getConfigCtx = /*#__PURE__*/function () {
|
|
309
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(envParams, cmd, defaultDora) {
|
|
310
|
+
var workflow;
|
|
311
|
+
return _regenerator().w(function (_context) {
|
|
312
|
+
while (1) switch (_context.n) {
|
|
313
|
+
case 0:
|
|
314
|
+
workflow = configCtxWorkflow(new ConfigCtx());
|
|
315
|
+
workflow.use(collectBaseConfigMw(envParams.workRootDir, cmd));
|
|
316
|
+
workflow.use(collectPackageJsonMw());
|
|
317
|
+
workflow.use(collectTsconfigJsonMw());
|
|
318
|
+
workflow.use(collectDoraConfigMw(ActionMap[envParams.action]));
|
|
319
|
+
workflow.use(collectCdnConfigMw(ActionMap[envParams.action]));
|
|
320
|
+
workflow.use(wholeDoraConfigMw(defaultDora));
|
|
321
|
+
workflow.use(wholeDoraInoutMw());
|
|
322
|
+
workflow.use(clearMw());
|
|
323
|
+
_context.n = 1;
|
|
324
|
+
return workflow.getResult();
|
|
325
|
+
case 1:
|
|
326
|
+
return _context.a(2, _context.v);
|
|
327
|
+
}
|
|
328
|
+
}, _callee);
|
|
329
|
+
}));
|
|
330
|
+
return function getConfigCtx(_x, _x2, _x3) {
|
|
331
|
+
return _ref.apply(this, arguments);
|
|
332
|
+
};
|
|
333
|
+
}();
|
|
334
|
+
|
|
335
|
+
var ModuleHtmlMultiple = /*#__PURE__*/function () {
|
|
336
|
+
function ModuleHtmlMultiple() {
|
|
337
|
+
var publicPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/';
|
|
338
|
+
_classCallCheck(this, ModuleHtmlMultiple);
|
|
339
|
+
this.publicPath = publicPath;
|
|
340
|
+
_defineProperty(this, "assetMap", {});
|
|
341
|
+
_defineProperty(this, "dynamicHtml", new DynamicHtml());
|
|
342
|
+
_defineProperty(this, "initAwaitList", []);
|
|
343
|
+
}
|
|
344
|
+
return _createClass(ModuleHtmlMultiple, [{
|
|
345
|
+
key: "setAssetList",
|
|
346
|
+
value: function setAssetList(assetMap) {
|
|
347
|
+
this.assetMap = assetMap;
|
|
348
|
+
this.initAwaitList.forEach(function (cb) {
|
|
349
|
+
return cb();
|
|
350
|
+
});
|
|
351
|
+
this.initAwaitList = [];
|
|
352
|
+
}
|
|
353
|
+
}, {
|
|
354
|
+
key: "getAssetMap",
|
|
355
|
+
value: function getAssetMap() {
|
|
356
|
+
return this.assetMap;
|
|
357
|
+
}
|
|
358
|
+
}, {
|
|
359
|
+
key: "getModuleHtml",
|
|
360
|
+
value: function () {
|
|
361
|
+
var _getModuleHtml = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleName) {
|
|
362
|
+
var _this = this;
|
|
363
|
+
var asset, moduleHtml;
|
|
364
|
+
return _regenerator().w(function (_context) {
|
|
365
|
+
while (1) switch (_context.n) {
|
|
366
|
+
case 0:
|
|
367
|
+
if (!(Object.keys(this.assetMap).length === 0)) {
|
|
368
|
+
_context.n = 1;
|
|
369
|
+
break;
|
|
250
370
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
371
|
+
_context.n = 1;
|
|
372
|
+
return new Promise(function (resolve) {
|
|
373
|
+
_this.initAwaitList.push(function () {
|
|
374
|
+
resolve();
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
case 1:
|
|
378
|
+
asset = this.assetMap[moduleName];
|
|
379
|
+
if (asset) {
|
|
380
|
+
_context.n = 2;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
throw new Error("Module ".concat(moduleName, " asset not found."));
|
|
384
|
+
case 2:
|
|
385
|
+
moduleHtml = this.dynamicHtml.copy();
|
|
386
|
+
moduleHtml.addBodyScripts(asset.scripts.map(function (src) {
|
|
387
|
+
return {
|
|
388
|
+
src: src,
|
|
389
|
+
order: 0
|
|
390
|
+
};
|
|
391
|
+
}));
|
|
392
|
+
moduleHtml.addHeadStyles(asset.styles.map(function (src) {
|
|
393
|
+
return {
|
|
394
|
+
src: src,
|
|
395
|
+
order: 0
|
|
396
|
+
};
|
|
397
|
+
}));
|
|
398
|
+
return _context.a(2, moduleHtml.generateHtmlTemplate());
|
|
254
399
|
}
|
|
255
|
-
},
|
|
256
|
-
}
|
|
257
|
-
|
|
400
|
+
}, _callee, this);
|
|
401
|
+
}));
|
|
402
|
+
function getModuleHtml(_x) {
|
|
403
|
+
return _getModuleHtml.apply(this, arguments);
|
|
258
404
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
};
|
|
405
|
+
return getModuleHtml;
|
|
406
|
+
}()
|
|
407
|
+
}]);
|
|
408
|
+
}();
|
|
262
409
|
|
|
263
|
-
var
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
410
|
+
var getServerCtx = function getServerCtx(configCtx, envParams) {
|
|
411
|
+
var workflow = configCtxWorkflow(new Ctx(configCtx));
|
|
412
|
+
workflow.use(envParamsMw(envParams));
|
|
413
|
+
workflow.use(webpackPlainMw());
|
|
414
|
+
workflow.use(webpackEntryWholeMw());
|
|
415
|
+
workflow.use(webpackOutputMw());
|
|
416
|
+
workflow.use(webpackDevtoolMw());
|
|
417
|
+
workflow.use(webpackExternalsMw());
|
|
418
|
+
workflow.use(webpackResolveLoaderMw());
|
|
419
|
+
workflow.use(webpackResolveMw());
|
|
420
|
+
workflow.use(webpackReactModuleMw());
|
|
421
|
+
workflow.use(webpackReactPluginMw());
|
|
422
|
+
workflow.use(webpackHtmlPluginMw());
|
|
423
|
+
workflow.use(webpackDevServerMw());
|
|
424
|
+
workflow.use(webpackLogLevelMw('warn'));
|
|
425
|
+
return workflow.getResult();
|
|
426
|
+
};
|
|
427
|
+
var serverBase = /*#__PURE__*/function () {
|
|
428
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ctx) {
|
|
429
|
+
var context;
|
|
430
|
+
return _regenerator().w(function (_context) {
|
|
431
|
+
while (1) switch (_context.n) {
|
|
432
|
+
case 0:
|
|
433
|
+
_context.n = 1;
|
|
434
|
+
return new Compiler(ctx.webpackConfig).context({});
|
|
435
|
+
case 1:
|
|
436
|
+
context = _context.v;
|
|
437
|
+
_context.n = 2;
|
|
438
|
+
return context.server(ctx.devServerConfig);
|
|
439
|
+
case 2:
|
|
440
|
+
return _context.a(2);
|
|
441
|
+
}
|
|
442
|
+
}, _callee);
|
|
443
|
+
}));
|
|
444
|
+
return function serverBase(_x) {
|
|
445
|
+
return _ref.apply(this, arguments);
|
|
446
|
+
};
|
|
447
|
+
}();
|
|
448
|
+
var serverMultipleBase = /*#__PURE__*/function () {
|
|
449
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(ctx) {
|
|
450
|
+
var context, _ctx$getDoraConfigSer, publicPath, dynamicHtml, moduleNames, origSetup;
|
|
451
|
+
return _regenerator().w(function (_context2) {
|
|
452
|
+
while (1) switch (_context2.n) {
|
|
453
|
+
case 0:
|
|
454
|
+
_context2.n = 1;
|
|
455
|
+
return new Compiler(ctx.webpackConfig).context({});
|
|
456
|
+
case 1:
|
|
457
|
+
context = _context2.v;
|
|
458
|
+
_ctx$getDoraConfigSer = ctx.getDoraConfigServiceConfig(), publicPath = _ctx$getDoraConfigSer.publicPath;
|
|
459
|
+
dynamicHtml = new ModuleHtmlMultiple();
|
|
460
|
+
moduleNames = (ctx.getDoraConfig().multiple || []).map(function (module) {
|
|
461
|
+
return module.name;
|
|
462
|
+
});
|
|
463
|
+
collectAssetUrls(context.compiler, function (assetList) {
|
|
464
|
+
dynamicHtml.setAssetList(assetList);
|
|
465
|
+
}, {
|
|
466
|
+
hostname: ctx.getDoraConfigServiceConfig().host || 'localhost',
|
|
467
|
+
port: ctx.getDoraConfigServiceConfig().port || 3000
|
|
468
|
+
});
|
|
469
|
+
origSetup = ctx.devServerConfig.setupMiddlewares;
|
|
470
|
+
ctx.updateDevServerConfig({
|
|
471
|
+
setupMiddlewares: function setupMiddlewares(middlewares, server) {
|
|
472
|
+
middlewares.unshift({
|
|
473
|
+
name: 'multi-entry-html',
|
|
474
|
+
middleware: function middleware(req, res, next) {
|
|
475
|
+
var targetModuleName = moduleNames.find(function (moduleName) {
|
|
476
|
+
return new RegExp("^".concat(uri.pathJoin(publicPath, moduleName === 'index' ? '' : moduleName), "(/)?$")).test(req.url || '');
|
|
477
|
+
});
|
|
478
|
+
if (targetModuleName) {
|
|
479
|
+
dynamicHtml.getModuleHtml(targetModuleName).then(function (html) {
|
|
480
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
481
|
+
res.end(html);
|
|
482
|
+
}).catch(function (err) {
|
|
483
|
+
res.statusCode = 500;
|
|
484
|
+
res.end("Error generating HTML for module ".concat(targetModuleName, ": ").concat(err));
|
|
485
|
+
});
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
next();
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
return origSetup ? origSetup(middlewares, server) : middlewares;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
_context2.n = 2;
|
|
495
|
+
return context.server(ctx.devServerConfig);
|
|
496
|
+
case 2:
|
|
497
|
+
return _context2.a(2);
|
|
280
498
|
}
|
|
281
|
-
},
|
|
282
|
-
});
|
|
499
|
+
}, _callee2);
|
|
500
|
+
}));
|
|
501
|
+
return function serverMultipleBase(_x2) {
|
|
502
|
+
return _ref2.apply(this, arguments);
|
|
503
|
+
};
|
|
504
|
+
}();
|
|
505
|
+
var serverBaseWorkfolw = function serverBaseWorkfolw(workflow) {
|
|
506
|
+
workflow.use(webpackPlainMw());
|
|
507
|
+
workflow.use(webpackDevtoolMw());
|
|
508
|
+
workflow.use(webpackExternalsMw());
|
|
509
|
+
workflow.use(webpackResolveLoaderMw());
|
|
510
|
+
workflow.use(webpackResolveMw());
|
|
511
|
+
workflow.use(webpackReactModuleMw());
|
|
512
|
+
workflow.use(webpackMultipleReactPluginMw());
|
|
513
|
+
workflow.use(webpackDevServerMw());
|
|
514
|
+
workflow.use(webpackLogLevelMw('warn'));
|
|
283
515
|
};
|
|
284
516
|
|
|
285
|
-
var buildSingle = function
|
|
286
|
-
|
|
287
|
-
var ctx, res,
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
517
|
+
var buildSingle = /*#__PURE__*/function () {
|
|
518
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
519
|
+
var ctx, res, _ref2, err, stats, _stats$compilation;
|
|
520
|
+
return _regenerator().w(function (_context) {
|
|
521
|
+
while (1) switch (_context.n) {
|
|
522
|
+
case 0:
|
|
523
|
+
_context.n = 1;
|
|
524
|
+
return getBuildCtx(configCtx, envParams);
|
|
525
|
+
case 1:
|
|
526
|
+
ctx = _context.v;
|
|
527
|
+
_context.n = 2;
|
|
528
|
+
return buildBase(ctx);
|
|
529
|
+
case 2:
|
|
530
|
+
res = _context.v;
|
|
531
|
+
_ref2 = res || {}, err = _ref2.err, stats = _ref2.stats;
|
|
532
|
+
if (!err) {
|
|
533
|
+
_context.n = 3;
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
295
536
|
cLog.error('build', 'build_error', 'webpack构建失败,捕获到错误');
|
|
296
537
|
console.error(err);
|
|
297
|
-
return
|
|
298
|
-
|
|
299
|
-
|
|
538
|
+
return _context.a(2);
|
|
539
|
+
case 3:
|
|
540
|
+
if (!(stats !== null && stats !== void 0 && stats.hasErrors())) {
|
|
541
|
+
_context.n = 4;
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
300
544
|
cLog.error('build', 'build_error', 'webpack构建失败,捕获到状态错误');
|
|
301
545
|
stats === null || stats === void 0 || (_stats$compilation = stats.compilation) === null || _stats$compilation === void 0 || (_stats$compilation = _stats$compilation.errors) === null || _stats$compilation === void 0 || _stats$compilation.forEach(function (error) {
|
|
302
546
|
console.error(error);
|
|
303
547
|
});
|
|
304
|
-
return
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return $error($boundEx);
|
|
548
|
+
return _context.a(2);
|
|
549
|
+
case 4:
|
|
550
|
+
cLog.info('build', 'build_success', 'webpack构建成功');
|
|
551
|
+
case 5:
|
|
552
|
+
return _context.a(2);
|
|
310
553
|
}
|
|
311
|
-
},
|
|
312
|
-
});
|
|
313
|
-
|
|
554
|
+
}, _callee);
|
|
555
|
+
}));
|
|
556
|
+
return function buildSingle(_x, _x2) {
|
|
557
|
+
return _ref.apply(this, arguments);
|
|
558
|
+
};
|
|
559
|
+
}();
|
|
314
560
|
|
|
315
|
-
var version = "0.0.
|
|
561
|
+
var version = "0.0.3";
|
|
316
562
|
|
|
317
563
|
/** 生产预设配置 */
|
|
318
564
|
var presetDoracliDefaultConfig = {
|
|
@@ -325,8 +571,9 @@ var presetDoracliDefaultConfig = {
|
|
|
325
571
|
internals: [],
|
|
326
572
|
minimize: true,
|
|
327
573
|
clear: false,
|
|
328
|
-
copy:
|
|
329
|
-
dts: {}
|
|
574
|
+
copy: [],
|
|
575
|
+
dts: {},
|
|
576
|
+
webpackConfig: {}
|
|
330
577
|
};
|
|
331
578
|
|
|
332
579
|
/** 生产预设配置 */
|
|
@@ -335,27 +582,104 @@ var presetDoracliBuildConfig = _objectSpread2(_objectSpread2({}, presetDoracliDe
|
|
|
335
582
|
clear: true
|
|
336
583
|
});
|
|
337
584
|
|
|
338
|
-
var
|
|
339
|
-
|
|
585
|
+
var getBuilderMutipleCtxList = /*#__PURE__*/function () {
|
|
586
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
587
|
+
var groupList, ctxList, i, groupConfigCtx, workflow, ctx;
|
|
588
|
+
return _regenerator().w(function (_context) {
|
|
589
|
+
while (1) switch (_context.n) {
|
|
590
|
+
case 0:
|
|
591
|
+
groupList = splitDoraConfig(configCtx);
|
|
592
|
+
ctxList = [];
|
|
593
|
+
i = 0;
|
|
594
|
+
case 1:
|
|
595
|
+
if (!(i < groupList.length)) {
|
|
596
|
+
_context.n = 4;
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
groupConfigCtx = groupList[i];
|
|
600
|
+
workflow = configCtxWorkflow(new Ctx(groupConfigCtx));
|
|
601
|
+
workflow.use(envParamsMw(envParams));
|
|
602
|
+
workflow.use(multipleToInOutMw());
|
|
603
|
+
builderBaseWorkfolw(workflow);
|
|
604
|
+
_context.n = 2;
|
|
605
|
+
return workflow.getResult();
|
|
606
|
+
case 2:
|
|
607
|
+
ctx = _context.v;
|
|
608
|
+
ctxList.push(ctx);
|
|
609
|
+
case 3:
|
|
610
|
+
i++;
|
|
611
|
+
_context.n = 1;
|
|
612
|
+
break;
|
|
613
|
+
case 4:
|
|
614
|
+
return _context.a(2, ctxList);
|
|
615
|
+
}
|
|
616
|
+
}, _callee);
|
|
617
|
+
}));
|
|
618
|
+
return function getBuilderMutipleCtxList(_x, _x2) {
|
|
619
|
+
return _ref.apply(this, arguments);
|
|
620
|
+
};
|
|
621
|
+
}();
|
|
622
|
+
|
|
623
|
+
var buildMultiple = /*#__PURE__*/function () {
|
|
624
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
625
|
+
var ctxList, i, ctx;
|
|
626
|
+
return _regenerator().w(function (_context) {
|
|
627
|
+
while (1) switch (_context.n) {
|
|
628
|
+
case 0:
|
|
629
|
+
_context.n = 1;
|
|
630
|
+
return getBuilderMutipleCtxList(configCtx, envParams);
|
|
631
|
+
case 1:
|
|
632
|
+
ctxList = _context.v;
|
|
633
|
+
cLog.log('build', 'info', "\u5171".concat(ctxList.length, "\u4E2A\u4EFB\u52A1\uFF0C\u6B63\u5728\u542F\u52A8\u4E2D..."));
|
|
634
|
+
i = 0;
|
|
635
|
+
case 2:
|
|
636
|
+
if (!(i < ctxList.length)) {
|
|
637
|
+
_context.n = 5;
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
ctx = ctxList[i];
|
|
641
|
+
_context.n = 3;
|
|
642
|
+
return buildMultipleBase(ctx);
|
|
643
|
+
case 3:
|
|
644
|
+
cLog.log('build', 'success', "\u7B2C".concat(i + 1, "\u4E2A\u4EFB\u52A1\u6784\u5EFA\u7ED3\u675F"));
|
|
645
|
+
case 4:
|
|
646
|
+
i++;
|
|
647
|
+
_context.n = 2;
|
|
648
|
+
break;
|
|
649
|
+
case 5:
|
|
650
|
+
cLog.info('build', 'all_end', '多任务构建结束');
|
|
651
|
+
case 6:
|
|
652
|
+
return _context.a(2);
|
|
653
|
+
}
|
|
654
|
+
}, _callee);
|
|
655
|
+
}));
|
|
656
|
+
return function buildMultiple(_x, _x2) {
|
|
657
|
+
return _ref.apply(this, arguments);
|
|
658
|
+
};
|
|
659
|
+
}();
|
|
660
|
+
|
|
661
|
+
var buildEntry = /*#__PURE__*/function () {
|
|
662
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(cmd) {
|
|
340
663
|
var envParams, configCtx;
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
} catch ($boundEx) {
|
|
354
|
-
return $error($boundEx);
|
|
664
|
+
return _regenerator().w(function (_context) {
|
|
665
|
+
while (1) switch (_context.n) {
|
|
666
|
+
case 0:
|
|
667
|
+
envParams = {
|
|
668
|
+
action: 'build',
|
|
669
|
+
workRootDir: process.cwd()
|
|
670
|
+
};
|
|
671
|
+
_context.n = 1;
|
|
672
|
+
return getConfigCtx(envParams, cmd, presetDoracliBuildConfig);
|
|
673
|
+
case 1:
|
|
674
|
+
configCtx = _context.v;
|
|
675
|
+
return _context.a(2, buildMultiple(configCtx, envParams));
|
|
355
676
|
}
|
|
356
|
-
},
|
|
357
|
-
});
|
|
358
|
-
|
|
677
|
+
}, _callee);
|
|
678
|
+
}));
|
|
679
|
+
return function buildEntry(_x) {
|
|
680
|
+
return _ref.apply(this, arguments);
|
|
681
|
+
};
|
|
682
|
+
}();
|
|
359
683
|
|
|
360
684
|
/** 生产预设配置 */
|
|
361
685
|
var presetDoracliDevConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
@@ -363,115 +687,164 @@ var presetDoracliDevConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefa
|
|
|
363
687
|
minimize: false
|
|
364
688
|
});
|
|
365
689
|
|
|
366
|
-
var devEntry = function
|
|
367
|
-
|
|
690
|
+
var devEntry = /*#__PURE__*/function () {
|
|
691
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(cmd) {
|
|
368
692
|
var envParams, configCtx;
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
} catch ($boundEx) {
|
|
382
|
-
return $error($boundEx);
|
|
693
|
+
return _regenerator().w(function (_context) {
|
|
694
|
+
while (1) switch (_context.n) {
|
|
695
|
+
case 0:
|
|
696
|
+
envParams = {
|
|
697
|
+
action: 'dev',
|
|
698
|
+
workRootDir: process.cwd()
|
|
699
|
+
};
|
|
700
|
+
_context.n = 1;
|
|
701
|
+
return getConfigCtx(envParams, cmd, presetDoracliDevConfig);
|
|
702
|
+
case 1:
|
|
703
|
+
configCtx = _context.v;
|
|
704
|
+
return _context.a(2, buildMultiple(configCtx, envParams));
|
|
383
705
|
}
|
|
384
|
-
},
|
|
385
|
-
});
|
|
386
|
-
|
|
706
|
+
}, _callee);
|
|
707
|
+
}));
|
|
708
|
+
return function devEntry(_x) {
|
|
709
|
+
return _ref.apply(this, arguments);
|
|
710
|
+
};
|
|
711
|
+
}();
|
|
387
712
|
|
|
388
713
|
/** 生产预设配置 */
|
|
389
714
|
var presetDoracliServerConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
390
715
|
clear: false,
|
|
391
716
|
minimize: false,
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
717
|
+
serviceConfig: {
|
|
718
|
+
openBrowser: true,
|
|
719
|
+
static: {
|
|
720
|
+
'./public': '/public'
|
|
721
|
+
},
|
|
722
|
+
port: 3000,
|
|
723
|
+
host: 'localhost',
|
|
724
|
+
publicPath: '/',
|
|
725
|
+
allowedHosts: 'all'
|
|
396
726
|
}
|
|
397
727
|
});
|
|
398
728
|
|
|
399
|
-
var
|
|
400
|
-
var
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return Promise.resolve(service(ctx.devServerConfig, compiler)).then(function ($await_3) {
|
|
413
|
-
try {
|
|
414
|
-
return $return();
|
|
415
|
-
} catch ($boundEx) {
|
|
416
|
-
return $error($boundEx);
|
|
417
|
-
}
|
|
418
|
-
}, $error);
|
|
419
|
-
} catch ($boundEx) {
|
|
420
|
-
return $error($boundEx);
|
|
729
|
+
var getServerMutipleCtxList = /*#__PURE__*/function () {
|
|
730
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
731
|
+
var groupList, ctxList, i, groupConfigCtx, workflow, ctx;
|
|
732
|
+
return _regenerator().w(function (_context) {
|
|
733
|
+
while (1) switch (_context.n) {
|
|
734
|
+
case 0:
|
|
735
|
+
groupList = splitDoraConfig(configCtx);
|
|
736
|
+
ctxList = [];
|
|
737
|
+
i = 0;
|
|
738
|
+
case 1:
|
|
739
|
+
if (!(i < groupList.length)) {
|
|
740
|
+
_context.n = 4;
|
|
741
|
+
break;
|
|
421
742
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
743
|
+
groupConfigCtx = groupList[i];
|
|
744
|
+
workflow = configCtxWorkflow(new Ctx(groupConfigCtx));
|
|
745
|
+
workflow.use(envParamsMw(envParams));
|
|
746
|
+
workflow.use(multipleToInOutMw());
|
|
747
|
+
serverBaseWorkfolw(workflow);
|
|
748
|
+
_context.n = 2;
|
|
749
|
+
return workflow.getResult();
|
|
750
|
+
case 2:
|
|
751
|
+
ctx = _context.v;
|
|
752
|
+
ctxList.push(ctx);
|
|
753
|
+
case 3:
|
|
754
|
+
i++;
|
|
755
|
+
_context.n = 1;
|
|
756
|
+
break;
|
|
757
|
+
case 4:
|
|
758
|
+
return _context.a(2, ctxList);
|
|
425
759
|
}
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
|
|
760
|
+
}, _callee);
|
|
761
|
+
}));
|
|
762
|
+
return function getServerMutipleCtxList(_x, _x2) {
|
|
763
|
+
return _ref.apply(this, arguments);
|
|
764
|
+
};
|
|
765
|
+
}();
|
|
429
766
|
|
|
430
|
-
var
|
|
431
|
-
|
|
432
|
-
var
|
|
433
|
-
ctx
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
767
|
+
var serverMultiple = /*#__PURE__*/function () {
|
|
768
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
769
|
+
var _configCtx$getDoraCon;
|
|
770
|
+
var ctxList, getNextPort, i, ctx, port, moduleNames, entryUrl;
|
|
771
|
+
return _regenerator().w(function (_context) {
|
|
772
|
+
while (1) switch (_context.n) {
|
|
773
|
+
case 0:
|
|
774
|
+
_context.n = 1;
|
|
775
|
+
return getServerMutipleCtxList(configCtx, envParams);
|
|
776
|
+
case 1:
|
|
777
|
+
ctxList = _context.v;
|
|
778
|
+
getNextPort = portGetter(((_configCtx$getDoraCon = configCtx.getDoraConfig().serviceConfig) === null || _configCtx$getDoraCon === void 0 ? void 0 : _configCtx$getDoraCon.port) || 3000);
|
|
779
|
+
cLog.log('ser', 'info', "\u5171".concat(ctxList.length, "\u4E2A\u4EFB\u52A1\uFF0C\u6B63\u5728\u542F\u52A8\u4E2D..."));
|
|
780
|
+
i = 0;
|
|
781
|
+
case 2:
|
|
782
|
+
if (!(i < ctxList.length)) {
|
|
783
|
+
_context.n = 6;
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
ctx = ctxList[i];
|
|
787
|
+
_context.n = 3;
|
|
788
|
+
return getNextPort();
|
|
789
|
+
case 3:
|
|
790
|
+
port = _context.v;
|
|
791
|
+
ctx.updateDevServerConfig({
|
|
792
|
+
port: port,
|
|
793
|
+
open: false,
|
|
794
|
+
hot: true
|
|
795
|
+
});
|
|
796
|
+
_context.n = 4;
|
|
797
|
+
return serverMultipleBase(ctx);
|
|
798
|
+
case 4:
|
|
799
|
+
moduleNames = (ctx.getDoraConfig().multiple || []).map(function (module) {
|
|
800
|
+
return module.name;
|
|
801
|
+
});
|
|
802
|
+
cLog.log('ser', 'success', "[".concat(moduleNames.join(','), "] \u542F\u52A8\u6210\u529F~"));
|
|
803
|
+
entryUrl = uri.combine({
|
|
804
|
+
protocol: 'http:',
|
|
805
|
+
hostname: 'localhost',
|
|
806
|
+
port: port,
|
|
807
|
+
pathname: uri.pathJoin(ctx.getDoraConfigServiceConfig().publicPath || '/')
|
|
808
|
+
});
|
|
809
|
+
cLog.log('ser', 'link', "\u8BBF\u95EE\u5730\u5740 \u27A9 ".concat(entryUrl));
|
|
810
|
+
case 5:
|
|
811
|
+
i++;
|
|
812
|
+
_context.n = 2;
|
|
813
|
+
break;
|
|
814
|
+
case 6:
|
|
815
|
+
cLog.info('ser', 'success', "\u6240\u6709\u670D\u52A1\u542F\u52A8\u6210\u529F~");
|
|
816
|
+
case 7:
|
|
817
|
+
return _context.a(2);
|
|
441
818
|
}
|
|
442
|
-
},
|
|
443
|
-
});
|
|
444
|
-
|
|
819
|
+
}, _callee);
|
|
820
|
+
}));
|
|
821
|
+
return function serverMultiple(_x, _x2) {
|
|
822
|
+
return _ref.apply(this, arguments);
|
|
823
|
+
};
|
|
824
|
+
}();
|
|
445
825
|
|
|
446
|
-
var serverEntry = function
|
|
447
|
-
|
|
448
|
-
var envParams, configCtx
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
try {
|
|
462
|
-
cdnConfig = $await_2 || {};
|
|
463
|
-
configCtx.setCdnConfig(cdnConfig);
|
|
464
|
-
return $return(serverSingle(configCtx, envParams));
|
|
465
|
-
} catch ($boundEx) {
|
|
466
|
-
return $error($boundEx);
|
|
467
|
-
}
|
|
468
|
-
}, $error);
|
|
469
|
-
} catch ($boundEx) {
|
|
470
|
-
return $error($boundEx);
|
|
826
|
+
var serverEntry = /*#__PURE__*/function () {
|
|
827
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(cmd) {
|
|
828
|
+
var envParams, configCtx;
|
|
829
|
+
return _regenerator().w(function (_context) {
|
|
830
|
+
while (1) switch (_context.n) {
|
|
831
|
+
case 0:
|
|
832
|
+
envParams = {
|
|
833
|
+
action: 'server',
|
|
834
|
+
workRootDir: process.cwd()
|
|
835
|
+
};
|
|
836
|
+
_context.n = 1;
|
|
837
|
+
return getConfigCtx(envParams, cmd, presetDoracliServerConfig);
|
|
838
|
+
case 1:
|
|
839
|
+
configCtx = _context.v;
|
|
840
|
+
return _context.a(2, serverMultiple(configCtx, envParams));
|
|
471
841
|
}
|
|
472
|
-
},
|
|
473
|
-
});
|
|
474
|
-
|
|
842
|
+
}, _callee);
|
|
843
|
+
}));
|
|
844
|
+
return function serverEntry(_x) {
|
|
845
|
+
return _ref.apply(this, arguments);
|
|
846
|
+
};
|
|
847
|
+
}();
|
|
475
848
|
|
|
476
849
|
var childCommands = [{
|
|
477
850
|
command: 'server',
|
|
@@ -535,4 +908,34 @@ var commandOptions = {
|
|
|
535
908
|
childCommands: childCommands
|
|
536
909
|
};
|
|
537
910
|
|
|
538
|
-
|
|
911
|
+
var serverSingle = /*#__PURE__*/function () {
|
|
912
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
913
|
+
var workflow, ctx;
|
|
914
|
+
return _regenerator().w(function (_context) {
|
|
915
|
+
while (1) switch (_context.n) {
|
|
916
|
+
case 0:
|
|
917
|
+
workflow = configCtxWorkflow(new Ctx(configCtx));
|
|
918
|
+
workflow.use(envParamsMw(envParams));
|
|
919
|
+
workflow.use(webpackEntryWholeMw());
|
|
920
|
+
workflow.use(webpackOutputMw());
|
|
921
|
+
serverBaseWorkfolw(workflow);
|
|
922
|
+
workflow.use(webpackHtmlPluginMw());
|
|
923
|
+
_context.n = 1;
|
|
924
|
+
return workflow.getResult();
|
|
925
|
+
case 1:
|
|
926
|
+
ctx = _context.v;
|
|
927
|
+
_context.n = 2;
|
|
928
|
+
return serverBase(ctx);
|
|
929
|
+
case 2:
|
|
930
|
+
cLog.info('ser', 'success', 'webpack 服务启动成功~');
|
|
931
|
+
case 3:
|
|
932
|
+
return _context.a(2);
|
|
933
|
+
}
|
|
934
|
+
}, _callee);
|
|
935
|
+
}));
|
|
936
|
+
return function serverSingle(_x, _x2) {
|
|
937
|
+
return _ref.apply(this, arguments);
|
|
938
|
+
};
|
|
939
|
+
}();
|
|
940
|
+
|
|
941
|
+
export { buildBase, buildMultipleBase, buildSingle, builderBaseWorkfolw, childCommands, commandOptions, devEntry, getBuildCtx, getConfigCtx, getServerCtx, getServerMutipleCtxList, serverBase, serverBaseWorkfolw, serverMultipleBase, serverSingle };
|