@doracli/rspack-react 0.0.1 → 0.0.3
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/bin/enter.mjs +3 -0
- package/lib/cjs/index.js +710 -0
- package/lib/esm/index.js +703 -0
- package/lib/type/index.d.ts +17 -0
- package/package.json +15 -5
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import { EnvEnum, parseCdnConfig, getTsPathAlias, cLog, ConfigCtx, collectConfig, resolveCdnConfig } from '@doracli/helper';
|
|
2
|
+
import { getDevtool, getExternals, getEntry, getMode, getReactModulePreset, getOptimization, getOutput, getReactPluginsPreset, getResolveLoader, Compiler, Ctx, getDevServer } from '@doracli/rspack';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { get } from '@cclr/lang';
|
|
5
|
+
|
|
6
|
+
function _arrayLikeToArray(r, a) {
|
|
7
|
+
(null == a || a > r.length) && (a = r.length);
|
|
8
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
function _arrayWithoutHoles(r) {
|
|
12
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
13
|
+
}
|
|
14
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
15
|
+
try {
|
|
16
|
+
var i = n[a](c),
|
|
17
|
+
u = i.value;
|
|
18
|
+
} catch (n) {
|
|
19
|
+
return void e(n);
|
|
20
|
+
}
|
|
21
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
22
|
+
}
|
|
23
|
+
function _asyncToGenerator(n) {
|
|
24
|
+
return function () {
|
|
25
|
+
var t = this,
|
|
26
|
+
e = arguments;
|
|
27
|
+
return new Promise(function (r, o) {
|
|
28
|
+
var a = n.apply(t, e);
|
|
29
|
+
function _next(n) {
|
|
30
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
31
|
+
}
|
|
32
|
+
function _throw(n) {
|
|
33
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
34
|
+
}
|
|
35
|
+
_next(void 0);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function _defineProperty(e, r, t) {
|
|
40
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
41
|
+
value: t,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
}) : e[r] = t, e;
|
|
46
|
+
}
|
|
47
|
+
function _iterableToArray(r) {
|
|
48
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
49
|
+
}
|
|
50
|
+
function _nonIterableSpread() {
|
|
51
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
52
|
+
}
|
|
53
|
+
function ownKeys(e, r) {
|
|
54
|
+
var t = Object.keys(e);
|
|
55
|
+
if (Object.getOwnPropertySymbols) {
|
|
56
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
57
|
+
r && (o = o.filter(function (r) {
|
|
58
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
59
|
+
})), t.push.apply(t, o);
|
|
60
|
+
}
|
|
61
|
+
return t;
|
|
62
|
+
}
|
|
63
|
+
function _objectSpread2(e) {
|
|
64
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
65
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
66
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
67
|
+
_defineProperty(e, r, t[r]);
|
|
68
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
69
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return e;
|
|
73
|
+
}
|
|
74
|
+
function _regenerator() {
|
|
75
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
76
|
+
var e,
|
|
77
|
+
t,
|
|
78
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
79
|
+
n = r.iterator || "@@iterator",
|
|
80
|
+
o = r.toStringTag || "@@toStringTag";
|
|
81
|
+
function i(r, n, o, i) {
|
|
82
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
83
|
+
u = Object.create(c.prototype);
|
|
84
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
85
|
+
var i,
|
|
86
|
+
c,
|
|
87
|
+
u,
|
|
88
|
+
f = 0,
|
|
89
|
+
p = o || [],
|
|
90
|
+
y = false,
|
|
91
|
+
G = {
|
|
92
|
+
p: 0,
|
|
93
|
+
n: 0,
|
|
94
|
+
v: e,
|
|
95
|
+
a: d,
|
|
96
|
+
f: d.bind(e, 4),
|
|
97
|
+
d: function (t, r) {
|
|
98
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
function d(r, n) {
|
|
102
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
103
|
+
var o,
|
|
104
|
+
i = p[t],
|
|
105
|
+
d = G.p,
|
|
106
|
+
l = i[2];
|
|
107
|
+
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));
|
|
108
|
+
}
|
|
109
|
+
if (o || r > 1) return a;
|
|
110
|
+
throw y = true, n;
|
|
111
|
+
}
|
|
112
|
+
return function (o, p, l) {
|
|
113
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
114
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
115
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
116
|
+
try {
|
|
117
|
+
if (f = 2, i) {
|
|
118
|
+
if (c || (o = "next"), t = i[o]) {
|
|
119
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
120
|
+
if (!t.done) return t;
|
|
121
|
+
u = t.value, c < 2 && (c = 0);
|
|
122
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
123
|
+
i = e;
|
|
124
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
125
|
+
} catch (t) {
|
|
126
|
+
i = e, c = 1, u = t;
|
|
127
|
+
} finally {
|
|
128
|
+
f = 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
value: t,
|
|
133
|
+
done: y
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
}(r, o, i), true), u;
|
|
137
|
+
}
|
|
138
|
+
var a = {};
|
|
139
|
+
function Generator() {}
|
|
140
|
+
function GeneratorFunction() {}
|
|
141
|
+
function GeneratorFunctionPrototype() {}
|
|
142
|
+
t = Object.getPrototypeOf;
|
|
143
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
144
|
+
return this;
|
|
145
|
+
}), t),
|
|
146
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
147
|
+
function f(e) {
|
|
148
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
149
|
+
}
|
|
150
|
+
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 () {
|
|
151
|
+
return this;
|
|
152
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
153
|
+
return "[object Generator]";
|
|
154
|
+
}), (_regenerator = function () {
|
|
155
|
+
return {
|
|
156
|
+
w: i,
|
|
157
|
+
m: f
|
|
158
|
+
};
|
|
159
|
+
})();
|
|
160
|
+
}
|
|
161
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
162
|
+
var i = Object.defineProperty;
|
|
163
|
+
try {
|
|
164
|
+
i({}, "", {});
|
|
165
|
+
} catch (e) {
|
|
166
|
+
i = 0;
|
|
167
|
+
}
|
|
168
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
169
|
+
function o(r, n) {
|
|
170
|
+
_regeneratorDefine(e, r, function (e) {
|
|
171
|
+
return this._invoke(r, n, e);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
r ? i ? i(e, r, {
|
|
175
|
+
value: n,
|
|
176
|
+
enumerable: !t,
|
|
177
|
+
configurable: !t,
|
|
178
|
+
writable: !t
|
|
179
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
180
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
181
|
+
}
|
|
182
|
+
function _toConsumableArray(r) {
|
|
183
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
184
|
+
}
|
|
185
|
+
function _toPrimitive(t, r) {
|
|
186
|
+
if ("object" != typeof t || !t) return t;
|
|
187
|
+
var e = t[Symbol.toPrimitive];
|
|
188
|
+
if (void 0 !== e) {
|
|
189
|
+
var i = e.call(t, r);
|
|
190
|
+
if ("object" != typeof i) return i;
|
|
191
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
192
|
+
}
|
|
193
|
+
return ("string" === r ? String : Number)(t);
|
|
194
|
+
}
|
|
195
|
+
function _toPropertyKey(t) {
|
|
196
|
+
var i = _toPrimitive(t, "string");
|
|
197
|
+
return "symbol" == typeof i ? i : i + "";
|
|
198
|
+
}
|
|
199
|
+
function _unsupportedIterableToArray(r, a) {
|
|
200
|
+
if (r) {
|
|
201
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
202
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
203
|
+
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;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
var updateDevtool = function updateDevtool(ctx) {
|
|
208
|
+
var devtool = getDevtool(ctx.envParams);
|
|
209
|
+
ctx.updateRspackConfig({
|
|
210
|
+
devtool: devtool
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// export const getExternals = (ctx: Ctx): TExternals => {
|
|
215
|
+
// const { externals } = ctx.geTDoraConfigRspack();
|
|
216
|
+
// if (externals) return externals;
|
|
217
|
+
|
|
218
|
+
// return [];
|
|
219
|
+
// };
|
|
220
|
+
|
|
221
|
+
var updateExternals = function updateExternals(ctx) {
|
|
222
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
223
|
+
userExternals = _ctx$getDoraConfig.externals;
|
|
224
|
+
var externals = getExternals(userExternals);
|
|
225
|
+
ctx.updateRspackConfig({
|
|
226
|
+
externals: externals
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
var updateEntry = function updateEntry(ctx) {
|
|
231
|
+
var entry = getEntry(ctx.envParams);
|
|
232
|
+
ctx.updateRspackConfig({
|
|
233
|
+
entry: entry
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
var updateMode = function updateMode(ctx) {
|
|
238
|
+
var mode = getMode(ctx.envParams);
|
|
239
|
+
ctx.updateRspackConfig({
|
|
240
|
+
mode: mode
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
var updateModule = /*#__PURE__*/function () {
|
|
245
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ctx) {
|
|
246
|
+
var module;
|
|
247
|
+
return _regenerator().w(function (_context) {
|
|
248
|
+
while (1) switch (_context.n) {
|
|
249
|
+
case 0:
|
|
250
|
+
module = getReactModulePreset(ctx.envParams);
|
|
251
|
+
ctx.updateRspackConfig({
|
|
252
|
+
module: module
|
|
253
|
+
});
|
|
254
|
+
case 1:
|
|
255
|
+
return _context.a(2);
|
|
256
|
+
}
|
|
257
|
+
}, _callee);
|
|
258
|
+
}));
|
|
259
|
+
return function updateModule(_x) {
|
|
260
|
+
return _ref.apply(this, arguments);
|
|
261
|
+
};
|
|
262
|
+
}();
|
|
263
|
+
|
|
264
|
+
var updateOptimization = function updateOptimization(ctx) {
|
|
265
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
266
|
+
minimize = _ctx$getDoraConfig.minimize;
|
|
267
|
+
var optimization = getOptimization({
|
|
268
|
+
minimize: minimize
|
|
269
|
+
});
|
|
270
|
+
ctx.updateRspackConfig({
|
|
271
|
+
optimization: optimization
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
var updateOutput = function updateOutput(ctx) {
|
|
276
|
+
var output = getOutput(ctx.envParams);
|
|
277
|
+
ctx.updateRspackConfig({
|
|
278
|
+
output: output
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
var ActionMap = {
|
|
283
|
+
build: EnvEnum.prod,
|
|
284
|
+
server: EnvEnum.dev,
|
|
285
|
+
lib: EnvEnum.prod
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
var updatePlugins = /*#__PURE__*/function () {
|
|
289
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ctx) {
|
|
290
|
+
var cdnConfig, _ctx$getDoraConfig, minimize, plugins;
|
|
291
|
+
return _regenerator().w(function (_context) {
|
|
292
|
+
while (1) switch (_context.n) {
|
|
293
|
+
case 0:
|
|
294
|
+
_context.n = 1;
|
|
295
|
+
return parseCdnConfig(ctx.configCtx.getCdnConfig(), ActionMap[ctx.envParams.action]);
|
|
296
|
+
case 1:
|
|
297
|
+
cdnConfig = _context.v;
|
|
298
|
+
_ctx$getDoraConfig = ctx.getDoraConfig(), minimize = _ctx$getDoraConfig.minimize;
|
|
299
|
+
plugins = getReactPluginsPreset(ctx.envParams, {
|
|
300
|
+
HtmlWebpackPluginOptions: cdnConfig,
|
|
301
|
+
minimize: minimize
|
|
302
|
+
});
|
|
303
|
+
return _context.a(2, ctx.updateRspackConfig({
|
|
304
|
+
plugins: plugins
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
307
|
+
}, _callee);
|
|
308
|
+
}));
|
|
309
|
+
return function updatePlugins(_x) {
|
|
310
|
+
return _ref.apply(this, arguments);
|
|
311
|
+
};
|
|
312
|
+
}();
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* 获取rspack的resolve配置
|
|
316
|
+
* @param userResolve
|
|
317
|
+
* @returns
|
|
318
|
+
*/
|
|
319
|
+
var updateResolve = function updateResolve(ctx) {
|
|
320
|
+
var tsConfig = ctx.configCtx.getTsConfig();
|
|
321
|
+
var _ctx$geTDoraConfigRsp = ctx.geTDoraConfigRspack(),
|
|
322
|
+
userConfigResolve = _ctx$geTDoraConfigRsp.resolve;
|
|
323
|
+
var injectAlias = get(userConfigResolve, 'alias', {});
|
|
324
|
+
var injectExtensions = get(userConfigResolve, 'extensions', []);
|
|
325
|
+
var tsAlias = getTsPathAlias(tsConfig);
|
|
326
|
+
var resolveObj = {
|
|
327
|
+
extensions: Array.from(new Set(['.ts', '.tsx', '.js', '.jsx'].concat(_toConsumableArray(injectExtensions)))),
|
|
328
|
+
alias: _objectSpread2(_objectSpread2({
|
|
329
|
+
'@src': resolve('src'),
|
|
330
|
+
'@': resolve('src')
|
|
331
|
+
}, tsAlias), injectAlias)
|
|
332
|
+
};
|
|
333
|
+
ctx.updateRspackConfig({
|
|
334
|
+
resolve: resolveObj
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
var updateResolveLoader = function updateResolveLoader(ctx) {
|
|
339
|
+
var resolveLoader = getResolveLoader();
|
|
340
|
+
ctx.updateRspackConfig({
|
|
341
|
+
resolveLoader: resolveLoader
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
var initRspackConfig = /*#__PURE__*/function () {
|
|
346
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ctx) {
|
|
347
|
+
return _regenerator().w(function (_context) {
|
|
348
|
+
while (1) switch (_context.n) {
|
|
349
|
+
case 0:
|
|
350
|
+
_context.n = 1;
|
|
351
|
+
return updateMode(ctx);
|
|
352
|
+
case 1:
|
|
353
|
+
_context.n = 2;
|
|
354
|
+
return updateEntry(ctx);
|
|
355
|
+
case 2:
|
|
356
|
+
_context.n = 3;
|
|
357
|
+
return updateOutput(ctx);
|
|
358
|
+
case 3:
|
|
359
|
+
_context.n = 4;
|
|
360
|
+
return updateDevtool(ctx);
|
|
361
|
+
case 4:
|
|
362
|
+
_context.n = 5;
|
|
363
|
+
return updateExternals(ctx);
|
|
364
|
+
case 5:
|
|
365
|
+
_context.n = 6;
|
|
366
|
+
return updateResolve(ctx);
|
|
367
|
+
case 6:
|
|
368
|
+
_context.n = 7;
|
|
369
|
+
return updateResolveLoader(ctx);
|
|
370
|
+
case 7:
|
|
371
|
+
_context.n = 8;
|
|
372
|
+
return updateOptimization(ctx);
|
|
373
|
+
case 8:
|
|
374
|
+
_context.n = 9;
|
|
375
|
+
return updateModule(ctx);
|
|
376
|
+
case 9:
|
|
377
|
+
_context.n = 10;
|
|
378
|
+
return updatePlugins(ctx);
|
|
379
|
+
case 10:
|
|
380
|
+
return _context.a(2);
|
|
381
|
+
}
|
|
382
|
+
}, _callee);
|
|
383
|
+
}));
|
|
384
|
+
return function initRspackConfig(_x) {
|
|
385
|
+
return _ref.apply(this, arguments);
|
|
386
|
+
};
|
|
387
|
+
}();
|
|
388
|
+
|
|
389
|
+
var buildBase = /*#__PURE__*/function () {
|
|
390
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ctx) {
|
|
391
|
+
var timeEnd, compiler, res;
|
|
392
|
+
return _regenerator().w(function (_context) {
|
|
393
|
+
while (1) switch (_context.n) {
|
|
394
|
+
case 0:
|
|
395
|
+
_context.n = 1;
|
|
396
|
+
return initRspackConfig(ctx);
|
|
397
|
+
case 1:
|
|
398
|
+
timeEnd = cLog.time('build');
|
|
399
|
+
compiler = new Compiler(ctx.rspackConfig);
|
|
400
|
+
_context.n = 2;
|
|
401
|
+
return compiler.build({});
|
|
402
|
+
case 2:
|
|
403
|
+
res = _context.v;
|
|
404
|
+
timeEnd();
|
|
405
|
+
return _context.a(2, res);
|
|
406
|
+
}
|
|
407
|
+
}, _callee);
|
|
408
|
+
}));
|
|
409
|
+
return function buildBase(_x) {
|
|
410
|
+
return _ref.apply(this, arguments);
|
|
411
|
+
};
|
|
412
|
+
}();
|
|
413
|
+
|
|
414
|
+
var buildSingle = /*#__PURE__*/function () {
|
|
415
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
416
|
+
var ctx, res, _ref2, err, stats, _stats$compilation;
|
|
417
|
+
return _regenerator().w(function (_context) {
|
|
418
|
+
while (1) switch (_context.n) {
|
|
419
|
+
case 0:
|
|
420
|
+
ctx = new Ctx(configCtx);
|
|
421
|
+
ctx.updateEnvParams(envParams);
|
|
422
|
+
_context.n = 1;
|
|
423
|
+
return buildBase(ctx);
|
|
424
|
+
case 1:
|
|
425
|
+
res = _context.v;
|
|
426
|
+
_ref2 = res || {}, err = _ref2.err, stats = _ref2.stats;
|
|
427
|
+
if (!err) {
|
|
428
|
+
_context.n = 2;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
cLog.error('build', 'build_error', 'webpack构建失败,捕获到错误');
|
|
432
|
+
console.error(err);
|
|
433
|
+
return _context.a(2);
|
|
434
|
+
case 2:
|
|
435
|
+
if (!(stats !== null && stats !== void 0 && stats.hasErrors())) {
|
|
436
|
+
_context.n = 3;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
cLog.error('build', 'build_error', 'webpack构建失败,捕获到状态错误');
|
|
440
|
+
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) {
|
|
441
|
+
console.error(error);
|
|
442
|
+
});
|
|
443
|
+
return _context.a(2);
|
|
444
|
+
case 3:
|
|
445
|
+
cLog.info('build', 'build_success', 'webpack构建成功');
|
|
446
|
+
case 4:
|
|
447
|
+
return _context.a(2);
|
|
448
|
+
}
|
|
449
|
+
}, _callee);
|
|
450
|
+
}));
|
|
451
|
+
return function buildSingle(_x, _x2) {
|
|
452
|
+
return _ref.apply(this, arguments);
|
|
453
|
+
};
|
|
454
|
+
}();
|
|
455
|
+
|
|
456
|
+
var version = "0.0.1";
|
|
457
|
+
|
|
458
|
+
/** 生产预设配置 */
|
|
459
|
+
var presetDoracliDefaultConfig = {
|
|
460
|
+
output: {
|
|
461
|
+
path: './dist'
|
|
462
|
+
},
|
|
463
|
+
formatList: ['cjs'],
|
|
464
|
+
alias: {},
|
|
465
|
+
externals: [],
|
|
466
|
+
internals: [],
|
|
467
|
+
minimize: true,
|
|
468
|
+
clear: false,
|
|
469
|
+
copy: [],
|
|
470
|
+
dts: {}
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
/** 生产预设配置 */
|
|
474
|
+
var presetDoracliBuildConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
475
|
+
minimize: true,
|
|
476
|
+
clear: true
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
var buildEntry = /*#__PURE__*/function () {
|
|
480
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(cmd) {
|
|
481
|
+
var envParams, configCtx;
|
|
482
|
+
return _regenerator().w(function (_context) {
|
|
483
|
+
while (1) switch (_context.n) {
|
|
484
|
+
case 0:
|
|
485
|
+
envParams = {
|
|
486
|
+
action: 'build',
|
|
487
|
+
workRootDir: process.cwd()
|
|
488
|
+
};
|
|
489
|
+
configCtx = new ConfigCtx();
|
|
490
|
+
configCtx.setCmd(cmd);
|
|
491
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
492
|
+
_context.n = 1;
|
|
493
|
+
return collectConfig(configCtx, ActionMap[envParams.action], {
|
|
494
|
+
doraConfig: presetDoracliBuildConfig
|
|
495
|
+
});
|
|
496
|
+
case 1:
|
|
497
|
+
return _context.a(2, buildSingle(configCtx, envParams));
|
|
498
|
+
}
|
|
499
|
+
}, _callee);
|
|
500
|
+
}));
|
|
501
|
+
return function buildEntry(_x) {
|
|
502
|
+
return _ref.apply(this, arguments);
|
|
503
|
+
};
|
|
504
|
+
}();
|
|
505
|
+
|
|
506
|
+
/** 生产预设配置 */
|
|
507
|
+
var presetDoracliDevConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
508
|
+
clear: true,
|
|
509
|
+
minimize: false
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
var devEntry = /*#__PURE__*/function () {
|
|
513
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(cmd) {
|
|
514
|
+
var envParams, configCtx;
|
|
515
|
+
return _regenerator().w(function (_context) {
|
|
516
|
+
while (1) switch (_context.n) {
|
|
517
|
+
case 0:
|
|
518
|
+
envParams = {
|
|
519
|
+
action: 'build',
|
|
520
|
+
workRootDir: process.cwd()
|
|
521
|
+
};
|
|
522
|
+
configCtx = new ConfigCtx();
|
|
523
|
+
configCtx.setCmd(cmd);
|
|
524
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
525
|
+
_context.n = 1;
|
|
526
|
+
return collectConfig(configCtx, ActionMap[envParams.action], {
|
|
527
|
+
doraConfig: presetDoracliDevConfig
|
|
528
|
+
});
|
|
529
|
+
case 1:
|
|
530
|
+
return _context.a(2, buildSingle(configCtx, envParams));
|
|
531
|
+
}
|
|
532
|
+
}, _callee);
|
|
533
|
+
}));
|
|
534
|
+
return function devEntry(_x) {
|
|
535
|
+
return _ref.apply(this, arguments);
|
|
536
|
+
};
|
|
537
|
+
}();
|
|
538
|
+
|
|
539
|
+
/** 生产预设配置 */
|
|
540
|
+
var presetDoracliServerConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
541
|
+
clear: false,
|
|
542
|
+
minimize: false,
|
|
543
|
+
rspackConfig: {
|
|
544
|
+
serviceConfig: {
|
|
545
|
+
open: true
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
var updateDevServer = function updateDevServer(ctx) {
|
|
551
|
+
var userServiceConfig = ctx.geTDoraConfigRspack().serviceConfig || {};
|
|
552
|
+
ctx.updateDevServerConfig(getDevServer(userServiceConfig));
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
var serverBase = /*#__PURE__*/function () {
|
|
556
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ctx) {
|
|
557
|
+
var compiler;
|
|
558
|
+
return _regenerator().w(function (_context) {
|
|
559
|
+
while (1) switch (_context.n) {
|
|
560
|
+
case 0:
|
|
561
|
+
_context.n = 1;
|
|
562
|
+
return initRspackConfig(ctx);
|
|
563
|
+
case 1:
|
|
564
|
+
_context.n = 2;
|
|
565
|
+
return updateDevServer(ctx);
|
|
566
|
+
case 2:
|
|
567
|
+
compiler = new Compiler(ctx.rspackConfig);
|
|
568
|
+
_context.n = 3;
|
|
569
|
+
return compiler.server(ctx.devServerConfig);
|
|
570
|
+
case 3:
|
|
571
|
+
return _context.a(2);
|
|
572
|
+
}
|
|
573
|
+
}, _callee);
|
|
574
|
+
}));
|
|
575
|
+
return function serverBase(_x) {
|
|
576
|
+
return _ref.apply(this, arguments);
|
|
577
|
+
};
|
|
578
|
+
}();
|
|
579
|
+
|
|
580
|
+
var serverSingle = /*#__PURE__*/function () {
|
|
581
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, envParams) {
|
|
582
|
+
var ctx;
|
|
583
|
+
return _regenerator().w(function (_context) {
|
|
584
|
+
while (1) switch (_context.n) {
|
|
585
|
+
case 0:
|
|
586
|
+
ctx = new Ctx(configCtx);
|
|
587
|
+
ctx.updateEnvParams(envParams);
|
|
588
|
+
_context.n = 1;
|
|
589
|
+
return serverBase(ctx);
|
|
590
|
+
case 1:
|
|
591
|
+
cLog.info('server', 'success', 'rspack 服务启动成功~');
|
|
592
|
+
case 2:
|
|
593
|
+
return _context.a(2);
|
|
594
|
+
}
|
|
595
|
+
}, _callee);
|
|
596
|
+
}));
|
|
597
|
+
return function serverSingle(_x, _x2) {
|
|
598
|
+
return _ref.apply(this, arguments);
|
|
599
|
+
};
|
|
600
|
+
}();
|
|
601
|
+
|
|
602
|
+
var serverEntry = /*#__PURE__*/function () {
|
|
603
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(cmd) {
|
|
604
|
+
var envParams, configCtx, cdnConfig, _t;
|
|
605
|
+
return _regenerator().w(function (_context) {
|
|
606
|
+
while (1) switch (_context.n) {
|
|
607
|
+
case 0:
|
|
608
|
+
envParams = {
|
|
609
|
+
action: 'server',
|
|
610
|
+
workRootDir: process.cwd()
|
|
611
|
+
};
|
|
612
|
+
configCtx = new ConfigCtx();
|
|
613
|
+
configCtx.setCmd(cmd);
|
|
614
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
615
|
+
_context.n = 1;
|
|
616
|
+
return collectConfig(configCtx, ActionMap[envParams.action], {
|
|
617
|
+
doraConfig: presetDoracliServerConfig
|
|
618
|
+
});
|
|
619
|
+
case 1:
|
|
620
|
+
_context.n = 2;
|
|
621
|
+
return resolveCdnConfig(envParams.workRootDir, ActionMap[envParams.action]);
|
|
622
|
+
case 2:
|
|
623
|
+
_t = _context.v;
|
|
624
|
+
if (_t) {
|
|
625
|
+
_context.n = 3;
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
_t = {};
|
|
629
|
+
case 3:
|
|
630
|
+
cdnConfig = _t;
|
|
631
|
+
configCtx.setCdnConfig(cdnConfig);
|
|
632
|
+
return _context.a(2, serverSingle(configCtx, envParams));
|
|
633
|
+
}
|
|
634
|
+
}, _callee);
|
|
635
|
+
}));
|
|
636
|
+
return function serverEntry(_x) {
|
|
637
|
+
return _ref.apply(this, arguments);
|
|
638
|
+
};
|
|
639
|
+
}();
|
|
640
|
+
|
|
641
|
+
var childCommands = [{
|
|
642
|
+
command: 'server',
|
|
643
|
+
description: 'run a project by dev',
|
|
644
|
+
options: [{
|
|
645
|
+
name: 'format',
|
|
646
|
+
simpleName: 'f',
|
|
647
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
648
|
+
description: 'set output module type'
|
|
649
|
+
}, {
|
|
650
|
+
name: 'workRootDir',
|
|
651
|
+
simpleName: 'r',
|
|
652
|
+
type: '[string]',
|
|
653
|
+
description: 'set work root path',
|
|
654
|
+
defaultValue: './'
|
|
655
|
+
}],
|
|
656
|
+
action: function action(env) {
|
|
657
|
+
serverEntry(env);
|
|
658
|
+
}
|
|
659
|
+
}, {
|
|
660
|
+
command: 'build',
|
|
661
|
+
description: 'run a project by build',
|
|
662
|
+
options: [{
|
|
663
|
+
name: 'format',
|
|
664
|
+
simpleName: 'f',
|
|
665
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
666
|
+
description: 'set output module type'
|
|
667
|
+
}, {
|
|
668
|
+
name: 'workRootDir',
|
|
669
|
+
simpleName: 'r',
|
|
670
|
+
type: '[string]',
|
|
671
|
+
description: 'set work root path',
|
|
672
|
+
defaultValue: './'
|
|
673
|
+
}],
|
|
674
|
+
action: function action(env) {
|
|
675
|
+
buildEntry(env);
|
|
676
|
+
}
|
|
677
|
+
}, {
|
|
678
|
+
command: 'dev',
|
|
679
|
+
description: 'run a project by build',
|
|
680
|
+
options: [{
|
|
681
|
+
name: 'format',
|
|
682
|
+
simpleName: 'f',
|
|
683
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
684
|
+
description: 'set output module type'
|
|
685
|
+
}, {
|
|
686
|
+
name: 'workRootDir',
|
|
687
|
+
simpleName: 'r',
|
|
688
|
+
type: '[string]',
|
|
689
|
+
description: 'set work root path',
|
|
690
|
+
defaultValue: './'
|
|
691
|
+
}],
|
|
692
|
+
action: function action(env) {
|
|
693
|
+
devEntry(env);
|
|
694
|
+
}
|
|
695
|
+
}];
|
|
696
|
+
var commandOptions = {
|
|
697
|
+
name: 'magic',
|
|
698
|
+
usage: 'magic <command> [option]',
|
|
699
|
+
version: version,
|
|
700
|
+
childCommands: childCommands
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
export { buildBase, buildSingle, childCommands, commandOptions, serverBase, serverSingle };
|