@doracli/webpack-react 0.0.4 → 0.0.6

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