@doracli/rollup 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,2073 +1,2073 @@
1
- 'use strict';
2
-
3
- var rollup = require('rollup');
4
- var lang = require('@cclr/lang');
5
- var helper = require('@doracli/helper');
6
- var filePro = require('@dorabag/file-pro');
7
- var path = require('path');
8
- var alias = require('@rollup/plugin-alias');
9
- var babel = require('@rollup/plugin-babel');
10
- var commonjs = require('@rollup/plugin-commonjs');
11
- var copy = require('rollup-plugin-copy');
12
- var rollupPluginDts = require('rollup-plugin-dts');
13
- var json = require('@rollup/plugin-json');
14
- var terser = require('@rollup/plugin-terser');
15
- var autoprefixer = require('autoprefixer');
16
- var cssnanoPlugin = require('cssnano');
17
- var fs = require('fs');
18
- var promises = require('fs/promises');
19
- var postcss = require('rollup-plugin-postcss');
20
- var resolve = require('@rollup/plugin-node-resolve');
21
- var presetBabel = require('@doracli/preset-babel');
22
-
23
- var _documentCurrentScript =
24
- typeof document !== 'undefined' ? document.currentScript : null;
25
- function _arrayLikeToArray(r, a) {
26
- (null == a || a > r.length) && (a = r.length);
27
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
28
- return n;
29
- }
30
- function _arrayWithHoles(r) {
31
- if (Array.isArray(r)) return r;
32
- }
33
- function _arrayWithoutHoles(r) {
34
- if (Array.isArray(r)) return _arrayLikeToArray(r);
35
- }
36
- function _assertThisInitialized(e) {
37
- if (void 0 === e)
38
- throw new ReferenceError(
39
- "this hasn't been initialised - super() hasn't been called"
40
- );
41
- return e;
42
- }
43
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
44
- try {
45
- var i = n[a](c),
46
- u = i.value;
47
- } catch (n) {
48
- return void e(n);
49
- }
50
- i.done ? t(u) : Promise.resolve(u).then(r, o);
51
- }
52
- function _asyncToGenerator(n) {
53
- return function () {
54
- var t = this,
55
- e = arguments;
56
- return new Promise(function (r, o) {
57
- var a = n.apply(t, e);
58
- function _next(n) {
59
- asyncGeneratorStep(a, r, o, _next, _throw, 'next', n);
60
- }
61
- function _throw(n) {
62
- asyncGeneratorStep(a, r, o, _next, _throw, 'throw', n);
63
- }
64
- _next(void 0);
65
- });
66
- };
67
- }
68
- function _callSuper(t, o, e) {
69
- return (
70
- (o = _getPrototypeOf(o)),
71
- _possibleConstructorReturn(
72
- t,
73
- _isNativeReflectConstruct()
74
- ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor)
75
- : o.apply(t, e)
76
- )
77
- );
78
- }
79
- function _classCallCheck(a, n) {
80
- if (!(a instanceof n))
81
- throw new TypeError('Cannot call a class as a function');
82
- }
83
- function _defineProperties(e, r) {
84
- for (var t = 0; t < r.length; t++) {
85
- var o = r[t];
86
- ((o.enumerable = o.enumerable || false),
87
- (o.configurable = true),
88
- 'value' in o && (o.writable = true),
89
- Object.defineProperty(e, _toPropertyKey(o.key), o));
90
- }
91
- }
92
- function _createClass(e, r, t) {
93
- return (
94
- r && _defineProperties(e.prototype, r),
95
- Object.defineProperty(e, 'prototype', {
96
- writable: false,
97
- }),
98
- e
99
- );
100
- }
101
- function _defineProperty(e, r, t) {
102
- return (
103
- (r = _toPropertyKey(r)) in e
104
- ? Object.defineProperty(e, r, {
105
- value: t,
106
- enumerable: true,
107
- configurable: true,
108
- writable: true,
109
- })
110
- : (e[r] = t),
111
- e
112
- );
113
- }
114
- function _getPrototypeOf(t) {
115
- return (
116
- (_getPrototypeOf = Object.setPrototypeOf
117
- ? Object.getPrototypeOf.bind()
118
- : function (t) {
119
- return t.__proto__ || Object.getPrototypeOf(t);
120
- }),
121
- _getPrototypeOf(t)
122
- );
123
- }
124
- function _inherits(t, e) {
125
- if ('function' != typeof e && null !== e)
126
- throw new TypeError('Super expression must either be null or a function');
127
- ((t.prototype = Object.create(e && e.prototype, {
128
- constructor: {
129
- value: t,
130
- writable: true,
131
- configurable: true,
132
- },
133
- })),
134
- Object.defineProperty(t, 'prototype', {
135
- writable: false,
136
- }),
137
- e && _setPrototypeOf(t, e));
138
- }
139
- function _isNativeReflectConstruct() {
140
- try {
141
- var t = !Boolean.prototype.valueOf.call(
142
- Reflect.construct(Boolean, [], function () {})
143
- );
144
- } catch (t) {}
145
- return (_isNativeReflectConstruct = function () {
146
- return !!t;
147
- })();
148
- }
149
- function _iterableToArray(r) {
150
- if (
151
- ('undefined' != typeof Symbol && null != r[Symbol.iterator]) ||
152
- null != r['@@iterator']
153
- )
154
- return Array.from(r);
155
- }
156
- function _iterableToArrayLimit(r, l) {
157
- var t =
158
- null == r
159
- ? null
160
- : ('undefined' != typeof Symbol && r[Symbol.iterator]) || r['@@iterator'];
161
- if (null != t) {
162
- var e,
163
- n,
164
- i,
165
- u,
166
- a = [],
167
- f = true,
168
- o = false;
169
- try {
170
- if (((i = (t = t.call(r)).next), 0 === l));
171
- else
172
- for (
173
- ;
174
- !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l);
175
- f = !0
176
- );
177
- } catch (r) {
178
- ((o = true), (n = r));
179
- } finally {
180
- try {
181
- if (!f && null != t.return && ((u = t.return()), Object(u) !== u))
182
- return;
183
- } finally {
184
- if (o) throw n;
185
- }
186
- }
187
- return a;
188
- }
189
- }
190
- function _nonIterableRest() {
191
- throw new TypeError(
192
- 'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
193
- );
194
- }
195
- function _nonIterableSpread() {
196
- throw new TypeError(
197
- 'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
198
- );
199
- }
200
- function ownKeys(e, r) {
201
- var t = Object.keys(e);
202
- if (Object.getOwnPropertySymbols) {
203
- var o = Object.getOwnPropertySymbols(e);
204
- (r &&
205
- (o = o.filter(function (r) {
206
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
207
- })),
208
- t.push.apply(t, o));
209
- }
210
- return t;
211
- }
212
- function _objectSpread2(e) {
213
- for (var r = 1; r < arguments.length; r++) {
214
- var t = null != arguments[r] ? arguments[r] : {};
215
- r % 2
216
- ? ownKeys(Object(t), true).forEach(function (r) {
217
- _defineProperty(e, r, t[r]);
218
- })
219
- : Object.getOwnPropertyDescriptors
220
- ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))
221
- : ownKeys(Object(t)).forEach(function (r) {
222
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
223
- });
224
- }
225
- return e;
226
- }
227
- function _objectWithoutProperties(e, t) {
228
- if (null == e) return {};
229
- var o,
230
- r,
231
- i = _objectWithoutPropertiesLoose(e, t);
232
- if (Object.getOwnPropertySymbols) {
233
- var n = Object.getOwnPropertySymbols(e);
234
- for (r = 0; r < n.length; r++)
235
- ((o = n[r]),
236
- -1 === t.indexOf(o) &&
237
- {}.propertyIsEnumerable.call(e, o) &&
238
- (i[o] = e[o]));
239
- }
240
- return i;
241
- }
242
- function _objectWithoutPropertiesLoose(r, e) {
243
- if (null == r) return {};
244
- var t = {};
245
- for (var n in r)
246
- if ({}.hasOwnProperty.call(r, n)) {
247
- if (-1 !== e.indexOf(n)) continue;
248
- t[n] = r[n];
249
- }
250
- return t;
251
- }
252
- function _possibleConstructorReturn(t, e) {
253
- if (e && ('object' == typeof e || 'function' == typeof e)) return e;
254
- if (void 0 !== e)
255
- throw new TypeError(
256
- 'Derived constructors may only return object or undefined'
257
- );
258
- return _assertThisInitialized(t);
259
- }
260
- function _regenerator() {
261
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
262
- var e,
263
- t,
264
- r = 'function' == typeof Symbol ? Symbol : {},
265
- n = r.iterator || '@@iterator',
266
- o = r.toStringTag || '@@toStringTag';
267
- function i(r, n, o, i) {
268
- var c = n && n.prototype instanceof Generator ? n : Generator,
269
- u = Object.create(c.prototype);
270
- return (
271
- _regeneratorDefine(
272
- u,
273
- '_invoke',
274
- (function (r, n, o) {
275
- var i,
276
- c,
277
- u,
278
- f = 0,
279
- p = o || [],
280
- y = false,
281
- G = {
282
- p: 0,
283
- n: 0,
284
- v: e,
285
- a: d,
286
- f: d.bind(e, 4),
287
- d: function (t, r) {
288
- return ((i = t), (c = 0), (u = e), (G.n = r), a);
289
- },
290
- };
291
- function d(r, n) {
292
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
293
- var o,
294
- i = p[t],
295
- d = G.p,
296
- l = i[2];
297
- r > 3
298
- ? (o = l === n) &&
299
- ((u = i[(c = i[4]) ? 5 : ((c = 3), 3)]), (i[4] = i[5] = e))
300
- : i[0] <= d &&
301
- ((o = r < 2 && d < i[1])
302
- ? ((c = 0), (G.v = n), (G.n = i[1]))
303
- : d < l &&
304
- (o = r < 3 || i[0] > n || n > l) &&
305
- ((i[4] = r), (i[5] = n), (G.n = l), (c = 0)));
306
- }
307
- if (o || r > 1) return a;
308
- throw ((y = true), n);
309
- }
310
- return function (o, p, l) {
311
- if (f > 1) throw TypeError('Generator is already running');
312
- for (
313
- y && 1 === p && d(p, l), c = p, u = l;
314
- (t = c < 2 ? e : u) || !y;
315
-
316
- ) {
317
- i ||
318
- (c
319
- ? c < 3
320
- ? (c > 1 && (G.n = -1), d(c, u))
321
- : (G.n = u)
322
- : (G.v = u));
323
- try {
324
- if (((f = 2), i)) {
325
- if ((c || (o = 'next'), (t = i[o]))) {
326
- if (!(t = t.call(i, u)))
327
- throw TypeError('iterator result is not an object');
328
- if (!t.done) return t;
329
- ((u = t.value), c < 2 && (c = 0));
330
- } else
331
- (1 === c && (t = i.return) && t.call(i),
332
- c < 2 &&
333
- ((u = TypeError(
334
- "The iterator does not provide a '" + o + "' method"
335
- )),
336
- (c = 1)));
337
- i = e;
338
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
339
- } catch (t) {
340
- ((i = e), (c = 1), (u = t));
341
- } finally {
342
- f = 1;
343
- }
344
- }
345
- return {
346
- value: t,
347
- done: y,
348
- };
349
- };
350
- })(r, o, i),
351
- true
352
- ),
353
- u
354
- );
355
- }
356
- var a = {};
357
- function Generator() {}
358
- function GeneratorFunction() {}
359
- function GeneratorFunctionPrototype() {}
360
- t = Object.getPrototypeOf;
361
- var c = [][n]
362
- ? t(t([][n]()))
363
- : (_regeneratorDefine((t = {}), n, function () {
364
- return this;
365
- }),
366
- t),
367
- u =
368
- (GeneratorFunctionPrototype.prototype =
369
- Generator.prototype =
370
- Object.create(c));
371
- function f(e) {
372
- return (
373
- Object.setPrototypeOf
374
- ? Object.setPrototypeOf(e, GeneratorFunctionPrototype)
375
- : ((e.__proto__ = GeneratorFunctionPrototype),
376
- _regeneratorDefine(e, o, 'GeneratorFunction')),
377
- (e.prototype = Object.create(u)),
378
- e
379
- );
380
- }
381
- return (
382
- (GeneratorFunction.prototype = GeneratorFunctionPrototype),
383
- _regeneratorDefine(u, 'constructor', GeneratorFunctionPrototype),
384
- _regeneratorDefine(
385
- GeneratorFunctionPrototype,
386
- 'constructor',
387
- GeneratorFunction
388
- ),
389
- (GeneratorFunction.displayName = 'GeneratorFunction'),
390
- _regeneratorDefine(GeneratorFunctionPrototype, o, 'GeneratorFunction'),
391
- _regeneratorDefine(u),
392
- _regeneratorDefine(u, o, 'Generator'),
393
- _regeneratorDefine(u, n, function () {
394
- return this;
395
- }),
396
- _regeneratorDefine(u, 'toString', function () {
397
- return '[object Generator]';
398
- }),
399
- (_regenerator = function () {
400
- return {
401
- w: i,
402
- m: f,
403
- };
404
- })()
405
- );
406
- }
407
- function _regeneratorDefine(e, r, n, t) {
408
- var i = Object.defineProperty;
409
- try {
410
- i({}, '', {});
411
- } catch (e) {
412
- i = 0;
413
- }
414
- ((_regeneratorDefine = function (e, r, n, t) {
415
- function o(r, n) {
416
- _regeneratorDefine(e, r, function (e) {
417
- return this._invoke(r, n, e);
418
- });
419
- }
420
- r
421
- ? i
422
- ? i(e, r, {
423
- value: n,
424
- enumerable: !t,
425
- configurable: !t,
426
- writable: !t,
427
- })
428
- : (e[r] = n)
429
- : (o('next', 0), o('throw', 1), o('return', 2));
430
- }),
431
- _regeneratorDefine(e, r, n, t));
432
- }
433
- function _setPrototypeOf(t, e) {
434
- return (
435
- (_setPrototypeOf = Object.setPrototypeOf
436
- ? Object.setPrototypeOf.bind()
437
- : function (t, e) {
438
- return ((t.__proto__ = e), t);
439
- }),
440
- _setPrototypeOf(t, e)
441
- );
442
- }
443
- function _slicedToArray(r, e) {
444
- return (
445
- _arrayWithHoles(r) ||
446
- _iterableToArrayLimit(r, e) ||
447
- _unsupportedIterableToArray(r, e) ||
448
- _nonIterableRest()
449
- );
450
- }
451
- function _toConsumableArray(r) {
452
- return (
453
- _arrayWithoutHoles(r) ||
454
- _iterableToArray(r) ||
455
- _unsupportedIterableToArray(r) ||
456
- _nonIterableSpread()
457
- );
458
- }
459
- function _toPrimitive(t, r) {
460
- if ('object' != typeof t || !t) return t;
461
- var e = t[Symbol.toPrimitive];
462
- if (void 0 !== e) {
463
- var i = e.call(t, r);
464
- if ('object' != typeof i) return i;
465
- throw new TypeError('@@toPrimitive must return a primitive value.');
466
- }
467
- return ('string' === r ? String : Number)(t);
468
- }
469
- function _toPropertyKey(t) {
470
- var i = _toPrimitive(t, 'string');
471
- return 'symbol' == typeof i ? i : i + '';
472
- }
473
- function _unsupportedIterableToArray(r, a) {
474
- if (r) {
475
- if ('string' == typeof r) return _arrayLikeToArray(r, a);
476
- var t = {}.toString.call(r).slice(8, -1);
477
- return (
478
- 'Object' === t && r.constructor && (t = r.constructor.name),
479
- 'Map' === t || 'Set' === t
480
- ? Array.from(r)
481
- : 'Arguments' === t ||
482
- /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)
483
- ? _arrayLikeToArray(r, a)
484
- : void 0
485
- );
486
- }
487
- }
488
-
489
- var mergeRollupOptions = function mergeRollupOptions(first, second) {
490
- if (!first) return second;
491
- if (!second) return first;
492
- return _objectSpread2(_objectSpread2({}, first), second);
493
- };
494
-
495
- var Compiler = /*#__PURE__*/ (function (_CompilerBase) {
496
- function Compiler() {
497
- var _this;
498
- _classCallCheck(this, Compiler);
499
- for (
500
- var _len = arguments.length, args = new Array(_len), _key = 0;
501
- _key < _len;
502
- _key++
503
- ) {
504
- args[_key] = arguments[_key];
505
- }
506
- _this = _callSuper(this, Compiler, [].concat(args));
507
- _defineProperty(
508
- _this,
509
- 'context',
510
- /*#__PURE__*/ (function () {
511
- var _ref = _asyncToGenerator(
512
- /*#__PURE__*/ _regenerator().m(function _callee3(options) {
513
- var rollupBuild, outputList;
514
- return _regenerator().w(function (_context3) {
515
- while (1)
516
- switch (_context3.n) {
517
- case 0:
518
- _context3.n = 1;
519
- return rollup.rollup(
520
- mergeRollupOptions(_this.initOptions, options)
521
- );
522
- case 1:
523
- rollupBuild = _context3.v;
524
- outputList = [];
525
- if (options.output) {
526
- outputList = lang.isArray(options.output)
527
- ? options.output
528
- : [options.output];
529
- }
530
- return _context3.a(
531
- 2,
532
- Promise.resolve({
533
- rebuild: (function () {
534
- var _rebuild = _asyncToGenerator(
535
- /*#__PURE__*/ _regenerator().m(function _callee() {
536
- var outputOptions, i, output, writeRes;
537
- return _regenerator().w(function (_context) {
538
- while (1)
539
- switch (_context.n) {
540
- case 0:
541
- outputOptions = [];
542
- i = 0;
543
- case 1:
544
- if (!(i < outputList.length)) {
545
- _context.n = 4;
546
- break;
547
- }
548
- output = outputList[i];
549
- _context.n = 2;
550
- return rollupBuild.write(output);
551
- case 2:
552
- writeRes = _context.v;
553
- outputOptions.push(writeRes);
554
- case 3:
555
- i++;
556
- _context.n = 1;
557
- break;
558
- case 4:
559
- return _context.a(
560
- 2,
561
- Promise.resolve({
562
- rollupBuild: rollupBuild,
563
- outputOptions: outputOptions,
564
- })
565
- );
566
- }
567
- }, _callee);
568
- })
569
- );
570
- function rebuild() {
571
- return _rebuild.apply(this, arguments);
572
- }
573
- return rebuild;
574
- })(),
575
- cancel: (function () {
576
- var _cancel = _asyncToGenerator(
577
- /*#__PURE__*/ _regenerator().m(function _callee2() {
578
- return _regenerator().w(function (_context2) {
579
- while (1)
580
- switch (_context2.n) {
581
- case 0:
582
- helper.cLog.warn(
583
- 'build',
584
- 'empty',
585
- 'Rollup does not need to be canceled.'
586
- );
587
- case 1:
588
- return _context2.a(2);
589
- }
590
- }, _callee2);
591
- })
592
- );
593
- function cancel() {
594
- return _cancel.apply(this, arguments);
595
- }
596
- return cancel;
597
- })(),
598
- })
599
- );
600
- }
601
- }, _callee3);
602
- })
603
- );
604
- return function (_x) {
605
- return _ref.apply(this, arguments);
606
- };
607
- })()
608
- );
609
- _defineProperty(
610
- _this,
611
- 'inOutMap',
612
- /*#__PURE__*/ (function () {
613
- var _ref2 = _asyncToGenerator(
614
- /*#__PURE__*/ _regenerator().m(function _callee4(inputOutputMap) {
615
- var input;
616
- return _regenerator().w(function (_context4) {
617
- while (1)
618
- switch (_context4.n) {
619
- case 0:
620
- input = {};
621
- Object.entries(inputOutputMap).forEach(function (_ref3) {
622
- var _ref4 = _slicedToArray(_ref3, 2),
623
- input = _ref4[0],
624
- output = _ref4[1];
625
- input[output] = input;
626
- });
627
- return _context4.a(
628
- 2,
629
- _this.build({
630
- input: input,
631
- })
632
- );
633
- }
634
- }, _callee4);
635
- })
636
- );
637
- return function (_x2) {
638
- return _ref2.apply(this, arguments);
639
- };
640
- })()
641
- );
642
- _defineProperty(
643
- _this,
644
- 'input',
645
- /*#__PURE__*/ (function () {
646
- var _ref5 = _asyncToGenerator(
647
- /*#__PURE__*/ _regenerator().m(function _callee6(input) {
648
- var rollupBuild;
649
- return _regenerator().w(function (_context6) {
650
- while (1)
651
- switch (_context6.n) {
652
- case 0:
653
- _context6.n = 1;
654
- return rollup.rollup(
655
- mergeRollupOptions(_this.initOptions, {
656
- input: input || _this.initOptions.input,
657
- })
658
- );
659
- case 1:
660
- rollupBuild = _context6.v;
661
- return _context6.a(2, {
662
- output: (function () {
663
- var _output2 = _asyncToGenerator(
664
- /*#__PURE__*/ _regenerator().m(
665
- function _callee5(_output) {
666
- var writeRes;
667
- return _regenerator().w(function (_context5) {
668
- while (1)
669
- switch (_context5.n) {
670
- case 0:
671
- _context5.n = 1;
672
- return rollupBuild.write(_output);
673
- case 1:
674
- writeRes = _context5.v;
675
- return _context5.a(2, {
676
- rollupBuild: rollupBuild,
677
- outputOption: writeRes,
678
- });
679
- }
680
- }, _callee5);
681
- }
682
- )
683
- );
684
- function output(_x4) {
685
- return _output2.apply(this, arguments);
686
- }
687
- return output;
688
- })(),
689
- });
690
- }
691
- }, _callee6);
692
- })
693
- );
694
- return function (_x3) {
695
- return _ref5.apply(this, arguments);
696
- };
697
- })()
698
- );
699
- _defineProperty(
700
- _this,
701
- 'build',
702
- /*#__PURE__*/ (function () {
703
- var _ref6 = _asyncToGenerator(
704
- /*#__PURE__*/ _regenerator().m(function _callee7(options) {
705
- var rollupBuild, outputList, outputOptions, i, output, writeRes;
706
- return _regenerator().w(function (_context7) {
707
- while (1)
708
- switch (_context7.n) {
709
- case 0:
710
- _context7.n = 1;
711
- return rollup.rollup(
712
- mergeRollupOptions(_this.initOptions, options)
713
- );
714
- case 1:
715
- rollupBuild = _context7.v;
716
- outputList = [];
717
- if (options.output) {
718
- outputList = lang.isArray(options.output)
719
- ? options.output
720
- : [options.output];
721
- }
722
- outputOptions = [];
723
- i = 0;
724
- case 2:
725
- if (!(i < outputList.length)) {
726
- _context7.n = 5;
727
- break;
728
- }
729
- output = outputList[i];
730
- _context7.n = 3;
731
- return rollupBuild.write(output);
732
- case 3:
733
- writeRes = _context7.v;
734
- outputOptions.push(writeRes);
735
- case 4:
736
- i++;
737
- _context7.n = 2;
738
- break;
739
- case 5:
740
- return _context7.a(2, {
741
- rollupBuild: rollupBuild,
742
- outputOptions: outputOptions,
743
- });
744
- }
745
- }, _callee7);
746
- })
747
- );
748
- return function (_x5) {
749
- return _ref6.apply(this, arguments);
750
- };
751
- })()
752
- );
753
- _defineProperty(_this, 'watch', function (options) {
754
- var watchOptions = mergeRollupOptions(_this.initOptions, options);
755
- return rollup.watch(watchOptions);
756
- });
757
- _defineProperty(
758
- _this,
759
- 'server',
760
- /*#__PURE__*/ _asyncToGenerator(
761
- /*#__PURE__*/ _regenerator().m(function _callee8() {
762
- return _regenerator().w(function (_context8) {
763
- while (1)
764
- switch (_context8.n) {
765
- case 0:
766
- helper.cLog.warn(
767
- 'serve',
768
- 'empty',
769
- 'Rollup does not support serve functionality.'
770
- );
771
- return _context8.a(2);
772
- }
773
- }, _callee8);
774
- })
775
- )
776
- );
777
- return _this;
778
- }
779
- _inherits(Compiler, _CompilerBase);
780
- return _createClass(Compiler);
781
- })(helper.CompilerBase);
782
-
783
- /**
784
- * 获取external配置
785
- * @param envParams 环境参数
786
- * @param options 用户配置的external选项
787
- * @returns TExternalOption
788
- */
789
- var getExternal = function getExternal(_envParams, options) {
790
- var _ref = options || {},
791
- dependencies = _ref.dependencies,
792
- devDependencies = _ref.devDependencies,
793
- peerDependencies = _ref.peerDependencies,
794
- externals = _ref.externals,
795
- internals = _ref.internals,
796
- filter = _ref.filter;
797
- if (filter) return filter;
798
-
799
- // 需要打包的模块
800
- var internalsMap = lang.isArray(internals)
801
- ? internals.reduce(function (prev, cur) {
802
- prev[cur] = cur;
803
- return prev;
804
- }, {})
805
- : internals || {};
806
-
807
- // 不需要打包的模块
808
- var extraExternals = lang.isArray(externals)
809
- ? externals
810
- : Object.keys(externals || {});
811
- var obj = _objectSpread2(
812
- _objectSpread2(_objectSpread2({}, dependencies), peerDependencies),
813
- devDependencies
814
- );
815
- var externalList = Object.keys(obj)
816
- .concat(extraExternals)
817
- .filter(function (key) {
818
- return !internalsMap[key];
819
- });
820
- return function (source, _importer, _isResolved) {
821
- if (/^@doracli\//.test(source)) return true;
822
- var isExternal = externalList.find(function (externalModule) {
823
- return source.startsWith(externalModule);
824
- });
825
- return !!isExternal;
826
- };
827
- };
828
-
829
- /**
830
- * 获取入口文件
831
- * @description input 不传,则自动寻找
832
- * @param envParams 环境参数
833
- * @param input 入口文件路径
834
- * @returnscj
835
- */
836
- var getInput = /*#__PURE__*/ (function () {
837
- var _ref = _asyncToGenerator(
838
- /*#__PURE__*/ _regenerator().m(function _callee(envParams, input) {
839
- var workRootDir, rightFile;
840
- return _regenerator().w(function (_context) {
841
- while (1)
842
- switch (_context.n) {
843
- case 0:
844
- workRootDir = envParams.workRootDir;
845
- rightFile = input;
846
- if (!lang.isString(input)) {
847
- _context.n = 2;
848
- break;
849
- }
850
- _context.n = 1;
851
- return filePro.isValidDir(input);
852
- case 1:
853
- if (_context.v) {
854
- _context.n = 2;
855
- break;
856
- }
857
- helper.cLog.warn(
858
- 'rollup',
859
- 'input',
860
- '\u65E0\u6709\u6548\u5165\u53E3\u8DEF\u5F84 '.concat(
861
- input,
862
- '\uFF0C\u5C06\u81EA\u52A8\u5BFB\u627E\u6709\u6548\u8DEF\u5F84'
863
- )
864
- );
865
- rightFile = undefined;
866
- case 2:
867
- if (!rightFile) {
868
- rightFile = helper.findInput(workRootDir);
869
- }
870
- if (!rightFile) {
871
- helper.cLog.error(
872
- 'common',
873
- 'find_input',
874
- '需要有一个入口文件 index 或者 src/index'
875
- );
876
- process.exit();
877
- }
878
- helper.cLog.log(
879
- 'rollup',
880
- 'input',
881
- '\u5165\u53E3\u6587\u4EF6\u8DEF\u5F84 '.concat(rightFile)
882
- );
883
- return _context.a(2, rightFile);
884
- }
885
- }, _callee);
886
- })
887
- );
888
- return function getInput(_x, _x2) {
889
- return _ref.apply(this, arguments);
890
- };
891
- })();
892
-
893
- var _excluded$4 = ['format'];
894
- /**
895
- * 生成单个output
896
- * @description 如果不配置output,则默认生成cjs格式的output,输出路径为`lib/index.js`
897
- * @description 自动组合完整的file
898
- * @param optionsOutput
899
- * @returns
900
- */
901
- var getOutput = function getOutput(envParams, options) {
902
- var workRootDir = envParams.workRootDir;
903
- if (!options) {
904
- return {
905
- file: path.join(workRootDir, 'lib/index.js'),
906
- format: 'esm',
907
- sourcemap: false,
908
- };
909
- }
910
- var format = options.format,
911
- outputOptions = _objectWithoutProperties(options, _excluded$4);
912
- var realFormat = format || 'esm';
913
- return _objectSpread2(
914
- {
915
- format: realFormat,
916
- sourcemap: false,
917
- },
918
- outputOptions
919
- );
920
- };
921
-
922
- var _excluded$3 = ['entries'];
923
-
924
- /**
925
- * 获取别名插件
926
- * @param config 快捷配置
927
- * @param pluginConfig 标准配置
928
- * @returns 别名插件
929
- */
930
- var getAliasPlugin = function getAliasPlugin(config, pluginConfig) {
931
- var userConfig = config.alias,
932
- tsConfigPath = config.tsConfigPath;
933
- var aliasObj = helper.getTsPathAlias(tsConfigPath || []);
934
- var _ref = pluginConfig || {},
935
- entries = _ref.entries,
936
- extPluginConfig = _objectWithoutProperties(_ref, _excluded$3);
937
- return alias(
938
- _objectSpread2(
939
- _objectSpread2({}, extPluginConfig),
940
- {},
941
- {
942
- entries: _objectSpread2(
943
- _objectSpread2(_objectSpread2({}, entries), userConfig),
944
- aliasObj
945
- ),
946
- }
947
- )
948
- );
949
- };
950
-
951
- /**
952
- * 获取Babel插件
953
- * @param _config 快捷配置
954
- * @param pluginConfig 标准配置
955
- * @returns Babel插件
956
- */
957
- var getBabelPlugin = function getBabelPlugin(_config, pluginConfig) {
958
- return babel(
959
- _objectSpread2(
960
- {
961
- babelrc: false,
962
- configFile: false,
963
- compact: false,
964
- cwd: filePro.getNodeModulesDir(
965
- filePro.getDirname({
966
- url:
967
- typeof document === 'undefined'
968
- ? require('u' + 'rl').pathToFileURL(__filename).href
969
- : (_documentCurrentScript &&
970
- _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' &&
971
- _documentCurrentScript.src) ||
972
- new URL('index.js', document.baseURI).href,
973
- })
974
- ),
975
- extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs'],
976
- ignore: ['node_modules/**'],
977
- babelHelpers: 'bundled',
978
- exclude: 'node_modules/**',
979
- },
980
- pluginConfig
981
- )
982
- );
983
- };
984
-
985
- /**
986
- * 获取CommonJS插件
987
- * @description 将 CommonJS 转换成 ES2015 模块供 Rollup 处理
988
- * @param _config
989
- * @param pluginConfig
990
- * @returns
991
- */
992
- var getCommonjsPlugin = function getCommonjsPlugin(_config, pluginConfig) {
993
- return commonjs(pluginConfig);
994
- };
995
-
996
- var _excluded$2 = ['targets'];
997
- /**
998
- * 获取拷贝插件
999
- * @param config 快捷配置
1000
- * @param pluginConfig 标准配置
1001
- * @returns 拷贝插件
1002
- */
1003
- var getCopyPlugin = function getCopyPlugin(config, pluginConfig) {
1004
- var _ref = config || {},
1005
- copyList = _ref.copyList;
1006
- var _ref2 = pluginConfig || {},
1007
- targets = _ref2.targets,
1008
- extPluginConfig = _objectWithoutProperties(_ref2, _excluded$2);
1009
- var resTargets = _toConsumableArray(targets || []);
1010
- if (copyList) {
1011
- resTargets.push.apply(resTargets, _toConsumableArray(copyList));
1012
- }
1013
- return copy(
1014
- _objectSpread2(
1015
- _objectSpread2({}, extPluginConfig),
1016
- {},
1017
- {
1018
- targets: resTargets,
1019
- }
1020
- )
1021
- );
1022
- };
1023
-
1024
- /**
1025
- * 获取 dts 插件
1026
- * @param _config
1027
- * @param pluginConfig
1028
- * @returns
1029
- */
1030
- var getDtsPlugin = function getDtsPlugin(_config, pluginConfig) {
1031
- return rollupPluginDts.dts(
1032
- _objectSpread2(
1033
- {
1034
- respectExternal: false,
1035
- tsconfig: 'tsconfig.json',
1036
- compilerOptions: {},
1037
- },
1038
- pluginConfig
1039
- )
1040
- );
1041
- };
1042
-
1043
- /**
1044
- * 获取Json插件
1045
- * @description 允许将 .json 文件作为 ES6 模块导入
1046
- * @param _config
1047
- * @param pluginConfig
1048
- * @returns
1049
- */
1050
- var getJsonPlugin = function getJsonPlugin(_config, pluginConfig) {
1051
- return json(pluginConfig);
1052
- };
1053
-
1054
- /**
1055
- * 获取代码压缩插件
1056
- * @returns Minimize插件
1057
- */
1058
- var getMinimizePlugin = function getMinimizePlugin() {
1059
- return terser();
1060
- };
1061
-
1062
- var _excluded$1 = ['plugins'];
1063
-
1064
- /**
1065
- * 创建Postcss插件
1066
- * @param config 快捷配置
1067
- * @param pluginConfig 标准配置
1068
- * @returns Postcss插件
1069
- */
1070
- var getPostcssPlugin = function getPostcssPlugin(config, pluginConfig) {
1071
- var minimize = config.minimize,
1072
- output = config.output;
1073
- var _ref = pluginConfig || {},
1074
- injectPlugin = _ref.plugins,
1075
- otherConfig = _objectWithoutProperties(_ref, _excluded$1);
1076
- var outputWhole = path.isAbsolute(output)
1077
- ? output
1078
- : path.resolve(process.cwd(), output);
1079
- var plugins = [
1080
- autoprefixer({
1081
- overrideBrowserslist: [
1082
- 'defaults',
1083
- 'not ie < 8',
1084
- 'last 2 versions',
1085
- '> 1%',
1086
- 'iOS 7',
1087
- 'last 3 iOS versions',
1088
- ],
1089
- }),
1090
- ].concat(_toConsumableArray(injectPlugin || []));
1091
- if (minimize) {
1092
- plugins.push(cssnanoPlugin());
1093
- }
1094
-
1095
- /**
1096
- * 输出文件锁,防止多次写入
1097
- * 当输出n个格式时,会被同时调用n次
1098
- */
1099
- var codeFileNameLock = '';
1100
- return postcss(
1101
- _objectSpread2(
1102
- {
1103
- plugins: plugins,
1104
- extract: true,
1105
- onExtract: (function () {
1106
- var _ref2 = _asyncToGenerator(
1107
- /*#__PURE__*/ _regenerator().m(function _callee(getExtracted) {
1108
- var _ref3, code, codeFileName, dir;
1109
- return _regenerator().w(function (_context) {
1110
- while (1)
1111
- switch (_context.n) {
1112
- case 0:
1113
- ((_ref3 = getExtracted()),
1114
- (code = _ref3.code),
1115
- (codeFileName = _ref3.codeFileName));
1116
- if (!(codeFileNameLock === codeFileName)) {
1117
- _context.n = 1;
1118
- break;
1119
- }
1120
- return _context.a(2, false);
1121
- case 1:
1122
- codeFileNameLock = codeFileName;
1123
- if (filePro.isValidFilePathSync(outputWhole)) {
1124
- fs.rmSync(outputWhole, {
1125
- recursive: true,
1126
- force: true,
1127
- });
1128
- }
1129
- dir = path.dirname(outputWhole);
1130
- _context.n = 2;
1131
- return filePro.mkdirRecursive(dir);
1132
- case 2:
1133
- _context.n = 3;
1134
- return promises.writeFile(outputWhole, code);
1135
- case 3:
1136
- helper.cLog.info(
1137
- 'style',
1138
- 'success',
1139
- '\u8F93\u51FA\u7C7B\u578B => css\uFF1B',
1140
- '\u8DEF\u5F84 =>'.concat(
1141
- path.relative(filePro.getCwd(), outputWhole)
1142
- )
1143
- );
1144
- codeFileNameLock = '';
1145
- return _context.a(2, false);
1146
- }
1147
- }, _callee);
1148
- })
1149
- );
1150
- return function onExtract(_x) {
1151
- return _ref2.apply(this, arguments);
1152
- };
1153
- })(),
1154
- },
1155
- otherConfig
1156
- )
1157
- );
1158
- };
1159
-
1160
- /**
1161
- * 获取解析插件
1162
- * @param config 快捷配置
1163
- * @param pluginConfig 标准配置
1164
- * @returns 解析插件
1165
- */
1166
- var getResolvePlugin = function getResolvePlugin(config, pluginConfig) {
1167
- var extensions = config.extensions;
1168
- return resolve(
1169
- _objectSpread2(
1170
- {
1171
- extensions: extensions,
1172
- preferBuiltins: true,
1173
- },
1174
- pluginConfig
1175
- )
1176
- );
1177
- };
1178
-
1179
- /**
1180
- * 获取Node环境下的插件集合
1181
- * @param config 快捷配置
1182
- * @returns
1183
- */
1184
- var getNodePlugins = function getNodePlugins(config) {
1185
- var alias = config.alias,
1186
- minimize = config.minimize,
1187
- copyList = config.copyList;
1188
- var plugins = [
1189
- getResolvePlugin(
1190
- {
1191
- extensions: ['.js', '.ts', '.json'],
1192
- },
1193
- {
1194
- preferBuiltins: true,
1195
- }
1196
- ),
1197
- getAliasPlugin({
1198
- alias: _objectSpread2(
1199
- {
1200
- '@': 'src',
1201
- },
1202
- alias
1203
- ),
1204
- }),
1205
- getCopyPlugin({
1206
- copyList: copyList,
1207
- }),
1208
- getCommonjsPlugin(),
1209
- getJsonPlugin(),
1210
- ];
1211
- plugins.push(getBabelPlugin({}, presetBabel.nodeBabelPreset()));
1212
- if (minimize) {
1213
- plugins.push(getMinimizePlugin());
1214
- }
1215
- return plugins;
1216
- };
1217
-
1218
- /**
1219
- * 获取Node环境下的插件集合
1220
- * @param config 快捷配置
1221
- * @returns
1222
- */
1223
- var getReactPlugins = /*#__PURE__*/ (function () {
1224
- var _ref = _asyncToGenerator(
1225
- /*#__PURE__*/ _regenerator().m(function _callee(config) {
1226
- var alias,
1227
- minimize,
1228
- cssOutput,
1229
- copy,
1230
- plugins,
1231
- _t,
1232
- _t2,
1233
- _t3,
1234
- _t4,
1235
- _t5,
1236
- _t6;
1237
- return _regenerator().w(function (_context) {
1238
- while (1)
1239
- switch (_context.n) {
1240
- case 0:
1241
- ((alias = config.alias),
1242
- (minimize = config.minimize),
1243
- (cssOutput = config.cssOutput),
1244
- (copy = config.copy));
1245
- _context.n = 1;
1246
- return getPostcssPlugin({
1247
- minimize: !!minimize,
1248
- output: cssOutput || 'lib/css/index.css',
1249
- });
1250
- case 1:
1251
- _t = _context.v;
1252
- _t2 = getResolvePlugin(
1253
- {
1254
- extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs'],
1255
- },
1256
- {
1257
- preferBuiltins: true,
1258
- }
1259
- );
1260
- _t3 = getAliasPlugin({
1261
- alias: _objectSpread2(
1262
- {
1263
- '@': 'src',
1264
- },
1265
- alias
1266
- ),
1267
- });
1268
- _t4 = getCopyPlugin({
1269
- copyList: copy,
1270
- });
1271
- _t5 = getCommonjsPlugin();
1272
- _t6 = getJsonPlugin();
1273
- plugins = [_t, _t2, _t3, _t4, _t5, _t6];
1274
- plugins.push(getBabelPlugin({}, presetBabel.reactBabelPreset()));
1275
- if (minimize) {
1276
- plugins.push(getMinimizePlugin());
1277
- }
1278
- return _context.a(2, plugins);
1279
- }
1280
- }, _callee);
1281
- })
1282
- );
1283
- return function getReactPlugins(_x) {
1284
- return _ref.apply(this, arguments);
1285
- };
1286
- })();
1287
-
1288
- /**
1289
- * 获取watch配置
1290
- * @param options
1291
- * @returns
1292
- */
1293
- var getWatch = function getWatch(envParams, options) {
1294
- var workRootDir = envParams.workRootDir;
1295
- return _objectSpread2(
1296
- {
1297
- exclude: 'node_modules/**',
1298
- include: path.join(workRootDir, 'src/**'),
1299
- clearScreen: false,
1300
- skipWrite: false,
1301
- buildDelay: 500,
1302
- chokidar: {
1303
- usePolling: true,
1304
- },
1305
- },
1306
- options
1307
- );
1308
- };
1309
-
1310
- var envParamsMw = function envParamsMw(envParams) {
1311
- return function (ctx) {
1312
- return function (next) {
1313
- return /*#__PURE__*/ _asyncToGenerator(
1314
- /*#__PURE__*/ _regenerator().m(function _callee() {
1315
- return _regenerator().w(function (_context) {
1316
- while (1)
1317
- switch (_context.n) {
1318
- case 0:
1319
- ctx.updateEnvParams(envParams);
1320
- return _context.a(2, next());
1321
- }
1322
- }, _callee);
1323
- })
1324
- );
1325
- };
1326
- };
1327
- };
1328
-
1329
- var rollupExternalMw = function rollupExternalMw() {
1330
- return function (ctx) {
1331
- return function (next) {
1332
- return /*#__PURE__*/ _asyncToGenerator(
1333
- /*#__PURE__*/ _regenerator().m(function _callee() {
1334
- var _ref2,
1335
- dependencies,
1336
- devDependencies,
1337
- peerDependencies,
1338
- _ref3,
1339
- externals,
1340
- internals,
1341
- dependFilter;
1342
- return _regenerator().w(function (_context) {
1343
- while (1)
1344
- switch (_context.n) {
1345
- case 0:
1346
- ((_ref2 = ctx.configCtx.getPackageConfig() || {}),
1347
- (dependencies = _ref2.dependencies),
1348
- (devDependencies = _ref2.devDependencies),
1349
- (peerDependencies = _ref2.peerDependencies));
1350
- ((_ref3 = ctx.configCtx.getDoraConfig() || {}),
1351
- (externals = _ref3.externals),
1352
- (internals = _ref3.internals));
1353
- dependFilter = helper.createDependFilter({
1354
- dependencies: dependencies,
1355
- devDependencies: devDependencies,
1356
- peerDependencies: peerDependencies,
1357
- externals: externals,
1358
- internals: internals,
1359
- });
1360
- ctx.updateRollupOptions({
1361
- external: function external(moduleId) {
1362
- if (/^@doracli\//.test(moduleId)) return true;
1363
- return dependFilter(moduleId);
1364
- },
1365
- });
1366
- return _context.a(2, next());
1367
- }
1368
- }, _callee);
1369
- })
1370
- );
1371
- };
1372
- };
1373
- };
1374
- var rollupDtsExternalMw = function rollupDtsExternalMw() {
1375
- return function (ctx) {
1376
- return function (next) {
1377
- return /*#__PURE__*/ _asyncToGenerator(
1378
- /*#__PURE__*/ _regenerator().m(function _callee2() {
1379
- var external;
1380
- return _regenerator().w(function (_context2) {
1381
- while (1)
1382
- switch (_context2.n) {
1383
- case 0:
1384
- external = function external(id) {
1385
- if (
1386
- /\.(css|less|scss|sass|styl|png|jpe?g|svg|gif|webp|ico)$/.test(
1387
- id
1388
- )
1389
- ) {
1390
- return true;
1391
- }
1392
- return false;
1393
- };
1394
- ctx.updateRollupOptions({
1395
- external: external,
1396
- });
1397
- return _context2.a(2, next());
1398
- }
1399
- }, _callee2);
1400
- })
1401
- );
1402
- };
1403
- };
1404
- };
1405
-
1406
- var _excluded = ['file', 'dir', 'format'];
1407
- /**
1408
- * 获取运行时输出配置
1409
- * @param output
1410
- * @param isMultiple
1411
- * @param workRootDir
1412
- * @returns
1413
- */
1414
- var getOutputRuntime = function getOutputRuntime(
1415
- output,
1416
- isMultiple,
1417
- workRootDir
1418
- ) {
1419
- var file = output.file,
1420
- dir = output.dir,
1421
- format = output.format,
1422
- extOutput = _objectWithoutProperties(output, _excluded);
1423
- var fileWhole = isMultiple
1424
- ? path.join(workRootDir, dir, format, file)
1425
- : path.join(workRootDir, dir, file);
1426
- return _objectSpread2(
1427
- {
1428
- file: fileWhole,
1429
- format: format,
1430
- },
1431
- extOutput
1432
- );
1433
- };
1434
-
1435
- /**
1436
- * 从rollup配置中,获取第一个input
1437
- * @param inputOrigin
1438
- * @returns
1439
- */
1440
- var getFirstInput = function getFirstInput(inputOrigin) {
1441
- if (typeof inputOrigin === 'string') {
1442
- var name = filePro.getFilename(inputOrigin);
1443
- return {
1444
- path: inputOrigin,
1445
- name: name,
1446
- };
1447
- } else if (Array.isArray(inputOrigin) && inputOrigin.length > 0) {
1448
- var firstInput = inputOrigin[0];
1449
- var _name = filePro.getFilename(firstInput);
1450
- return {
1451
- path: firstInput,
1452
- name: _name,
1453
- };
1454
- } else if (lang.isObject(inputOrigin)) {
1455
- var firstKey = Object.keys(inputOrigin)[0];
1456
- var _firstInput = inputOrigin[firstKey];
1457
- return {
1458
- path: _firstInput,
1459
- name: firstKey,
1460
- };
1461
- }
1462
- return undefined;
1463
- };
1464
-
1465
- var rollupWatchLog = function rollupWatchLog(watcher) {
1466
- // event.code 可以是以下之一:
1467
- // START - 监视器正在(重新)启动
1468
- // BUNDLE_START - 单次打包
1469
- // * 如果存在,event.input 将是输入选项对象
1470
- // * event.output 包含生成的输出的 "file"
1471
- // 或 "dir" 选项值的数组
1472
- // BUNDLE_END - 完成打包
1473
- // * 如果存在,event.input 将是输入选项对象
1474
- // * event.output 包含生成的输出的 "file"
1475
- // 或 "dir" 选项值的数组
1476
- // * event.duration 是构建持续时间(以毫秒为单位)
1477
- // * event.result 包含 bundle 对象,
1478
- // 可以通过调用 bundle.generate
1479
- // 或 bundle.write 来生成其他输出。
1480
- // 当使用 watch.skipWrite 选项时,这尤其重要。
1481
- // 生成输出后,你应该调用 "event.result.close()",
1482
- // 或者如果你不生成输出,也应该调用。
1483
- // 这将允许插件通过
1484
- // "closeBundle" 钩子清理资源。
1485
- // END - 完成所有产物的构建
1486
- // ERROR - 在打包时遇到错误
1487
- // * event.error 包含抛出的错误
1488
- // * 对于构建错误,event.result 为 null,
1489
- // 对于输出生成错误,它包含 bundle 对象。
1490
- // 与 "BUNDLE_END" 一样,如果存在,
1491
- // 你应该在完成后调用 "event.result.close()"。
1492
- // 如果从事件处理程序返回一个 Promise,则 Rollup
1493
- // 将等待 Promise 解析后再继续。
1494
-
1495
- watcher.on('event', function (event) {
1496
- var _event$result;
1497
- switch (event.code) {
1498
- case 'BUNDLE_END':
1499
- // 这将确保在每次运行后正确关闭打包
1500
- helper.cLog.info(
1501
- 'serve',
1502
- event.code,
1503
- '\u5355\u6B21\u6253\u5305\u5B8C\u6210'
1504
- );
1505
- event.result.close();
1506
- break;
1507
- case 'ERROR':
1508
- helper.cLog.error(
1509
- 'serve',
1510
- event.code,
1511
- '\u5355\u6B21\u6253\u5305\u6355\u83B7\u5230\u9519\u8BEF'
1512
- );
1513
- handleError(event.error, true);
1514
- (_event$result = event.result) === null ||
1515
- _event$result === void 0 ||
1516
- _event$result.close();
1517
- break;
1518
- case 'BUNDLE_START':
1519
- helper.cLog.log(
1520
- 'serve',
1521
- event.code,
1522
- '\u5355\u6B21\u6253\u5305\u4E2D....'
1523
- );
1524
- break;
1525
- case 'END':
1526
- helper.cLog.info(
1527
- 'serve',
1528
- event.code,
1529
- '\u5B8C\u6210\u5355\u6B21\u6784\u5EFA'
1530
- );
1531
- break;
1532
- case 'START':
1533
- helper.cLog.log(
1534
- 'serve',
1535
- event.code,
1536
- '\u76D1\u89C6\u5668\u6B63\u5728\uFF08\u91CD\u65B0\uFF09\u542F\u52A8'
1537
- );
1538
- break;
1539
- }
1540
- });
1541
-
1542
- // 此外,你可以挂钩以下内容。
1543
- // 同样,返回 Promise 以使 Rollup 在该阶段等待:
1544
- watcher.on('change', function (id, _ref) {
1545
- var event = _ref.event;
1546
- /* 更改了一个文件 */
1547
- helper.cLog.log(
1548
- 'serve',
1549
- event.toUpperCase(),
1550
- ''
1551
- .concat('检测到文件变动'.padEnd(12, ' '), ' ')
1552
- .concat(helper.picocolors.cyan(path.relative(filePro.getCwd(), id)))
1553
- );
1554
- });
1555
- watcher.on('restart', function () {
1556
- /* 新触发了一次运行 */
1557
- helper.cLog.log('serve', 'restart'.toUpperCase(), '新触发了一次运行');
1558
- });
1559
- watcher.on('close', function () {
1560
- /* 监视器被关闭了,请看下面的代码 */
1561
- });
1562
- };
1563
- var _picocolors$createCol = helper.picocolors.createColors(),
1564
- bold = _picocolors$createCol.bold,
1565
- cyan = _picocolors$createCol.cyan,
1566
- dim = _picocolors$createCol.dim,
1567
- red = _picocolors$createCol.red;
1568
-
1569
- // log to stderr to keep `rollup main.js > bundle.js` from breaking
1570
- var stderr = function stderr() {
1571
- for (
1572
- var _len = arguments.length, parameters = new Array(_len), _key = 0;
1573
- _key < _len;
1574
- _key++
1575
- ) {
1576
- parameters[_key] = arguments[_key];
1577
- }
1578
- return process.stderr.write(''.concat(parameters.join(''), '\n'));
1579
- };
1580
- function handleError(error) {
1581
- var _error$cause;
1582
- var recover =
1583
- arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1584
- var name =
1585
- error.name ||
1586
- ((_error$cause = error.cause) === null || _error$cause === void 0
1587
- ? void 0
1588
- : _error$cause.name);
1589
- var nameSection = name ? ''.concat(name, ': ') : '';
1590
- var pluginSection = error.plugin ? '(plugin '.concat(error.plugin, ') ') : '';
1591
- var message = ''
1592
- .concat(pluginSection)
1593
- .concat(nameSection)
1594
- .concat(error.message);
1595
- var outputLines = [bold(red('[!] '.concat(bold(message.toString()))))];
1596
- if (error.url) {
1597
- outputLines.push(cyan(error.url));
1598
- }
1599
- if (error.loc) {
1600
- outputLines.push(
1601
- ' ('.concat(error.loc.line, ':').concat(error.loc.column, ')')
1602
- );
1603
- }
1604
- if (error.frame) {
1605
- outputLines.push(dim(error.frame));
1606
- }
1607
- if (error.stack) {
1608
- var _error$stack;
1609
- outputLines.push(
1610
- dim(
1611
- (_error$stack = error.stack) === null || _error$stack === void 0
1612
- ? void 0
1613
- : _error$stack.replace(
1614
- ''.concat(nameSection).concat(error.message, '\n'),
1615
- ''
1616
- )
1617
- )
1618
- );
1619
- }
1620
- outputLines.push('', '');
1621
- stderr(outputLines.join('\n'));
1622
- if (!recover) process.exit(1);
1623
- }
1624
-
1625
- var rollupInputMw = function rollupInputMw() {
1626
- return function (ctx) {
1627
- return function (next) {
1628
- return function () {
1629
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
1630
- input = _ctx$getDoraConfig.input;
1631
- var inputWhole = input;
1632
- if (!inputWhole) {
1633
- inputWhole = helper.findInput(ctx.envParams.workRootDir);
1634
- if (!inputWhole) {
1635
- helper.cLog.error(
1636
- 'common',
1637
- 'find_input',
1638
- '需要有一个入口文件 index 或者 src/index'
1639
- );
1640
- process.exit();
1641
- }
1642
- }
1643
- ctx.updateRollupOptions({
1644
- input: inputWhole,
1645
- });
1646
- return next();
1647
- };
1648
- };
1649
- };
1650
- };
1651
- var rollupOutputListMw = function rollupOutputListMw() {
1652
- return function (ctx) {
1653
- return function (next) {
1654
- return function () {
1655
- var _ctx$getDoraConfig2 = ctx.getDoraConfig(),
1656
- input = _ctx$getDoraConfig2.input,
1657
- output = _ctx$getDoraConfig2.output,
1658
- formatList = _ctx$getDoraConfig2.formatList;
1659
- var file = output.file,
1660
- path = output.path;
1661
- var outputFile = file;
1662
- if (!outputFile) {
1663
- var moduleName = filePro.getFilename(input);
1664
- outputFile = ''.concat(moduleName, '.js');
1665
- }
1666
- var outputList = formatList.map(function (format) {
1667
- return {
1668
- dir: path,
1669
- file: outputFile,
1670
- format: format,
1671
- };
1672
- });
1673
- ctx.updateRollupOutputList(outputList);
1674
- return next();
1675
- };
1676
- };
1677
- };
1678
- };
1679
- var rollupInoutMw = function rollupInoutMw() {
1680
- return function (ctx) {
1681
- return function (next) {
1682
- return /*#__PURE__*/ _asyncToGenerator(
1683
- /*#__PURE__*/ _regenerator().m(function _callee() {
1684
- var _ctx$getDoraConfig3,
1685
- input,
1686
- output,
1687
- formatList,
1688
- file,
1689
- path,
1690
- inputWhole,
1691
- outputFile,
1692
- moduleName,
1693
- outputList;
1694
- return _regenerator().w(function (_context) {
1695
- while (1)
1696
- switch (_context.n) {
1697
- case 0:
1698
- ((_ctx$getDoraConfig3 = ctx.getDoraConfig()),
1699
- (input = _ctx$getDoraConfig3.input),
1700
- (output = _ctx$getDoraConfig3.output),
1701
- (formatList = _ctx$getDoraConfig3.formatList));
1702
- ((file = output.file), (path = output.path));
1703
- inputWhole = input;
1704
- outputFile = file;
1705
- if (!inputWhole) {
1706
- inputWhole = helper.findInput(ctx.envParams.workRootDir);
1707
- if (!inputWhole) {
1708
- helper.cLog.error(
1709
- 'common',
1710
- 'find_input',
1711
- '需要有一个入口文件 index 或者 src/index'
1712
- );
1713
- process.exit();
1714
- }
1715
- }
1716
- if (!outputFile) {
1717
- moduleName = filePro.getFilename(inputWhole);
1718
- outputFile = ''.concat(moduleName, '.js');
1719
- }
1720
- outputList = formatList.map(function (format) {
1721
- return {
1722
- dir: path,
1723
- file: outputFile,
1724
- format: format,
1725
- };
1726
- });
1727
- ctx.updateRollupOptions({
1728
- input: inputWhole,
1729
- });
1730
- ctx.updateRollupOutputList(outputList);
1731
- return _context.a(2, next());
1732
- }
1733
- }, _callee);
1734
- })
1735
- );
1736
- };
1737
- };
1738
- };
1739
- var rollupWatchOutputMw = function rollupWatchOutputMw() {
1740
- return function (ctx) {
1741
- return function (next) {
1742
- return /*#__PURE__*/ _asyncToGenerator(
1743
- /*#__PURE__*/ _regenerator().m(function _callee2() {
1744
- return _regenerator().w(function (_context2) {
1745
- while (1)
1746
- switch (_context2.n) {
1747
- case 0:
1748
- ctx.updateRollupOptions({
1749
- output: ctx.rollupOutputList.map(function (output) {
1750
- return getOutputRuntime(
1751
- output,
1752
- ctx.rollupOutputList.length > 1,
1753
- ctx.envParams.workRootDir
1754
- );
1755
- }),
1756
- });
1757
- return _context2.a(2, next());
1758
- }
1759
- }, _callee2);
1760
- })
1761
- );
1762
- };
1763
- };
1764
- };
1765
- var rollupDtsInoutMw = function rollupDtsInoutMw() {
1766
- return function (ctx) {
1767
- return function (next) {
1768
- return /*#__PURE__*/ _asyncToGenerator(
1769
- /*#__PURE__*/ _regenerator().m(function _callee3() {
1770
- var _ctx$getDoraConfig4, output, dts, dtsInput, dtsOutput;
1771
- return _regenerator().w(function (_context3) {
1772
- while (1)
1773
- switch (_context3.n) {
1774
- case 0:
1775
- ((_ctx$getDoraConfig4 = ctx.getDoraConfig()),
1776
- (output = _ctx$getDoraConfig4.output),
1777
- (dts = _ctx$getDoraConfig4.dts));
1778
- if (dts) {
1779
- _context3.n = 1;
1780
- break;
1781
- }
1782
- return _context3.a(2);
1783
- case 1:
1784
- dtsInput =
1785
- (dts === null || dts === void 0 ? void 0 : dts.input) ||
1786
- ctx.rollupOptions.input;
1787
- dtsOutput =
1788
- (dts === null || dts === void 0 ? void 0 : dts.output) ||
1789
- path.resolve(output.path || './lib', 'type/index.d.ts');
1790
- ctx.updateRollupOptions({
1791
- input: dtsInput,
1792
- });
1793
- ctx.updateRollupOutputList([
1794
- {
1795
- file: dtsOutput,
1796
- },
1797
- ]);
1798
- return _context3.a(2, next());
1799
- }
1800
- }, _callee3);
1801
- })
1802
- );
1803
- };
1804
- };
1805
- };
1806
-
1807
- var insertTsMw = function insertTsMw() {
1808
- return function (ctx) {
1809
- return function (next) {
1810
- return /*#__PURE__*/ _asyncToGenerator(
1811
- /*#__PURE__*/ _regenerator().m(function _callee() {
1812
- var input;
1813
- return _regenerator().w(function (_context) {
1814
- while (1)
1815
- switch (_context.n) {
1816
- case 0:
1817
- input = ctx.rollupOptions.input;
1818
- if (!path.extname(input).toLowerCase().includes('ts')) {
1819
- _context.n = 1;
1820
- break;
1821
- }
1822
- _context.n = 1;
1823
- return helper.insertTsconfig(ctx.envParams.workRootDir);
1824
- case 1:
1825
- return _context.a(2, next());
1826
- }
1827
- }, _callee);
1828
- })
1829
- );
1830
- };
1831
- };
1832
- };
1833
-
1834
- var rollupReactPluginMw = function rollupReactPluginMw() {
1835
- return function (ctx) {
1836
- return function (next) {
1837
- return /*#__PURE__*/ _asyncToGenerator(
1838
- /*#__PURE__*/ _regenerator().m(function _callee() {
1839
- var _ctx$getDoraConfig,
1840
- minimize,
1841
- alias,
1842
- copy,
1843
- output,
1844
- path$1,
1845
- tsConfig,
1846
- tsAlias,
1847
- plugins;
1848
- return _regenerator().w(function (_context) {
1849
- while (1)
1850
- switch (_context.n) {
1851
- case 0:
1852
- ((_ctx$getDoraConfig = ctx.getDoraConfig()),
1853
- (minimize = _ctx$getDoraConfig.minimize),
1854
- (alias = _ctx$getDoraConfig.alias),
1855
- (copy = _ctx$getDoraConfig.copy),
1856
- (output = _ctx$getDoraConfig.output));
1857
- path$1 = output.path;
1858
- tsConfig = ctx.configCtx.getTsConfig();
1859
- tsAlias = helper.getTsPathAlias(tsConfig);
1860
- _context.n = 1;
1861
- return getReactPlugins({
1862
- minimize: minimize,
1863
- alias: _objectSpread2(_objectSpread2({}, tsAlias), alias),
1864
- copy: copy,
1865
- cssOutput: path.resolve(
1866
- ctx.envParams.workRootDir,
1867
- path$1,
1868
- 'style/index.css'
1869
- ),
1870
- });
1871
- case 1:
1872
- plugins = _context.v;
1873
- ctx.updateRollupOptions({
1874
- plugins: plugins,
1875
- });
1876
- return _context.a(2, next());
1877
- }
1878
- }, _callee);
1879
- })
1880
- );
1881
- };
1882
- };
1883
- };
1884
- var rollupNodePluginMw = function rollupNodePluginMw() {
1885
- return function (ctx) {
1886
- return function (next) {
1887
- return /*#__PURE__*/ _asyncToGenerator(
1888
- /*#__PURE__*/ _regenerator().m(function _callee2() {
1889
- var _ctx$getDoraConfig2, minimize, alias, tsConfig, tsAlias, plugins;
1890
- return _regenerator().w(function (_context2) {
1891
- while (1)
1892
- switch (_context2.n) {
1893
- case 0:
1894
- ((_ctx$getDoraConfig2 = ctx.getDoraConfig()),
1895
- (minimize = _ctx$getDoraConfig2.minimize),
1896
- (alias = _ctx$getDoraConfig2.alias));
1897
- tsConfig = ctx.configCtx.getTsConfig();
1898
- tsAlias = helper.getTsPathAlias(tsConfig);
1899
- _context2.n = 1;
1900
- return getNodePlugins({
1901
- minimize: minimize,
1902
- alias: _objectSpread2(_objectSpread2({}, tsAlias), alias),
1903
- });
1904
- case 1:
1905
- plugins = _context2.v;
1906
- ctx.updateRollupOptions({
1907
- plugins: plugins,
1908
- });
1909
- return _context2.a(2, next());
1910
- }
1911
- }, _callee2);
1912
- })
1913
- );
1914
- };
1915
- };
1916
- };
1917
- var rollupDtsPluginMw = function rollupDtsPluginMw() {
1918
- return function (ctx) {
1919
- return function (next) {
1920
- return /*#__PURE__*/ _asyncToGenerator(
1921
- /*#__PURE__*/ _regenerator().m(function _callee3() {
1922
- var plugins;
1923
- return _regenerator().w(function (_context3) {
1924
- while (1)
1925
- switch (_context3.n) {
1926
- case 0:
1927
- plugins = [
1928
- getResolvePlugin(
1929
- {
1930
- extensions: ['.ts'],
1931
- },
1932
- {
1933
- preferBuiltins: true,
1934
- }
1935
- ),
1936
- getDtsPlugin(),
1937
- ];
1938
- ctx.updateRollupOptions({
1939
- plugins: plugins,
1940
- });
1941
- return _context3.a(2, next());
1942
- }
1943
- }, _callee3);
1944
- })
1945
- );
1946
- };
1947
- };
1948
- };
1949
-
1950
- var rollupWatchMw = function rollupWatchMw() {
1951
- return function (ctx) {
1952
- return function (next) {
1953
- return /*#__PURE__*/ _asyncToGenerator(
1954
- /*#__PURE__*/ _regenerator().m(function _callee() {
1955
- var watch;
1956
- return _regenerator().w(function (_context) {
1957
- while (1)
1958
- switch (_context.n) {
1959
- case 0:
1960
- _context.n = 1;
1961
- return getWatch(ctx.envParams);
1962
- case 1:
1963
- watch = _context.v;
1964
- ctx.updateRollupOptions({
1965
- watch: watch,
1966
- });
1967
- return _context.a(2, next());
1968
- }
1969
- }, _callee);
1970
- })
1971
- );
1972
- };
1973
- };
1974
- };
1975
-
1976
- var Ctx = /*#__PURE__*/ (function () {
1977
- function Ctx(configCtx) {
1978
- _classCallCheck(this, Ctx);
1979
- _defineProperty(this, 'configCtx', void 0);
1980
- _defineProperty(this, 'rollupOptions', {});
1981
- _defineProperty(this, 'rollupOutputList', []);
1982
- _defineProperty(this, 'envParams', {
1983
- action: 'build',
1984
- workRootDir: filePro.getCwd(),
1985
- });
1986
- this.configCtx = configCtx;
1987
- }
1988
- return _createClass(Ctx, [
1989
- {
1990
- key: 'updateEnvParams',
1991
- value: function updateEnvParams(argv) {
1992
- this.envParams = _objectSpread2(
1993
- _objectSpread2({}, this.envParams),
1994
- argv
1995
- );
1996
- },
1997
- },
1998
- {
1999
- key: 'updateRollupOptions',
2000
- value: function updateRollupOptions(options) {
2001
- this.rollupOptions = _objectSpread2(
2002
- _objectSpread2({}, this.rollupOptions),
2003
- options
2004
- );
2005
- },
2006
- },
2007
- {
2008
- key: 'updateRollupOutputList',
2009
- value: function updateRollupOutputList(list) {
2010
- var force =
2011
- arguments.length > 1 && arguments[1] !== undefined
2012
- ? arguments[1]
2013
- : false;
2014
- if (force) {
2015
- this.rollupOutputList = list;
2016
- } else {
2017
- this.rollupOutputList = [].concat(
2018
- _toConsumableArray(this.rollupOutputList),
2019
- _toConsumableArray(list)
2020
- );
2021
- }
2022
- },
2023
- },
2024
- {
2025
- key: 'getDoraConfig',
2026
- value: function getDoraConfig() {
2027
- return this.configCtx.getDoraConfig();
2028
- },
2029
- },
2030
- {
2031
- key: 'geTDoraConfigRollup',
2032
- value: function geTDoraConfigRollup() {
2033
- return this.configCtx.getDoraConfig().rollupConfig || {};
2034
- },
2035
- },
2036
- ]);
2037
- })();
2038
-
2039
- exports.Compiler = Compiler;
2040
- exports.Ctx = Ctx;
2041
- exports.envParamsMw = envParamsMw;
2042
- exports.getAliasPlugin = getAliasPlugin;
2043
- exports.getBabelPlugin = getBabelPlugin;
2044
- exports.getCommonjsPlugin = getCommonjsPlugin;
2045
- exports.getCopyPlugin = getCopyPlugin;
2046
- exports.getDtsPlugin = getDtsPlugin;
2047
- exports.getExternal = getExternal;
2048
- exports.getFirstInput = getFirstInput;
2049
- exports.getInput = getInput;
2050
- exports.getJsonPlugin = getJsonPlugin;
2051
- exports.getMinimizePlugin = getMinimizePlugin;
2052
- exports.getNodePlugins = getNodePlugins;
2053
- exports.getOutput = getOutput;
2054
- exports.getOutputRuntime = getOutputRuntime;
2055
- exports.getPostcssPlugin = getPostcssPlugin;
2056
- exports.getReactPlugins = getReactPlugins;
2057
- exports.getResolvePlugin = getResolvePlugin;
2058
- exports.getWatch = getWatch;
2059
- exports.handleError = handleError;
2060
- exports.insertTsMw = insertTsMw;
2061
- exports.mergeRollupOptions = mergeRollupOptions;
2062
- exports.rollupDtsExternalMw = rollupDtsExternalMw;
2063
- exports.rollupDtsInoutMw = rollupDtsInoutMw;
2064
- exports.rollupDtsPluginMw = rollupDtsPluginMw;
2065
- exports.rollupExternalMw = rollupExternalMw;
2066
- exports.rollupInoutMw = rollupInoutMw;
2067
- exports.rollupInputMw = rollupInputMw;
2068
- exports.rollupNodePluginMw = rollupNodePluginMw;
2069
- exports.rollupOutputListMw = rollupOutputListMw;
2070
- exports.rollupReactPluginMw = rollupReactPluginMw;
2071
- exports.rollupWatchLog = rollupWatchLog;
2072
- exports.rollupWatchMw = rollupWatchMw;
2073
- exports.rollupWatchOutputMw = rollupWatchOutputMw;
1
+ 'use strict';
2
+
3
+ var rollup = require('rollup');
4
+ var lang = require('@cclr/lang');
5
+ var helper = require('@doracli/helper');
6
+ var filePro = require('@dorabag/file-pro');
7
+ var path = require('path');
8
+ var alias = require('@rollup/plugin-alias');
9
+ var babel = require('@rollup/plugin-babel');
10
+ var commonjs = require('@rollup/plugin-commonjs');
11
+ var copy = require('rollup-plugin-copy');
12
+ var rollupPluginDts = require('rollup-plugin-dts');
13
+ var json = require('@rollup/plugin-json');
14
+ var terser = require('@rollup/plugin-terser');
15
+ var autoprefixer = require('autoprefixer');
16
+ var cssnanoPlugin = require('cssnano');
17
+ var fs = require('fs');
18
+ var promises = require('fs/promises');
19
+ var postcss = require('rollup-plugin-postcss');
20
+ var resolve = require('@rollup/plugin-node-resolve');
21
+ var presetBabel = require('@doracli/preset-babel');
22
+
23
+ var _documentCurrentScript =
24
+ typeof document !== 'undefined' ? document.currentScript : null;
25
+ function _arrayLikeToArray(r, a) {
26
+ (null == a || a > r.length) && (a = r.length);
27
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
28
+ return n;
29
+ }
30
+ function _arrayWithHoles(r) {
31
+ if (Array.isArray(r)) return r;
32
+ }
33
+ function _arrayWithoutHoles(r) {
34
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
35
+ }
36
+ function _assertThisInitialized(e) {
37
+ if (void 0 === e)
38
+ throw new ReferenceError(
39
+ "this hasn't been initialised - super() hasn't been called"
40
+ );
41
+ return e;
42
+ }
43
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
44
+ try {
45
+ var i = n[a](c),
46
+ u = i.value;
47
+ } catch (n) {
48
+ return void e(n);
49
+ }
50
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
51
+ }
52
+ function _asyncToGenerator(n) {
53
+ return function () {
54
+ var t = this,
55
+ e = arguments;
56
+ return new Promise(function (r, o) {
57
+ var a = n.apply(t, e);
58
+ function _next(n) {
59
+ asyncGeneratorStep(a, r, o, _next, _throw, 'next', n);
60
+ }
61
+ function _throw(n) {
62
+ asyncGeneratorStep(a, r, o, _next, _throw, 'throw', n);
63
+ }
64
+ _next(void 0);
65
+ });
66
+ };
67
+ }
68
+ function _callSuper(t, o, e) {
69
+ return (
70
+ (o = _getPrototypeOf(o)),
71
+ _possibleConstructorReturn(
72
+ t,
73
+ _isNativeReflectConstruct()
74
+ ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor)
75
+ : o.apply(t, e)
76
+ )
77
+ );
78
+ }
79
+ function _classCallCheck(a, n) {
80
+ if (!(a instanceof n))
81
+ throw new TypeError('Cannot call a class as a function');
82
+ }
83
+ function _defineProperties(e, r) {
84
+ for (var t = 0; t < r.length; t++) {
85
+ var o = r[t];
86
+ ((o.enumerable = o.enumerable || false),
87
+ (o.configurable = true),
88
+ 'value' in o && (o.writable = true),
89
+ Object.defineProperty(e, _toPropertyKey(o.key), o));
90
+ }
91
+ }
92
+ function _createClass(e, r, t) {
93
+ return (
94
+ r && _defineProperties(e.prototype, r),
95
+ Object.defineProperty(e, 'prototype', {
96
+ writable: false,
97
+ }),
98
+ e
99
+ );
100
+ }
101
+ function _defineProperty(e, r, t) {
102
+ return (
103
+ (r = _toPropertyKey(r)) in e
104
+ ? Object.defineProperty(e, r, {
105
+ value: t,
106
+ enumerable: true,
107
+ configurable: true,
108
+ writable: true,
109
+ })
110
+ : (e[r] = t),
111
+ e
112
+ );
113
+ }
114
+ function _getPrototypeOf(t) {
115
+ return (
116
+ (_getPrototypeOf = Object.setPrototypeOf
117
+ ? Object.getPrototypeOf.bind()
118
+ : function (t) {
119
+ return t.__proto__ || Object.getPrototypeOf(t);
120
+ }),
121
+ _getPrototypeOf(t)
122
+ );
123
+ }
124
+ function _inherits(t, e) {
125
+ if ('function' != typeof e && null !== e)
126
+ throw new TypeError('Super expression must either be null or a function');
127
+ ((t.prototype = Object.create(e && e.prototype, {
128
+ constructor: {
129
+ value: t,
130
+ writable: true,
131
+ configurable: true,
132
+ },
133
+ })),
134
+ Object.defineProperty(t, 'prototype', {
135
+ writable: false,
136
+ }),
137
+ e && _setPrototypeOf(t, e));
138
+ }
139
+ function _isNativeReflectConstruct() {
140
+ try {
141
+ var t = !Boolean.prototype.valueOf.call(
142
+ Reflect.construct(Boolean, [], function () {})
143
+ );
144
+ } catch (t) {}
145
+ return (_isNativeReflectConstruct = function () {
146
+ return !!t;
147
+ })();
148
+ }
149
+ function _iterableToArray(r) {
150
+ if (
151
+ ('undefined' != typeof Symbol && null != r[Symbol.iterator]) ||
152
+ null != r['@@iterator']
153
+ )
154
+ return Array.from(r);
155
+ }
156
+ function _iterableToArrayLimit(r, l) {
157
+ var t =
158
+ null == r
159
+ ? null
160
+ : ('undefined' != typeof Symbol && r[Symbol.iterator]) || r['@@iterator'];
161
+ if (null != t) {
162
+ var e,
163
+ n,
164
+ i,
165
+ u,
166
+ a = [],
167
+ f = true,
168
+ o = false;
169
+ try {
170
+ if (((i = (t = t.call(r)).next), 0 === l));
171
+ else
172
+ for (
173
+ ;
174
+ !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l);
175
+ f = !0
176
+ );
177
+ } catch (r) {
178
+ ((o = true), (n = r));
179
+ } finally {
180
+ try {
181
+ if (!f && null != t.return && ((u = t.return()), Object(u) !== u))
182
+ return;
183
+ } finally {
184
+ if (o) throw n;
185
+ }
186
+ }
187
+ return a;
188
+ }
189
+ }
190
+ function _nonIterableRest() {
191
+ throw new TypeError(
192
+ 'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
193
+ );
194
+ }
195
+ function _nonIterableSpread() {
196
+ throw new TypeError(
197
+ 'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
198
+ );
199
+ }
200
+ function ownKeys(e, r) {
201
+ var t = Object.keys(e);
202
+ if (Object.getOwnPropertySymbols) {
203
+ var o = Object.getOwnPropertySymbols(e);
204
+ (r &&
205
+ (o = o.filter(function (r) {
206
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
207
+ })),
208
+ t.push.apply(t, o));
209
+ }
210
+ return t;
211
+ }
212
+ function _objectSpread2(e) {
213
+ for (var r = 1; r < arguments.length; r++) {
214
+ var t = null != arguments[r] ? arguments[r] : {};
215
+ r % 2
216
+ ? ownKeys(Object(t), true).forEach(function (r) {
217
+ _defineProperty(e, r, t[r]);
218
+ })
219
+ : Object.getOwnPropertyDescriptors
220
+ ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))
221
+ : ownKeys(Object(t)).forEach(function (r) {
222
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
223
+ });
224
+ }
225
+ return e;
226
+ }
227
+ function _objectWithoutProperties(e, t) {
228
+ if (null == e) return {};
229
+ var o,
230
+ r,
231
+ i = _objectWithoutPropertiesLoose(e, t);
232
+ if (Object.getOwnPropertySymbols) {
233
+ var n = Object.getOwnPropertySymbols(e);
234
+ for (r = 0; r < n.length; r++)
235
+ ((o = n[r]),
236
+ -1 === t.indexOf(o) &&
237
+ {}.propertyIsEnumerable.call(e, o) &&
238
+ (i[o] = e[o]));
239
+ }
240
+ return i;
241
+ }
242
+ function _objectWithoutPropertiesLoose(r, e) {
243
+ if (null == r) return {};
244
+ var t = {};
245
+ for (var n in r)
246
+ if ({}.hasOwnProperty.call(r, n)) {
247
+ if (-1 !== e.indexOf(n)) continue;
248
+ t[n] = r[n];
249
+ }
250
+ return t;
251
+ }
252
+ function _possibleConstructorReturn(t, e) {
253
+ if (e && ('object' == typeof e || 'function' == typeof e)) return e;
254
+ if (void 0 !== e)
255
+ throw new TypeError(
256
+ 'Derived constructors may only return object or undefined'
257
+ );
258
+ return _assertThisInitialized(t);
259
+ }
260
+ function _regenerator() {
261
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
262
+ var e,
263
+ t,
264
+ r = 'function' == typeof Symbol ? Symbol : {},
265
+ n = r.iterator || '@@iterator',
266
+ o = r.toStringTag || '@@toStringTag';
267
+ function i(r, n, o, i) {
268
+ var c = n && n.prototype instanceof Generator ? n : Generator,
269
+ u = Object.create(c.prototype);
270
+ return (
271
+ _regeneratorDefine(
272
+ u,
273
+ '_invoke',
274
+ (function (r, n, o) {
275
+ var i,
276
+ c,
277
+ u,
278
+ f = 0,
279
+ p = o || [],
280
+ y = false,
281
+ G = {
282
+ p: 0,
283
+ n: 0,
284
+ v: e,
285
+ a: d,
286
+ f: d.bind(e, 4),
287
+ d: function (t, r) {
288
+ return ((i = t), (c = 0), (u = e), (G.n = r), a);
289
+ },
290
+ };
291
+ function d(r, n) {
292
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
293
+ var o,
294
+ i = p[t],
295
+ d = G.p,
296
+ l = i[2];
297
+ r > 3
298
+ ? (o = l === n) &&
299
+ ((u = i[(c = i[4]) ? 5 : ((c = 3), 3)]), (i[4] = i[5] = e))
300
+ : i[0] <= d &&
301
+ ((o = r < 2 && d < i[1])
302
+ ? ((c = 0), (G.v = n), (G.n = i[1]))
303
+ : d < l &&
304
+ (o = r < 3 || i[0] > n || n > l) &&
305
+ ((i[4] = r), (i[5] = n), (G.n = l), (c = 0)));
306
+ }
307
+ if (o || r > 1) return a;
308
+ throw ((y = true), n);
309
+ }
310
+ return function (o, p, l) {
311
+ if (f > 1) throw TypeError('Generator is already running');
312
+ for (
313
+ y && 1 === p && d(p, l), c = p, u = l;
314
+ (t = c < 2 ? e : u) || !y;
315
+
316
+ ) {
317
+ i ||
318
+ (c
319
+ ? c < 3
320
+ ? (c > 1 && (G.n = -1), d(c, u))
321
+ : (G.n = u)
322
+ : (G.v = u));
323
+ try {
324
+ if (((f = 2), i)) {
325
+ if ((c || (o = 'next'), (t = i[o]))) {
326
+ if (!(t = t.call(i, u)))
327
+ throw TypeError('iterator result is not an object');
328
+ if (!t.done) return t;
329
+ ((u = t.value), c < 2 && (c = 0));
330
+ } else
331
+ (1 === c && (t = i.return) && t.call(i),
332
+ c < 2 &&
333
+ ((u = TypeError(
334
+ "The iterator does not provide a '" + o + "' method"
335
+ )),
336
+ (c = 1)));
337
+ i = e;
338
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
339
+ } catch (t) {
340
+ ((i = e), (c = 1), (u = t));
341
+ } finally {
342
+ f = 1;
343
+ }
344
+ }
345
+ return {
346
+ value: t,
347
+ done: y,
348
+ };
349
+ };
350
+ })(r, o, i),
351
+ true
352
+ ),
353
+ u
354
+ );
355
+ }
356
+ var a = {};
357
+ function Generator() {}
358
+ function GeneratorFunction() {}
359
+ function GeneratorFunctionPrototype() {}
360
+ t = Object.getPrototypeOf;
361
+ var c = [][n]
362
+ ? t(t([][n]()))
363
+ : (_regeneratorDefine((t = {}), n, function () {
364
+ return this;
365
+ }),
366
+ t),
367
+ u =
368
+ (GeneratorFunctionPrototype.prototype =
369
+ Generator.prototype =
370
+ Object.create(c));
371
+ function f(e) {
372
+ return (
373
+ Object.setPrototypeOf
374
+ ? Object.setPrototypeOf(e, GeneratorFunctionPrototype)
375
+ : ((e.__proto__ = GeneratorFunctionPrototype),
376
+ _regeneratorDefine(e, o, 'GeneratorFunction')),
377
+ (e.prototype = Object.create(u)),
378
+ e
379
+ );
380
+ }
381
+ return (
382
+ (GeneratorFunction.prototype = GeneratorFunctionPrototype),
383
+ _regeneratorDefine(u, 'constructor', GeneratorFunctionPrototype),
384
+ _regeneratorDefine(
385
+ GeneratorFunctionPrototype,
386
+ 'constructor',
387
+ GeneratorFunction
388
+ ),
389
+ (GeneratorFunction.displayName = 'GeneratorFunction'),
390
+ _regeneratorDefine(GeneratorFunctionPrototype, o, 'GeneratorFunction'),
391
+ _regeneratorDefine(u),
392
+ _regeneratorDefine(u, o, 'Generator'),
393
+ _regeneratorDefine(u, n, function () {
394
+ return this;
395
+ }),
396
+ _regeneratorDefine(u, 'toString', function () {
397
+ return '[object Generator]';
398
+ }),
399
+ (_regenerator = function () {
400
+ return {
401
+ w: i,
402
+ m: f,
403
+ };
404
+ })()
405
+ );
406
+ }
407
+ function _regeneratorDefine(e, r, n, t) {
408
+ var i = Object.defineProperty;
409
+ try {
410
+ i({}, '', {});
411
+ } catch (e) {
412
+ i = 0;
413
+ }
414
+ ((_regeneratorDefine = function (e, r, n, t) {
415
+ function o(r, n) {
416
+ _regeneratorDefine(e, r, function (e) {
417
+ return this._invoke(r, n, e);
418
+ });
419
+ }
420
+ r
421
+ ? i
422
+ ? i(e, r, {
423
+ value: n,
424
+ enumerable: !t,
425
+ configurable: !t,
426
+ writable: !t,
427
+ })
428
+ : (e[r] = n)
429
+ : (o('next', 0), o('throw', 1), o('return', 2));
430
+ }),
431
+ _regeneratorDefine(e, r, n, t));
432
+ }
433
+ function _setPrototypeOf(t, e) {
434
+ return (
435
+ (_setPrototypeOf = Object.setPrototypeOf
436
+ ? Object.setPrototypeOf.bind()
437
+ : function (t, e) {
438
+ return ((t.__proto__ = e), t);
439
+ }),
440
+ _setPrototypeOf(t, e)
441
+ );
442
+ }
443
+ function _slicedToArray(r, e) {
444
+ return (
445
+ _arrayWithHoles(r) ||
446
+ _iterableToArrayLimit(r, e) ||
447
+ _unsupportedIterableToArray(r, e) ||
448
+ _nonIterableRest()
449
+ );
450
+ }
451
+ function _toConsumableArray(r) {
452
+ return (
453
+ _arrayWithoutHoles(r) ||
454
+ _iterableToArray(r) ||
455
+ _unsupportedIterableToArray(r) ||
456
+ _nonIterableSpread()
457
+ );
458
+ }
459
+ function _toPrimitive(t, r) {
460
+ if ('object' != typeof t || !t) return t;
461
+ var e = t[Symbol.toPrimitive];
462
+ if (void 0 !== e) {
463
+ var i = e.call(t, r);
464
+ if ('object' != typeof i) return i;
465
+ throw new TypeError('@@toPrimitive must return a primitive value.');
466
+ }
467
+ return ('string' === r ? String : Number)(t);
468
+ }
469
+ function _toPropertyKey(t) {
470
+ var i = _toPrimitive(t, 'string');
471
+ return 'symbol' == typeof i ? i : i + '';
472
+ }
473
+ function _unsupportedIterableToArray(r, a) {
474
+ if (r) {
475
+ if ('string' == typeof r) return _arrayLikeToArray(r, a);
476
+ var t = {}.toString.call(r).slice(8, -1);
477
+ return (
478
+ 'Object' === t && r.constructor && (t = r.constructor.name),
479
+ 'Map' === t || 'Set' === t
480
+ ? Array.from(r)
481
+ : 'Arguments' === t ||
482
+ /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)
483
+ ? _arrayLikeToArray(r, a)
484
+ : void 0
485
+ );
486
+ }
487
+ }
488
+
489
+ var mergeRollupOptions = function mergeRollupOptions(first, second) {
490
+ if (!first) return second;
491
+ if (!second) return first;
492
+ return _objectSpread2(_objectSpread2({}, first), second);
493
+ };
494
+
495
+ var Compiler = /*#__PURE__*/ (function (_CompilerBase) {
496
+ function Compiler() {
497
+ var _this;
498
+ _classCallCheck(this, Compiler);
499
+ for (
500
+ var _len = arguments.length, args = new Array(_len), _key = 0;
501
+ _key < _len;
502
+ _key++
503
+ ) {
504
+ args[_key] = arguments[_key];
505
+ }
506
+ _this = _callSuper(this, Compiler, [].concat(args));
507
+ _defineProperty(
508
+ _this,
509
+ 'context',
510
+ /*#__PURE__*/ (function () {
511
+ var _ref = _asyncToGenerator(
512
+ /*#__PURE__*/ _regenerator().m(function _callee3(options) {
513
+ var rollupBuild, outputList;
514
+ return _regenerator().w(function (_context3) {
515
+ while (1)
516
+ switch (_context3.n) {
517
+ case 0:
518
+ _context3.n = 1;
519
+ return rollup.rollup(
520
+ mergeRollupOptions(_this.initOptions, options)
521
+ );
522
+ case 1:
523
+ rollupBuild = _context3.v;
524
+ outputList = [];
525
+ if (options.output) {
526
+ outputList = lang.isArray(options.output)
527
+ ? options.output
528
+ : [options.output];
529
+ }
530
+ return _context3.a(
531
+ 2,
532
+ Promise.resolve({
533
+ rebuild: (function () {
534
+ var _rebuild = _asyncToGenerator(
535
+ /*#__PURE__*/ _regenerator().m(function _callee() {
536
+ var outputOptions, i, output, writeRes;
537
+ return _regenerator().w(function (_context) {
538
+ while (1)
539
+ switch (_context.n) {
540
+ case 0:
541
+ outputOptions = [];
542
+ i = 0;
543
+ case 1:
544
+ if (!(i < outputList.length)) {
545
+ _context.n = 4;
546
+ break;
547
+ }
548
+ output = outputList[i];
549
+ _context.n = 2;
550
+ return rollupBuild.write(output);
551
+ case 2:
552
+ writeRes = _context.v;
553
+ outputOptions.push(writeRes);
554
+ case 3:
555
+ i++;
556
+ _context.n = 1;
557
+ break;
558
+ case 4:
559
+ return _context.a(
560
+ 2,
561
+ Promise.resolve({
562
+ rollupBuild: rollupBuild,
563
+ outputOptions: outputOptions,
564
+ })
565
+ );
566
+ }
567
+ }, _callee);
568
+ })
569
+ );
570
+ function rebuild() {
571
+ return _rebuild.apply(this, arguments);
572
+ }
573
+ return rebuild;
574
+ })(),
575
+ cancel: (function () {
576
+ var _cancel = _asyncToGenerator(
577
+ /*#__PURE__*/ _regenerator().m(function _callee2() {
578
+ return _regenerator().w(function (_context2) {
579
+ while (1)
580
+ switch (_context2.n) {
581
+ case 0:
582
+ helper.cLog.warn(
583
+ 'build',
584
+ 'empty',
585
+ 'Rollup does not need to be canceled.'
586
+ );
587
+ case 1:
588
+ return _context2.a(2);
589
+ }
590
+ }, _callee2);
591
+ })
592
+ );
593
+ function cancel() {
594
+ return _cancel.apply(this, arguments);
595
+ }
596
+ return cancel;
597
+ })(),
598
+ })
599
+ );
600
+ }
601
+ }, _callee3);
602
+ })
603
+ );
604
+ return function (_x) {
605
+ return _ref.apply(this, arguments);
606
+ };
607
+ })()
608
+ );
609
+ _defineProperty(
610
+ _this,
611
+ 'inOutMap',
612
+ /*#__PURE__*/ (function () {
613
+ var _ref2 = _asyncToGenerator(
614
+ /*#__PURE__*/ _regenerator().m(function _callee4(inputOutputMap) {
615
+ var input;
616
+ return _regenerator().w(function (_context4) {
617
+ while (1)
618
+ switch (_context4.n) {
619
+ case 0:
620
+ input = {};
621
+ Object.entries(inputOutputMap).forEach(function (_ref3) {
622
+ var _ref4 = _slicedToArray(_ref3, 2),
623
+ input = _ref4[0],
624
+ output = _ref4[1];
625
+ input[output] = input;
626
+ });
627
+ return _context4.a(
628
+ 2,
629
+ _this.build({
630
+ input: input,
631
+ })
632
+ );
633
+ }
634
+ }, _callee4);
635
+ })
636
+ );
637
+ return function (_x2) {
638
+ return _ref2.apply(this, arguments);
639
+ };
640
+ })()
641
+ );
642
+ _defineProperty(
643
+ _this,
644
+ 'input',
645
+ /*#__PURE__*/ (function () {
646
+ var _ref5 = _asyncToGenerator(
647
+ /*#__PURE__*/ _regenerator().m(function _callee6(input) {
648
+ var rollupBuild;
649
+ return _regenerator().w(function (_context6) {
650
+ while (1)
651
+ switch (_context6.n) {
652
+ case 0:
653
+ _context6.n = 1;
654
+ return rollup.rollup(
655
+ mergeRollupOptions(_this.initOptions, {
656
+ input: input || _this.initOptions.input,
657
+ })
658
+ );
659
+ case 1:
660
+ rollupBuild = _context6.v;
661
+ return _context6.a(2, {
662
+ output: (function () {
663
+ var _output2 = _asyncToGenerator(
664
+ /*#__PURE__*/ _regenerator().m(
665
+ function _callee5(_output) {
666
+ var writeRes;
667
+ return _regenerator().w(function (_context5) {
668
+ while (1)
669
+ switch (_context5.n) {
670
+ case 0:
671
+ _context5.n = 1;
672
+ return rollupBuild.write(_output);
673
+ case 1:
674
+ writeRes = _context5.v;
675
+ return _context5.a(2, {
676
+ rollupBuild: rollupBuild,
677
+ outputOption: writeRes,
678
+ });
679
+ }
680
+ }, _callee5);
681
+ }
682
+ )
683
+ );
684
+ function output(_x4) {
685
+ return _output2.apply(this, arguments);
686
+ }
687
+ return output;
688
+ })(),
689
+ });
690
+ }
691
+ }, _callee6);
692
+ })
693
+ );
694
+ return function (_x3) {
695
+ return _ref5.apply(this, arguments);
696
+ };
697
+ })()
698
+ );
699
+ _defineProperty(
700
+ _this,
701
+ 'build',
702
+ /*#__PURE__*/ (function () {
703
+ var _ref6 = _asyncToGenerator(
704
+ /*#__PURE__*/ _regenerator().m(function _callee7(options) {
705
+ var rollupBuild, outputList, outputOptions, i, output, writeRes;
706
+ return _regenerator().w(function (_context7) {
707
+ while (1)
708
+ switch (_context7.n) {
709
+ case 0:
710
+ _context7.n = 1;
711
+ return rollup.rollup(
712
+ mergeRollupOptions(_this.initOptions, options)
713
+ );
714
+ case 1:
715
+ rollupBuild = _context7.v;
716
+ outputList = [];
717
+ if (options.output) {
718
+ outputList = lang.isArray(options.output)
719
+ ? options.output
720
+ : [options.output];
721
+ }
722
+ outputOptions = [];
723
+ i = 0;
724
+ case 2:
725
+ if (!(i < outputList.length)) {
726
+ _context7.n = 5;
727
+ break;
728
+ }
729
+ output = outputList[i];
730
+ _context7.n = 3;
731
+ return rollupBuild.write(output);
732
+ case 3:
733
+ writeRes = _context7.v;
734
+ outputOptions.push(writeRes);
735
+ case 4:
736
+ i++;
737
+ _context7.n = 2;
738
+ break;
739
+ case 5:
740
+ return _context7.a(2, {
741
+ rollupBuild: rollupBuild,
742
+ outputOptions: outputOptions,
743
+ });
744
+ }
745
+ }, _callee7);
746
+ })
747
+ );
748
+ return function (_x5) {
749
+ return _ref6.apply(this, arguments);
750
+ };
751
+ })()
752
+ );
753
+ _defineProperty(_this, 'watch', function (options) {
754
+ var watchOptions = mergeRollupOptions(_this.initOptions, options);
755
+ return rollup.watch(watchOptions);
756
+ });
757
+ _defineProperty(
758
+ _this,
759
+ 'server',
760
+ /*#__PURE__*/ _asyncToGenerator(
761
+ /*#__PURE__*/ _regenerator().m(function _callee8() {
762
+ return _regenerator().w(function (_context8) {
763
+ while (1)
764
+ switch (_context8.n) {
765
+ case 0:
766
+ helper.cLog.warn(
767
+ 'serve',
768
+ 'empty',
769
+ 'Rollup does not support serve functionality.'
770
+ );
771
+ return _context8.a(2);
772
+ }
773
+ }, _callee8);
774
+ })
775
+ )
776
+ );
777
+ return _this;
778
+ }
779
+ _inherits(Compiler, _CompilerBase);
780
+ return _createClass(Compiler);
781
+ })(helper.CompilerBase);
782
+
783
+ /**
784
+ * 获取external配置
785
+ * @param envParams 环境参数
786
+ * @param options 用户配置的external选项
787
+ * @returns TExternalOption
788
+ */
789
+ var getExternal = function getExternal(_envParams, options) {
790
+ var _ref = options || {},
791
+ dependencies = _ref.dependencies,
792
+ devDependencies = _ref.devDependencies,
793
+ peerDependencies = _ref.peerDependencies,
794
+ externals = _ref.externals,
795
+ internals = _ref.internals,
796
+ filter = _ref.filter;
797
+ if (filter) return filter;
798
+
799
+ // 需要打包的模块
800
+ var internalsMap = lang.isArray(internals)
801
+ ? internals.reduce(function (prev, cur) {
802
+ prev[cur] = cur;
803
+ return prev;
804
+ }, {})
805
+ : internals || {};
806
+
807
+ // 不需要打包的模块
808
+ var extraExternals = lang.isArray(externals)
809
+ ? externals
810
+ : Object.keys(externals || {});
811
+ var obj = _objectSpread2(
812
+ _objectSpread2(_objectSpread2({}, dependencies), peerDependencies),
813
+ devDependencies
814
+ );
815
+ var externalList = Object.keys(obj)
816
+ .concat(extraExternals)
817
+ .filter(function (key) {
818
+ return !internalsMap[key];
819
+ });
820
+ return function (source, _importer, _isResolved) {
821
+ if (/^@doracli\//.test(source)) return true;
822
+ var isExternal = externalList.find(function (externalModule) {
823
+ return source.startsWith(externalModule);
824
+ });
825
+ return !!isExternal;
826
+ };
827
+ };
828
+
829
+ /**
830
+ * 获取入口文件
831
+ * @description input 不传,则自动寻找
832
+ * @param envParams 环境参数
833
+ * @param input 入口文件路径
834
+ * @returnscj
835
+ */
836
+ var getInput = /*#__PURE__*/ (function () {
837
+ var _ref = _asyncToGenerator(
838
+ /*#__PURE__*/ _regenerator().m(function _callee(envParams, input) {
839
+ var workRootDir, rightFile;
840
+ return _regenerator().w(function (_context) {
841
+ while (1)
842
+ switch (_context.n) {
843
+ case 0:
844
+ workRootDir = envParams.workRootDir;
845
+ rightFile = input;
846
+ if (!lang.isString(input)) {
847
+ _context.n = 2;
848
+ break;
849
+ }
850
+ _context.n = 1;
851
+ return filePro.isValidDir(input);
852
+ case 1:
853
+ if (_context.v) {
854
+ _context.n = 2;
855
+ break;
856
+ }
857
+ helper.cLog.warn(
858
+ 'rollup',
859
+ 'input',
860
+ '\u65E0\u6709\u6548\u5165\u53E3\u8DEF\u5F84 '.concat(
861
+ input,
862
+ '\uFF0C\u5C06\u81EA\u52A8\u5BFB\u627E\u6709\u6548\u8DEF\u5F84'
863
+ )
864
+ );
865
+ rightFile = undefined;
866
+ case 2:
867
+ if (!rightFile) {
868
+ rightFile = helper.findInput(workRootDir);
869
+ }
870
+ if (!rightFile) {
871
+ helper.cLog.error(
872
+ 'common',
873
+ 'find_input',
874
+ '需要有一个入口文件 index 或者 src/index'
875
+ );
876
+ process.exit();
877
+ }
878
+ helper.cLog.log(
879
+ 'rollup',
880
+ 'input',
881
+ '\u5165\u53E3\u6587\u4EF6\u8DEF\u5F84 '.concat(rightFile)
882
+ );
883
+ return _context.a(2, rightFile);
884
+ }
885
+ }, _callee);
886
+ })
887
+ );
888
+ return function getInput(_x, _x2) {
889
+ return _ref.apply(this, arguments);
890
+ };
891
+ })();
892
+
893
+ var _excluded$4 = ['format'];
894
+ /**
895
+ * 生成单个output
896
+ * @description 如果不配置output,则默认生成cjs格式的output,输出路径为`lib/index.js`
897
+ * @description 自动组合完整的file
898
+ * @param optionsOutput
899
+ * @returns
900
+ */
901
+ var getOutput = function getOutput(envParams, options) {
902
+ var workRootDir = envParams.workRootDir;
903
+ if (!options) {
904
+ return {
905
+ file: path.join(workRootDir, 'lib/index.js'),
906
+ format: 'esm',
907
+ sourcemap: false,
908
+ };
909
+ }
910
+ var format = options.format,
911
+ outputOptions = _objectWithoutProperties(options, _excluded$4);
912
+ var realFormat = format || 'esm';
913
+ return _objectSpread2(
914
+ {
915
+ format: realFormat,
916
+ sourcemap: false,
917
+ },
918
+ outputOptions
919
+ );
920
+ };
921
+
922
+ var _excluded$3 = ['entries'];
923
+
924
+ /**
925
+ * 获取别名插件
926
+ * @param config 快捷配置
927
+ * @param pluginConfig 标准配置
928
+ * @returns 别名插件
929
+ */
930
+ var getAliasPlugin = function getAliasPlugin(config, pluginConfig) {
931
+ var userConfig = config.alias,
932
+ tsConfigPath = config.tsConfigPath;
933
+ var aliasObj = helper.getTsPathAlias(tsConfigPath || []);
934
+ var _ref = pluginConfig || {},
935
+ entries = _ref.entries,
936
+ extPluginConfig = _objectWithoutProperties(_ref, _excluded$3);
937
+ return alias(
938
+ _objectSpread2(
939
+ _objectSpread2({}, extPluginConfig),
940
+ {},
941
+ {
942
+ entries: _objectSpread2(
943
+ _objectSpread2(_objectSpread2({}, entries), userConfig),
944
+ aliasObj
945
+ ),
946
+ }
947
+ )
948
+ );
949
+ };
950
+
951
+ /**
952
+ * 获取Babel插件
953
+ * @param _config 快捷配置
954
+ * @param pluginConfig 标准配置
955
+ * @returns Babel插件
956
+ */
957
+ var getBabelPlugin = function getBabelPlugin(_config, pluginConfig) {
958
+ return babel(
959
+ _objectSpread2(
960
+ {
961
+ babelrc: false,
962
+ configFile: false,
963
+ compact: false,
964
+ cwd: filePro.getNodeModulesDir(
965
+ filePro.getDirname({
966
+ url:
967
+ typeof document === 'undefined'
968
+ ? require('u' + 'rl').pathToFileURL(__filename).href
969
+ : (_documentCurrentScript &&
970
+ _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' &&
971
+ _documentCurrentScript.src) ||
972
+ new URL('index.js', document.baseURI).href,
973
+ })
974
+ ),
975
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs'],
976
+ ignore: ['node_modules/**'],
977
+ babelHelpers: 'bundled',
978
+ exclude: 'node_modules/**',
979
+ },
980
+ pluginConfig
981
+ )
982
+ );
983
+ };
984
+
985
+ /**
986
+ * 获取CommonJS插件
987
+ * @description 将 CommonJS 转换成 ES2015 模块供 Rollup 处理
988
+ * @param _config
989
+ * @param pluginConfig
990
+ * @returns
991
+ */
992
+ var getCommonjsPlugin = function getCommonjsPlugin(_config, pluginConfig) {
993
+ return commonjs(pluginConfig);
994
+ };
995
+
996
+ var _excluded$2 = ['targets'];
997
+ /**
998
+ * 获取拷贝插件
999
+ * @param config 快捷配置
1000
+ * @param pluginConfig 标准配置
1001
+ * @returns 拷贝插件
1002
+ */
1003
+ var getCopyPlugin = function getCopyPlugin(config, pluginConfig) {
1004
+ var _ref = config || {},
1005
+ copyList = _ref.copyList;
1006
+ var _ref2 = pluginConfig || {},
1007
+ targets = _ref2.targets,
1008
+ extPluginConfig = _objectWithoutProperties(_ref2, _excluded$2);
1009
+ var resTargets = _toConsumableArray(targets || []);
1010
+ if (copyList) {
1011
+ resTargets.push.apply(resTargets, _toConsumableArray(copyList));
1012
+ }
1013
+ return copy(
1014
+ _objectSpread2(
1015
+ _objectSpread2({}, extPluginConfig),
1016
+ {},
1017
+ {
1018
+ targets: resTargets,
1019
+ }
1020
+ )
1021
+ );
1022
+ };
1023
+
1024
+ /**
1025
+ * 获取 dts 插件
1026
+ * @param _config
1027
+ * @param pluginConfig
1028
+ * @returns
1029
+ */
1030
+ var getDtsPlugin = function getDtsPlugin(_config, pluginConfig) {
1031
+ return rollupPluginDts.dts(
1032
+ _objectSpread2(
1033
+ {
1034
+ respectExternal: false,
1035
+ tsconfig: 'tsconfig.json',
1036
+ compilerOptions: {},
1037
+ },
1038
+ pluginConfig
1039
+ )
1040
+ );
1041
+ };
1042
+
1043
+ /**
1044
+ * 获取Json插件
1045
+ * @description 允许将 .json 文件作为 ES6 模块导入
1046
+ * @param _config
1047
+ * @param pluginConfig
1048
+ * @returns
1049
+ */
1050
+ var getJsonPlugin = function getJsonPlugin(_config, pluginConfig) {
1051
+ return json(pluginConfig);
1052
+ };
1053
+
1054
+ /**
1055
+ * 获取代码压缩插件
1056
+ * @returns Minimize插件
1057
+ */
1058
+ var getMinimizePlugin = function getMinimizePlugin() {
1059
+ return terser();
1060
+ };
1061
+
1062
+ var _excluded$1 = ['plugins'];
1063
+
1064
+ /**
1065
+ * 创建Postcss插件
1066
+ * @param config 快捷配置
1067
+ * @param pluginConfig 标准配置
1068
+ * @returns Postcss插件
1069
+ */
1070
+ var getPostcssPlugin = function getPostcssPlugin(config, pluginConfig) {
1071
+ var minimize = config.minimize,
1072
+ output = config.output;
1073
+ var _ref = pluginConfig || {},
1074
+ injectPlugin = _ref.plugins,
1075
+ otherConfig = _objectWithoutProperties(_ref, _excluded$1);
1076
+ var outputWhole = path.isAbsolute(output)
1077
+ ? output
1078
+ : path.resolve(process.cwd(), output);
1079
+ var plugins = [
1080
+ autoprefixer({
1081
+ overrideBrowserslist: [
1082
+ 'defaults',
1083
+ 'not ie < 8',
1084
+ 'last 2 versions',
1085
+ '> 1%',
1086
+ 'iOS 7',
1087
+ 'last 3 iOS versions',
1088
+ ],
1089
+ }),
1090
+ ].concat(_toConsumableArray(injectPlugin || []));
1091
+ if (minimize) {
1092
+ plugins.push(cssnanoPlugin());
1093
+ }
1094
+
1095
+ /**
1096
+ * 输出文件锁,防止多次写入
1097
+ * 当输出n个格式时,会被同时调用n次
1098
+ */
1099
+ var codeFileNameLock = '';
1100
+ return postcss(
1101
+ _objectSpread2(
1102
+ {
1103
+ plugins: plugins,
1104
+ extract: true,
1105
+ onExtract: (function () {
1106
+ var _ref2 = _asyncToGenerator(
1107
+ /*#__PURE__*/ _regenerator().m(function _callee(getExtracted) {
1108
+ var _ref3, code, codeFileName, dir;
1109
+ return _regenerator().w(function (_context) {
1110
+ while (1)
1111
+ switch (_context.n) {
1112
+ case 0:
1113
+ ((_ref3 = getExtracted()),
1114
+ (code = _ref3.code),
1115
+ (codeFileName = _ref3.codeFileName));
1116
+ if (!(codeFileNameLock === codeFileName)) {
1117
+ _context.n = 1;
1118
+ break;
1119
+ }
1120
+ return _context.a(2, false);
1121
+ case 1:
1122
+ codeFileNameLock = codeFileName;
1123
+ if (filePro.isValidFilePathSync(outputWhole)) {
1124
+ fs.rmSync(outputWhole, {
1125
+ recursive: true,
1126
+ force: true,
1127
+ });
1128
+ }
1129
+ dir = path.dirname(outputWhole);
1130
+ _context.n = 2;
1131
+ return filePro.mkdirRecursive(dir);
1132
+ case 2:
1133
+ _context.n = 3;
1134
+ return promises.writeFile(outputWhole, code);
1135
+ case 3:
1136
+ helper.cLog.info(
1137
+ 'style',
1138
+ 'success',
1139
+ '\u8F93\u51FA\u7C7B\u578B => css\uFF1B',
1140
+ '\u8DEF\u5F84 =>'.concat(
1141
+ path.relative(filePro.getCwd(), outputWhole)
1142
+ )
1143
+ );
1144
+ codeFileNameLock = '';
1145
+ return _context.a(2, false);
1146
+ }
1147
+ }, _callee);
1148
+ })
1149
+ );
1150
+ return function onExtract(_x) {
1151
+ return _ref2.apply(this, arguments);
1152
+ };
1153
+ })(),
1154
+ },
1155
+ otherConfig
1156
+ )
1157
+ );
1158
+ };
1159
+
1160
+ /**
1161
+ * 获取解析插件
1162
+ * @param config 快捷配置
1163
+ * @param pluginConfig 标准配置
1164
+ * @returns 解析插件
1165
+ */
1166
+ var getResolvePlugin = function getResolvePlugin(config, pluginConfig) {
1167
+ var extensions = config.extensions;
1168
+ return resolve(
1169
+ _objectSpread2(
1170
+ {
1171
+ extensions: extensions,
1172
+ preferBuiltins: true,
1173
+ },
1174
+ pluginConfig
1175
+ )
1176
+ );
1177
+ };
1178
+
1179
+ /**
1180
+ * 获取Node环境下的插件集合
1181
+ * @param config 快捷配置
1182
+ * @returns
1183
+ */
1184
+ var getNodePlugins = function getNodePlugins(config) {
1185
+ var alias = config.alias,
1186
+ minimize = config.minimize,
1187
+ copyList = config.copyList;
1188
+ var plugins = [
1189
+ getResolvePlugin(
1190
+ {
1191
+ extensions: ['.js', '.ts', '.json'],
1192
+ },
1193
+ {
1194
+ preferBuiltins: true,
1195
+ }
1196
+ ),
1197
+ getAliasPlugin({
1198
+ alias: _objectSpread2(
1199
+ {
1200
+ '@': 'src',
1201
+ },
1202
+ alias
1203
+ ),
1204
+ }),
1205
+ getCopyPlugin({
1206
+ copyList: copyList,
1207
+ }),
1208
+ getCommonjsPlugin(),
1209
+ getJsonPlugin(),
1210
+ ];
1211
+ plugins.push(getBabelPlugin({}, presetBabel.nodeBabelPreset()));
1212
+ if (minimize) {
1213
+ plugins.push(getMinimizePlugin());
1214
+ }
1215
+ return plugins;
1216
+ };
1217
+
1218
+ /**
1219
+ * 获取Node环境下的插件集合
1220
+ * @param config 快捷配置
1221
+ * @returns
1222
+ */
1223
+ var getReactPlugins = /*#__PURE__*/ (function () {
1224
+ var _ref = _asyncToGenerator(
1225
+ /*#__PURE__*/ _regenerator().m(function _callee(config) {
1226
+ var alias,
1227
+ minimize,
1228
+ cssOutput,
1229
+ copy,
1230
+ plugins,
1231
+ _t,
1232
+ _t2,
1233
+ _t3,
1234
+ _t4,
1235
+ _t5,
1236
+ _t6;
1237
+ return _regenerator().w(function (_context) {
1238
+ while (1)
1239
+ switch (_context.n) {
1240
+ case 0:
1241
+ ((alias = config.alias),
1242
+ (minimize = config.minimize),
1243
+ (cssOutput = config.cssOutput),
1244
+ (copy = config.copy));
1245
+ _context.n = 1;
1246
+ return getPostcssPlugin({
1247
+ minimize: !!minimize,
1248
+ output: cssOutput || 'lib/css/index.css',
1249
+ });
1250
+ case 1:
1251
+ _t = _context.v;
1252
+ _t2 = getResolvePlugin(
1253
+ {
1254
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs'],
1255
+ },
1256
+ {
1257
+ preferBuiltins: true,
1258
+ }
1259
+ );
1260
+ _t3 = getAliasPlugin({
1261
+ alias: _objectSpread2(
1262
+ {
1263
+ '@': 'src',
1264
+ },
1265
+ alias
1266
+ ),
1267
+ });
1268
+ _t4 = getCopyPlugin({
1269
+ copyList: copy,
1270
+ });
1271
+ _t5 = getCommonjsPlugin();
1272
+ _t6 = getJsonPlugin();
1273
+ plugins = [_t, _t2, _t3, _t4, _t5, _t6];
1274
+ plugins.push(getBabelPlugin({}, presetBabel.reactBabelPreset()));
1275
+ if (minimize) {
1276
+ plugins.push(getMinimizePlugin());
1277
+ }
1278
+ return _context.a(2, plugins);
1279
+ }
1280
+ }, _callee);
1281
+ })
1282
+ );
1283
+ return function getReactPlugins(_x) {
1284
+ return _ref.apply(this, arguments);
1285
+ };
1286
+ })();
1287
+
1288
+ /**
1289
+ * 获取watch配置
1290
+ * @param options
1291
+ * @returns
1292
+ */
1293
+ var getWatch = function getWatch(envParams, options) {
1294
+ var workRootDir = envParams.workRootDir;
1295
+ return _objectSpread2(
1296
+ {
1297
+ exclude: 'node_modules/**',
1298
+ include: path.join(workRootDir, 'src/**'),
1299
+ clearScreen: false,
1300
+ skipWrite: false,
1301
+ buildDelay: 500,
1302
+ chokidar: {
1303
+ usePolling: true,
1304
+ },
1305
+ },
1306
+ options
1307
+ );
1308
+ };
1309
+
1310
+ var envParamsMw = function envParamsMw(envParams) {
1311
+ return function (ctx) {
1312
+ return function (next) {
1313
+ return /*#__PURE__*/ _asyncToGenerator(
1314
+ /*#__PURE__*/ _regenerator().m(function _callee() {
1315
+ return _regenerator().w(function (_context) {
1316
+ while (1)
1317
+ switch (_context.n) {
1318
+ case 0:
1319
+ ctx.updateEnvParams(envParams);
1320
+ return _context.a(2, next());
1321
+ }
1322
+ }, _callee);
1323
+ })
1324
+ );
1325
+ };
1326
+ };
1327
+ };
1328
+
1329
+ var rollupExternalMw = function rollupExternalMw() {
1330
+ return function (ctx) {
1331
+ return function (next) {
1332
+ return /*#__PURE__*/ _asyncToGenerator(
1333
+ /*#__PURE__*/ _regenerator().m(function _callee() {
1334
+ var _ref2,
1335
+ dependencies,
1336
+ devDependencies,
1337
+ peerDependencies,
1338
+ _ref3,
1339
+ externals,
1340
+ internals,
1341
+ dependFilter;
1342
+ return _regenerator().w(function (_context) {
1343
+ while (1)
1344
+ switch (_context.n) {
1345
+ case 0:
1346
+ ((_ref2 = ctx.configCtx.getPackageConfig() || {}),
1347
+ (dependencies = _ref2.dependencies),
1348
+ (devDependencies = _ref2.devDependencies),
1349
+ (peerDependencies = _ref2.peerDependencies));
1350
+ ((_ref3 = ctx.configCtx.getDoraConfig() || {}),
1351
+ (externals = _ref3.externals),
1352
+ (internals = _ref3.internals));
1353
+ dependFilter = helper.createDependFilter({
1354
+ dependencies: dependencies,
1355
+ devDependencies: devDependencies,
1356
+ peerDependencies: peerDependencies,
1357
+ externals: externals,
1358
+ internals: internals,
1359
+ });
1360
+ ctx.updateRollupOptions({
1361
+ external: function external(moduleId) {
1362
+ if (/^@doracli\//.test(moduleId)) return true;
1363
+ return dependFilter(moduleId);
1364
+ },
1365
+ });
1366
+ return _context.a(2, next());
1367
+ }
1368
+ }, _callee);
1369
+ })
1370
+ );
1371
+ };
1372
+ };
1373
+ };
1374
+ var rollupDtsExternalMw = function rollupDtsExternalMw() {
1375
+ return function (ctx) {
1376
+ return function (next) {
1377
+ return /*#__PURE__*/ _asyncToGenerator(
1378
+ /*#__PURE__*/ _regenerator().m(function _callee2() {
1379
+ var external;
1380
+ return _regenerator().w(function (_context2) {
1381
+ while (1)
1382
+ switch (_context2.n) {
1383
+ case 0:
1384
+ external = function external(id) {
1385
+ if (
1386
+ /\.(css|less|scss|sass|styl|png|jpe?g|svg|gif|webp|ico)$/.test(
1387
+ id
1388
+ )
1389
+ ) {
1390
+ return true;
1391
+ }
1392
+ return false;
1393
+ };
1394
+ ctx.updateRollupOptions({
1395
+ external: external,
1396
+ });
1397
+ return _context2.a(2, next());
1398
+ }
1399
+ }, _callee2);
1400
+ })
1401
+ );
1402
+ };
1403
+ };
1404
+ };
1405
+
1406
+ var _excluded = ['file', 'dir', 'format'];
1407
+ /**
1408
+ * 获取运行时输出配置
1409
+ * @param output
1410
+ * @param isMultiple
1411
+ * @param workRootDir
1412
+ * @returns
1413
+ */
1414
+ var getOutputRuntime = function getOutputRuntime(
1415
+ output,
1416
+ isMultiple,
1417
+ workRootDir
1418
+ ) {
1419
+ var file = output.file,
1420
+ dir = output.dir,
1421
+ format = output.format,
1422
+ extOutput = _objectWithoutProperties(output, _excluded);
1423
+ var fileWhole = isMultiple
1424
+ ? path.join(workRootDir, dir, format, file)
1425
+ : path.join(workRootDir, dir, file);
1426
+ return _objectSpread2(
1427
+ {
1428
+ file: fileWhole,
1429
+ format: format,
1430
+ },
1431
+ extOutput
1432
+ );
1433
+ };
1434
+
1435
+ /**
1436
+ * 从rollup配置中,获取第一个input
1437
+ * @param inputOrigin
1438
+ * @returns
1439
+ */
1440
+ var getFirstInput = function getFirstInput(inputOrigin) {
1441
+ if (typeof inputOrigin === 'string') {
1442
+ var name = filePro.getFilename(inputOrigin);
1443
+ return {
1444
+ path: inputOrigin,
1445
+ name: name,
1446
+ };
1447
+ } else if (Array.isArray(inputOrigin) && inputOrigin.length > 0) {
1448
+ var firstInput = inputOrigin[0];
1449
+ var _name = filePro.getFilename(firstInput);
1450
+ return {
1451
+ path: firstInput,
1452
+ name: _name,
1453
+ };
1454
+ } else if (lang.isObject(inputOrigin)) {
1455
+ var firstKey = Object.keys(inputOrigin)[0];
1456
+ var _firstInput = inputOrigin[firstKey];
1457
+ return {
1458
+ path: _firstInput,
1459
+ name: firstKey,
1460
+ };
1461
+ }
1462
+ return undefined;
1463
+ };
1464
+
1465
+ var rollupWatchLog = function rollupWatchLog(watcher) {
1466
+ // event.code 可以是以下之一:
1467
+ // START - 监视器正在(重新)启动
1468
+ // BUNDLE_START - 单次打包
1469
+ // * 如果存在,event.input 将是输入选项对象
1470
+ // * event.output 包含生成的输出的 "file"
1471
+ // 或 "dir" 选项值的数组
1472
+ // BUNDLE_END - 完成打包
1473
+ // * 如果存在,event.input 将是输入选项对象
1474
+ // * event.output 包含生成的输出的 "file"
1475
+ // 或 "dir" 选项值的数组
1476
+ // * event.duration 是构建持续时间(以毫秒为单位)
1477
+ // * event.result 包含 bundle 对象,
1478
+ // 可以通过调用 bundle.generate
1479
+ // 或 bundle.write 来生成其他输出。
1480
+ // 当使用 watch.skipWrite 选项时,这尤其重要。
1481
+ // 生成输出后,你应该调用 "event.result.close()",
1482
+ // 或者如果你不生成输出,也应该调用。
1483
+ // 这将允许插件通过
1484
+ // "closeBundle" 钩子清理资源。
1485
+ // END - 完成所有产物的构建
1486
+ // ERROR - 在打包时遇到错误
1487
+ // * event.error 包含抛出的错误
1488
+ // * 对于构建错误,event.result 为 null,
1489
+ // 对于输出生成错误,它包含 bundle 对象。
1490
+ // 与 "BUNDLE_END" 一样,如果存在,
1491
+ // 你应该在完成后调用 "event.result.close()"。
1492
+ // 如果从事件处理程序返回一个 Promise,则 Rollup
1493
+ // 将等待 Promise 解析后再继续。
1494
+
1495
+ watcher.on('event', function (event) {
1496
+ var _event$result;
1497
+ switch (event.code) {
1498
+ case 'BUNDLE_END':
1499
+ // 这将确保在每次运行后正确关闭打包
1500
+ helper.cLog.info(
1501
+ 'serve',
1502
+ event.code,
1503
+ '\u5355\u6B21\u6253\u5305\u5B8C\u6210'
1504
+ );
1505
+ event.result.close();
1506
+ break;
1507
+ case 'ERROR':
1508
+ helper.cLog.error(
1509
+ 'serve',
1510
+ event.code,
1511
+ '\u5355\u6B21\u6253\u5305\u6355\u83B7\u5230\u9519\u8BEF'
1512
+ );
1513
+ handleError(event.error, true);
1514
+ (_event$result = event.result) === null ||
1515
+ _event$result === void 0 ||
1516
+ _event$result.close();
1517
+ break;
1518
+ case 'BUNDLE_START':
1519
+ helper.cLog.log(
1520
+ 'serve',
1521
+ event.code,
1522
+ '\u5355\u6B21\u6253\u5305\u4E2D....'
1523
+ );
1524
+ break;
1525
+ case 'END':
1526
+ helper.cLog.info(
1527
+ 'serve',
1528
+ event.code,
1529
+ '\u5B8C\u6210\u5355\u6B21\u6784\u5EFA'
1530
+ );
1531
+ break;
1532
+ case 'START':
1533
+ helper.cLog.log(
1534
+ 'serve',
1535
+ event.code,
1536
+ '\u76D1\u89C6\u5668\u6B63\u5728\uFF08\u91CD\u65B0\uFF09\u542F\u52A8'
1537
+ );
1538
+ break;
1539
+ }
1540
+ });
1541
+
1542
+ // 此外,你可以挂钩以下内容。
1543
+ // 同样,返回 Promise 以使 Rollup 在该阶段等待:
1544
+ watcher.on('change', function (id, _ref) {
1545
+ var event = _ref.event;
1546
+ /* 更改了一个文件 */
1547
+ helper.cLog.log(
1548
+ 'serve',
1549
+ event.toUpperCase(),
1550
+ ''
1551
+ .concat('检测到文件变动'.padEnd(12, ' '), ' ')
1552
+ .concat(helper.picocolors.cyan(path.relative(filePro.getCwd(), id)))
1553
+ );
1554
+ });
1555
+ watcher.on('restart', function () {
1556
+ /* 新触发了一次运行 */
1557
+ helper.cLog.log('serve', 'restart'.toUpperCase(), '新触发了一次运行');
1558
+ });
1559
+ watcher.on('close', function () {
1560
+ /* 监视器被关闭了,请看下面的代码 */
1561
+ });
1562
+ };
1563
+ var _picocolors$createCol = helper.picocolors.createColors(),
1564
+ bold = _picocolors$createCol.bold,
1565
+ cyan = _picocolors$createCol.cyan,
1566
+ dim = _picocolors$createCol.dim,
1567
+ red = _picocolors$createCol.red;
1568
+
1569
+ // log to stderr to keep `rollup main.js > bundle.js` from breaking
1570
+ var stderr = function stderr() {
1571
+ for (
1572
+ var _len = arguments.length, parameters = new Array(_len), _key = 0;
1573
+ _key < _len;
1574
+ _key++
1575
+ ) {
1576
+ parameters[_key] = arguments[_key];
1577
+ }
1578
+ return process.stderr.write(''.concat(parameters.join(''), '\n'));
1579
+ };
1580
+ function handleError(error) {
1581
+ var _error$cause;
1582
+ var recover =
1583
+ arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1584
+ var name =
1585
+ error.name ||
1586
+ ((_error$cause = error.cause) === null || _error$cause === void 0
1587
+ ? void 0
1588
+ : _error$cause.name);
1589
+ var nameSection = name ? ''.concat(name, ': ') : '';
1590
+ var pluginSection = error.plugin ? '(plugin '.concat(error.plugin, ') ') : '';
1591
+ var message = ''
1592
+ .concat(pluginSection)
1593
+ .concat(nameSection)
1594
+ .concat(error.message);
1595
+ var outputLines = [bold(red('[!] '.concat(bold(message.toString()))))];
1596
+ if (error.url) {
1597
+ outputLines.push(cyan(error.url));
1598
+ }
1599
+ if (error.loc) {
1600
+ outputLines.push(
1601
+ ' ('.concat(error.loc.line, ':').concat(error.loc.column, ')')
1602
+ );
1603
+ }
1604
+ if (error.frame) {
1605
+ outputLines.push(dim(error.frame));
1606
+ }
1607
+ if (error.stack) {
1608
+ var _error$stack;
1609
+ outputLines.push(
1610
+ dim(
1611
+ (_error$stack = error.stack) === null || _error$stack === void 0
1612
+ ? void 0
1613
+ : _error$stack.replace(
1614
+ ''.concat(nameSection).concat(error.message, '\n'),
1615
+ ''
1616
+ )
1617
+ )
1618
+ );
1619
+ }
1620
+ outputLines.push('', '');
1621
+ stderr(outputLines.join('\n'));
1622
+ if (!recover) process.exit(1);
1623
+ }
1624
+
1625
+ var rollupInputMw = function rollupInputMw() {
1626
+ return function (ctx) {
1627
+ return function (next) {
1628
+ return function () {
1629
+ var _ctx$getDoraConfig = ctx.getDoraConfig(),
1630
+ input = _ctx$getDoraConfig.input;
1631
+ var inputWhole = input;
1632
+ if (!inputWhole) {
1633
+ inputWhole = helper.findInput(ctx.envParams.workRootDir);
1634
+ if (!inputWhole) {
1635
+ helper.cLog.error(
1636
+ 'common',
1637
+ 'find_input',
1638
+ '需要有一个入口文件 index 或者 src/index'
1639
+ );
1640
+ process.exit();
1641
+ }
1642
+ }
1643
+ ctx.updateRollupOptions({
1644
+ input: inputWhole,
1645
+ });
1646
+ return next();
1647
+ };
1648
+ };
1649
+ };
1650
+ };
1651
+ var rollupOutputListMw = function rollupOutputListMw() {
1652
+ return function (ctx) {
1653
+ return function (next) {
1654
+ return function () {
1655
+ var _ctx$getDoraConfig2 = ctx.getDoraConfig(),
1656
+ input = _ctx$getDoraConfig2.input,
1657
+ output = _ctx$getDoraConfig2.output,
1658
+ formatList = _ctx$getDoraConfig2.formatList;
1659
+ var file = output.file,
1660
+ path = output.path;
1661
+ var outputFile = file;
1662
+ if (!outputFile) {
1663
+ var moduleName = filePro.getFilename(input);
1664
+ outputFile = ''.concat(moduleName, '.js');
1665
+ }
1666
+ var outputList = formatList.map(function (format) {
1667
+ return {
1668
+ dir: path,
1669
+ file: outputFile,
1670
+ format: format,
1671
+ };
1672
+ });
1673
+ ctx.updateRollupOutputList(outputList);
1674
+ return next();
1675
+ };
1676
+ };
1677
+ };
1678
+ };
1679
+ var rollupInoutMw = function rollupInoutMw() {
1680
+ return function (ctx) {
1681
+ return function (next) {
1682
+ return /*#__PURE__*/ _asyncToGenerator(
1683
+ /*#__PURE__*/ _regenerator().m(function _callee() {
1684
+ var _ctx$getDoraConfig3,
1685
+ input,
1686
+ output,
1687
+ formatList,
1688
+ file,
1689
+ path,
1690
+ inputWhole,
1691
+ outputFile,
1692
+ moduleName,
1693
+ outputList;
1694
+ return _regenerator().w(function (_context) {
1695
+ while (1)
1696
+ switch (_context.n) {
1697
+ case 0:
1698
+ ((_ctx$getDoraConfig3 = ctx.getDoraConfig()),
1699
+ (input = _ctx$getDoraConfig3.input),
1700
+ (output = _ctx$getDoraConfig3.output),
1701
+ (formatList = _ctx$getDoraConfig3.formatList));
1702
+ ((file = output.file), (path = output.path));
1703
+ inputWhole = input;
1704
+ outputFile = file;
1705
+ if (!inputWhole) {
1706
+ inputWhole = helper.findInput(ctx.envParams.workRootDir);
1707
+ if (!inputWhole) {
1708
+ helper.cLog.error(
1709
+ 'common',
1710
+ 'find_input',
1711
+ '需要有一个入口文件 index 或者 src/index'
1712
+ );
1713
+ process.exit();
1714
+ }
1715
+ }
1716
+ if (!outputFile) {
1717
+ moduleName = filePro.getFilename(inputWhole);
1718
+ outputFile = ''.concat(moduleName, '.js');
1719
+ }
1720
+ outputList = formatList.map(function (format) {
1721
+ return {
1722
+ dir: path,
1723
+ file: outputFile,
1724
+ format: format,
1725
+ };
1726
+ });
1727
+ ctx.updateRollupOptions({
1728
+ input: inputWhole,
1729
+ });
1730
+ ctx.updateRollupOutputList(outputList);
1731
+ return _context.a(2, next());
1732
+ }
1733
+ }, _callee);
1734
+ })
1735
+ );
1736
+ };
1737
+ };
1738
+ };
1739
+ var rollupWatchOutputMw = function rollupWatchOutputMw() {
1740
+ return function (ctx) {
1741
+ return function (next) {
1742
+ return /*#__PURE__*/ _asyncToGenerator(
1743
+ /*#__PURE__*/ _regenerator().m(function _callee2() {
1744
+ return _regenerator().w(function (_context2) {
1745
+ while (1)
1746
+ switch (_context2.n) {
1747
+ case 0:
1748
+ ctx.updateRollupOptions({
1749
+ output: ctx.rollupOutputList.map(function (output) {
1750
+ return getOutputRuntime(
1751
+ output,
1752
+ ctx.rollupOutputList.length > 1,
1753
+ ctx.envParams.workRootDir
1754
+ );
1755
+ }),
1756
+ });
1757
+ return _context2.a(2, next());
1758
+ }
1759
+ }, _callee2);
1760
+ })
1761
+ );
1762
+ };
1763
+ };
1764
+ };
1765
+ var rollupDtsInoutMw = function rollupDtsInoutMw() {
1766
+ return function (ctx) {
1767
+ return function (next) {
1768
+ return /*#__PURE__*/ _asyncToGenerator(
1769
+ /*#__PURE__*/ _regenerator().m(function _callee3() {
1770
+ var _ctx$getDoraConfig4, output, dts, dtsInput, dtsOutput;
1771
+ return _regenerator().w(function (_context3) {
1772
+ while (1)
1773
+ switch (_context3.n) {
1774
+ case 0:
1775
+ ((_ctx$getDoraConfig4 = ctx.getDoraConfig()),
1776
+ (output = _ctx$getDoraConfig4.output),
1777
+ (dts = _ctx$getDoraConfig4.dts));
1778
+ if (dts) {
1779
+ _context3.n = 1;
1780
+ break;
1781
+ }
1782
+ return _context3.a(2);
1783
+ case 1:
1784
+ dtsInput =
1785
+ (dts === null || dts === void 0 ? void 0 : dts.input) ||
1786
+ ctx.rollupOptions.input;
1787
+ dtsOutput =
1788
+ (dts === null || dts === void 0 ? void 0 : dts.output) ||
1789
+ path.resolve(output.path || './lib', 'type/index.d.ts');
1790
+ ctx.updateRollupOptions({
1791
+ input: dtsInput,
1792
+ });
1793
+ ctx.updateRollupOutputList([
1794
+ {
1795
+ file: dtsOutput,
1796
+ },
1797
+ ]);
1798
+ return _context3.a(2, next());
1799
+ }
1800
+ }, _callee3);
1801
+ })
1802
+ );
1803
+ };
1804
+ };
1805
+ };
1806
+
1807
+ var insertTsMw = function insertTsMw() {
1808
+ return function (ctx) {
1809
+ return function (next) {
1810
+ return /*#__PURE__*/ _asyncToGenerator(
1811
+ /*#__PURE__*/ _regenerator().m(function _callee() {
1812
+ var input;
1813
+ return _regenerator().w(function (_context) {
1814
+ while (1)
1815
+ switch (_context.n) {
1816
+ case 0:
1817
+ input = ctx.rollupOptions.input;
1818
+ if (!path.extname(input).toLowerCase().includes('ts')) {
1819
+ _context.n = 1;
1820
+ break;
1821
+ }
1822
+ _context.n = 1;
1823
+ return helper.insertTsconfig(ctx.envParams.workRootDir);
1824
+ case 1:
1825
+ return _context.a(2, next());
1826
+ }
1827
+ }, _callee);
1828
+ })
1829
+ );
1830
+ };
1831
+ };
1832
+ };
1833
+
1834
+ var rollupReactPluginMw = function rollupReactPluginMw() {
1835
+ return function (ctx) {
1836
+ return function (next) {
1837
+ return /*#__PURE__*/ _asyncToGenerator(
1838
+ /*#__PURE__*/ _regenerator().m(function _callee() {
1839
+ var _ctx$getDoraConfig,
1840
+ minimize,
1841
+ alias,
1842
+ copy,
1843
+ output,
1844
+ path$1,
1845
+ tsConfig,
1846
+ tsAlias,
1847
+ plugins;
1848
+ return _regenerator().w(function (_context) {
1849
+ while (1)
1850
+ switch (_context.n) {
1851
+ case 0:
1852
+ ((_ctx$getDoraConfig = ctx.getDoraConfig()),
1853
+ (minimize = _ctx$getDoraConfig.minimize),
1854
+ (alias = _ctx$getDoraConfig.alias),
1855
+ (copy = _ctx$getDoraConfig.copy),
1856
+ (output = _ctx$getDoraConfig.output));
1857
+ path$1 = output.path;
1858
+ tsConfig = ctx.configCtx.getTsConfig();
1859
+ tsAlias = helper.getTsPathAlias(tsConfig);
1860
+ _context.n = 1;
1861
+ return getReactPlugins({
1862
+ minimize: minimize,
1863
+ alias: _objectSpread2(_objectSpread2({}, tsAlias), alias),
1864
+ copy: copy,
1865
+ cssOutput: path.resolve(
1866
+ ctx.envParams.workRootDir,
1867
+ path$1,
1868
+ 'style/index.css'
1869
+ ),
1870
+ });
1871
+ case 1:
1872
+ plugins = _context.v;
1873
+ ctx.updateRollupOptions({
1874
+ plugins: plugins,
1875
+ });
1876
+ return _context.a(2, next());
1877
+ }
1878
+ }, _callee);
1879
+ })
1880
+ );
1881
+ };
1882
+ };
1883
+ };
1884
+ var rollupNodePluginMw = function rollupNodePluginMw() {
1885
+ return function (ctx) {
1886
+ return function (next) {
1887
+ return /*#__PURE__*/ _asyncToGenerator(
1888
+ /*#__PURE__*/ _regenerator().m(function _callee2() {
1889
+ var _ctx$getDoraConfig2, minimize, alias, tsConfig, tsAlias, plugins;
1890
+ return _regenerator().w(function (_context2) {
1891
+ while (1)
1892
+ switch (_context2.n) {
1893
+ case 0:
1894
+ ((_ctx$getDoraConfig2 = ctx.getDoraConfig()),
1895
+ (minimize = _ctx$getDoraConfig2.minimize),
1896
+ (alias = _ctx$getDoraConfig2.alias));
1897
+ tsConfig = ctx.configCtx.getTsConfig();
1898
+ tsAlias = helper.getTsPathAlias(tsConfig);
1899
+ _context2.n = 1;
1900
+ return getNodePlugins({
1901
+ minimize: minimize,
1902
+ alias: _objectSpread2(_objectSpread2({}, tsAlias), alias),
1903
+ });
1904
+ case 1:
1905
+ plugins = _context2.v;
1906
+ ctx.updateRollupOptions({
1907
+ plugins: plugins,
1908
+ });
1909
+ return _context2.a(2, next());
1910
+ }
1911
+ }, _callee2);
1912
+ })
1913
+ );
1914
+ };
1915
+ };
1916
+ };
1917
+ var rollupDtsPluginMw = function rollupDtsPluginMw() {
1918
+ return function (ctx) {
1919
+ return function (next) {
1920
+ return /*#__PURE__*/ _asyncToGenerator(
1921
+ /*#__PURE__*/ _regenerator().m(function _callee3() {
1922
+ var plugins;
1923
+ return _regenerator().w(function (_context3) {
1924
+ while (1)
1925
+ switch (_context3.n) {
1926
+ case 0:
1927
+ plugins = [
1928
+ getResolvePlugin(
1929
+ {
1930
+ extensions: ['.ts'],
1931
+ },
1932
+ {
1933
+ preferBuiltins: true,
1934
+ }
1935
+ ),
1936
+ getDtsPlugin(),
1937
+ ];
1938
+ ctx.updateRollupOptions({
1939
+ plugins: plugins,
1940
+ });
1941
+ return _context3.a(2, next());
1942
+ }
1943
+ }, _callee3);
1944
+ })
1945
+ );
1946
+ };
1947
+ };
1948
+ };
1949
+
1950
+ var rollupWatchMw = function rollupWatchMw() {
1951
+ return function (ctx) {
1952
+ return function (next) {
1953
+ return /*#__PURE__*/ _asyncToGenerator(
1954
+ /*#__PURE__*/ _regenerator().m(function _callee() {
1955
+ var watch;
1956
+ return _regenerator().w(function (_context) {
1957
+ while (1)
1958
+ switch (_context.n) {
1959
+ case 0:
1960
+ _context.n = 1;
1961
+ return getWatch(ctx.envParams);
1962
+ case 1:
1963
+ watch = _context.v;
1964
+ ctx.updateRollupOptions({
1965
+ watch: watch,
1966
+ });
1967
+ return _context.a(2, next());
1968
+ }
1969
+ }, _callee);
1970
+ })
1971
+ );
1972
+ };
1973
+ };
1974
+ };
1975
+
1976
+ var Ctx = /*#__PURE__*/ (function () {
1977
+ function Ctx(configCtx) {
1978
+ _classCallCheck(this, Ctx);
1979
+ _defineProperty(this, 'configCtx', void 0);
1980
+ _defineProperty(this, 'rollupOptions', {});
1981
+ _defineProperty(this, 'rollupOutputList', []);
1982
+ _defineProperty(this, 'envParams', {
1983
+ action: 'build',
1984
+ workRootDir: filePro.getCwd(),
1985
+ });
1986
+ this.configCtx = configCtx;
1987
+ }
1988
+ return _createClass(Ctx, [
1989
+ {
1990
+ key: 'updateEnvParams',
1991
+ value: function updateEnvParams(argv) {
1992
+ this.envParams = _objectSpread2(
1993
+ _objectSpread2({}, this.envParams),
1994
+ argv
1995
+ );
1996
+ },
1997
+ },
1998
+ {
1999
+ key: 'updateRollupOptions',
2000
+ value: function updateRollupOptions(options) {
2001
+ this.rollupOptions = _objectSpread2(
2002
+ _objectSpread2({}, this.rollupOptions),
2003
+ options
2004
+ );
2005
+ },
2006
+ },
2007
+ {
2008
+ key: 'updateRollupOutputList',
2009
+ value: function updateRollupOutputList(list) {
2010
+ var force =
2011
+ arguments.length > 1 && arguments[1] !== undefined
2012
+ ? arguments[1]
2013
+ : false;
2014
+ if (force) {
2015
+ this.rollupOutputList = list;
2016
+ } else {
2017
+ this.rollupOutputList = [].concat(
2018
+ _toConsumableArray(this.rollupOutputList),
2019
+ _toConsumableArray(list)
2020
+ );
2021
+ }
2022
+ },
2023
+ },
2024
+ {
2025
+ key: 'getDoraConfig',
2026
+ value: function getDoraConfig() {
2027
+ return this.configCtx.getDoraConfig();
2028
+ },
2029
+ },
2030
+ {
2031
+ key: 'geTDoraConfigRollup',
2032
+ value: function geTDoraConfigRollup() {
2033
+ return this.configCtx.getDoraConfig().rollupConfig || {};
2034
+ },
2035
+ },
2036
+ ]);
2037
+ })();
2038
+
2039
+ exports.Compiler = Compiler;
2040
+ exports.Ctx = Ctx;
2041
+ exports.envParamsMw = envParamsMw;
2042
+ exports.getAliasPlugin = getAliasPlugin;
2043
+ exports.getBabelPlugin = getBabelPlugin;
2044
+ exports.getCommonjsPlugin = getCommonjsPlugin;
2045
+ exports.getCopyPlugin = getCopyPlugin;
2046
+ exports.getDtsPlugin = getDtsPlugin;
2047
+ exports.getExternal = getExternal;
2048
+ exports.getFirstInput = getFirstInput;
2049
+ exports.getInput = getInput;
2050
+ exports.getJsonPlugin = getJsonPlugin;
2051
+ exports.getMinimizePlugin = getMinimizePlugin;
2052
+ exports.getNodePlugins = getNodePlugins;
2053
+ exports.getOutput = getOutput;
2054
+ exports.getOutputRuntime = getOutputRuntime;
2055
+ exports.getPostcssPlugin = getPostcssPlugin;
2056
+ exports.getReactPlugins = getReactPlugins;
2057
+ exports.getResolvePlugin = getResolvePlugin;
2058
+ exports.getWatch = getWatch;
2059
+ exports.handleError = handleError;
2060
+ exports.insertTsMw = insertTsMw;
2061
+ exports.mergeRollupOptions = mergeRollupOptions;
2062
+ exports.rollupDtsExternalMw = rollupDtsExternalMw;
2063
+ exports.rollupDtsInoutMw = rollupDtsInoutMw;
2064
+ exports.rollupDtsPluginMw = rollupDtsPluginMw;
2065
+ exports.rollupExternalMw = rollupExternalMw;
2066
+ exports.rollupInoutMw = rollupInoutMw;
2067
+ exports.rollupInputMw = rollupInputMw;
2068
+ exports.rollupNodePluginMw = rollupNodePluginMw;
2069
+ exports.rollupOutputListMw = rollupOutputListMw;
2070
+ exports.rollupReactPluginMw = rollupReactPluginMw;
2071
+ exports.rollupWatchLog = rollupWatchLog;
2072
+ exports.rollupWatchMw = rollupWatchMw;
2073
+ exports.rollupWatchOutputMw = rollupWatchOutputMw;