@doracli/esbuild 0.0.1 → 0.0.2
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 +592 -1
- package/lib/esm/index.js +573 -1
- package/lib/type/index.d.ts +348 -16
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,592 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var esbuild = require('esbuild');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var lang = require('@cclr/lang');
|
|
6
|
+
var helper = require('@doracli/helper');
|
|
7
|
+
var esbuildPluginHtml = require('@craftamap/esbuild-plugin-html');
|
|
8
|
+
var esbuildPluginLess = require('esbuild-plugin-less');
|
|
9
|
+
var autoprefixer = require('autoprefixer');
|
|
10
|
+
var postCssPlugin = require('esbuild-plugin-postcss');
|
|
11
|
+
var esbuildPluginSass = require('esbuild-plugin-sass');
|
|
12
|
+
var filePro = require('@dorabag/file-pro');
|
|
13
|
+
|
|
14
|
+
function _assertThisInitialized(e) {
|
|
15
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
16
|
+
return e;
|
|
17
|
+
}
|
|
18
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
19
|
+
try {
|
|
20
|
+
var i = n[a](c),
|
|
21
|
+
u = i.value;
|
|
22
|
+
} catch (n) {
|
|
23
|
+
return void e(n);
|
|
24
|
+
}
|
|
25
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
26
|
+
}
|
|
27
|
+
function _asyncToGenerator(n) {
|
|
28
|
+
return function () {
|
|
29
|
+
var t = this,
|
|
30
|
+
e = arguments;
|
|
31
|
+
return new Promise(function (r, o) {
|
|
32
|
+
var a = n.apply(t, e);
|
|
33
|
+
function _next(n) {
|
|
34
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
35
|
+
}
|
|
36
|
+
function _throw(n) {
|
|
37
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
38
|
+
}
|
|
39
|
+
_next(void 0);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function _callSuper(t, o, e) {
|
|
44
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
45
|
+
}
|
|
46
|
+
function _classCallCheck(a, n) {
|
|
47
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
48
|
+
}
|
|
49
|
+
function _defineProperties(e, r) {
|
|
50
|
+
for (var t = 0; t < r.length; t++) {
|
|
51
|
+
var o = r[t];
|
|
52
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function _createClass(e, r, t) {
|
|
56
|
+
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
57
|
+
writable: false
|
|
58
|
+
}), e;
|
|
59
|
+
}
|
|
60
|
+
function _defineProperty(e, r, t) {
|
|
61
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
62
|
+
value: t,
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true
|
|
66
|
+
}) : e[r] = t, e;
|
|
67
|
+
}
|
|
68
|
+
function _getPrototypeOf(t) {
|
|
69
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
70
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
71
|
+
}, _getPrototypeOf(t);
|
|
72
|
+
}
|
|
73
|
+
function _inherits(t, e) {
|
|
74
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
75
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
76
|
+
constructor: {
|
|
77
|
+
value: t,
|
|
78
|
+
writable: true,
|
|
79
|
+
configurable: true
|
|
80
|
+
}
|
|
81
|
+
}), Object.defineProperty(t, "prototype", {
|
|
82
|
+
writable: false
|
|
83
|
+
}), e && _setPrototypeOf(t, e);
|
|
84
|
+
}
|
|
85
|
+
function _isNativeReflectConstruct() {
|
|
86
|
+
try {
|
|
87
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
88
|
+
} catch (t) {}
|
|
89
|
+
return (_isNativeReflectConstruct = function () {
|
|
90
|
+
return !!t;
|
|
91
|
+
})();
|
|
92
|
+
}
|
|
93
|
+
function ownKeys(e, r) {
|
|
94
|
+
var t = Object.keys(e);
|
|
95
|
+
if (Object.getOwnPropertySymbols) {
|
|
96
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
97
|
+
r && (o = o.filter(function (r) {
|
|
98
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
99
|
+
})), t.push.apply(t, o);
|
|
100
|
+
}
|
|
101
|
+
return t;
|
|
102
|
+
}
|
|
103
|
+
function _objectSpread2(e) {
|
|
104
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
105
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
106
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
107
|
+
_defineProperty(e, r, t[r]);
|
|
108
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
109
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return e;
|
|
113
|
+
}
|
|
114
|
+
function _possibleConstructorReturn(t, e) {
|
|
115
|
+
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
116
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
117
|
+
return _assertThisInitialized(t);
|
|
118
|
+
}
|
|
119
|
+
function _regenerator() {
|
|
120
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
121
|
+
var e,
|
|
122
|
+
t,
|
|
123
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
124
|
+
n = r.iterator || "@@iterator",
|
|
125
|
+
o = r.toStringTag || "@@toStringTag";
|
|
126
|
+
function i(r, n, o, i) {
|
|
127
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
128
|
+
u = Object.create(c.prototype);
|
|
129
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
130
|
+
var i,
|
|
131
|
+
c,
|
|
132
|
+
u,
|
|
133
|
+
f = 0,
|
|
134
|
+
p = o || [],
|
|
135
|
+
y = false,
|
|
136
|
+
G = {
|
|
137
|
+
p: 0,
|
|
138
|
+
n: 0,
|
|
139
|
+
v: e,
|
|
140
|
+
a: d,
|
|
141
|
+
f: d.bind(e, 4),
|
|
142
|
+
d: function (t, r) {
|
|
143
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
function d(r, n) {
|
|
147
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
148
|
+
var o,
|
|
149
|
+
i = p[t],
|
|
150
|
+
d = G.p,
|
|
151
|
+
l = i[2];
|
|
152
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
153
|
+
}
|
|
154
|
+
if (o || r > 1) return a;
|
|
155
|
+
throw y = true, n;
|
|
156
|
+
}
|
|
157
|
+
return function (o, p, l) {
|
|
158
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
159
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
160
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
161
|
+
try {
|
|
162
|
+
if (f = 2, i) {
|
|
163
|
+
if (c || (o = "next"), t = i[o]) {
|
|
164
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
165
|
+
if (!t.done) return t;
|
|
166
|
+
u = t.value, c < 2 && (c = 0);
|
|
167
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
168
|
+
i = e;
|
|
169
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
170
|
+
} catch (t) {
|
|
171
|
+
i = e, c = 1, u = t;
|
|
172
|
+
} finally {
|
|
173
|
+
f = 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
value: t,
|
|
178
|
+
done: y
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
}(r, o, i), true), u;
|
|
182
|
+
}
|
|
183
|
+
var a = {};
|
|
184
|
+
function Generator() {}
|
|
185
|
+
function GeneratorFunction() {}
|
|
186
|
+
function GeneratorFunctionPrototype() {}
|
|
187
|
+
t = Object.getPrototypeOf;
|
|
188
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
189
|
+
return this;
|
|
190
|
+
}), t),
|
|
191
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
192
|
+
function f(e) {
|
|
193
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
194
|
+
}
|
|
195
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
196
|
+
return this;
|
|
197
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
198
|
+
return "[object Generator]";
|
|
199
|
+
}), (_regenerator = function () {
|
|
200
|
+
return {
|
|
201
|
+
w: i,
|
|
202
|
+
m: f
|
|
203
|
+
};
|
|
204
|
+
})();
|
|
205
|
+
}
|
|
206
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
207
|
+
var i = Object.defineProperty;
|
|
208
|
+
try {
|
|
209
|
+
i({}, "", {});
|
|
210
|
+
} catch (e) {
|
|
211
|
+
i = 0;
|
|
212
|
+
}
|
|
213
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
214
|
+
function o(r, n) {
|
|
215
|
+
_regeneratorDefine(e, r, function (e) {
|
|
216
|
+
return this._invoke(r, n, e);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
r ? i ? i(e, r, {
|
|
220
|
+
value: n,
|
|
221
|
+
enumerable: !t,
|
|
222
|
+
configurable: !t,
|
|
223
|
+
writable: !t
|
|
224
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
225
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
226
|
+
}
|
|
227
|
+
function _setPrototypeOf(t, e) {
|
|
228
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
229
|
+
return t.__proto__ = e, t;
|
|
230
|
+
}, _setPrototypeOf(t, e);
|
|
231
|
+
}
|
|
232
|
+
function _toPrimitive(t, r) {
|
|
233
|
+
if ("object" != typeof t || !t) return t;
|
|
234
|
+
var e = t[Symbol.toPrimitive];
|
|
235
|
+
if (void 0 !== e) {
|
|
236
|
+
var i = e.call(t, r);
|
|
237
|
+
if ("object" != typeof i) return i;
|
|
238
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
239
|
+
}
|
|
240
|
+
return ("string" === r ? String : Number)(t);
|
|
241
|
+
}
|
|
242
|
+
function _toPropertyKey(t) {
|
|
243
|
+
var i = _toPrimitive(t, "string");
|
|
244
|
+
return "symbol" == typeof i ? i : i + "";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
var builder = /*#__PURE__*/function () {
|
|
248
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config) {
|
|
249
|
+
return _regenerator().w(function (_context) {
|
|
250
|
+
while (1) switch (_context.n) {
|
|
251
|
+
case 0:
|
|
252
|
+
return _context.a(2, esbuild.build(config));
|
|
253
|
+
}
|
|
254
|
+
}, _callee);
|
|
255
|
+
}));
|
|
256
|
+
return function builder(_x) {
|
|
257
|
+
return _ref.apply(this, arguments);
|
|
258
|
+
};
|
|
259
|
+
}();
|
|
260
|
+
|
|
261
|
+
var Compiler = /*#__PURE__*/function (_CompilerBase) {
|
|
262
|
+
function Compiler(config) {
|
|
263
|
+
var _this;
|
|
264
|
+
_classCallCheck(this, Compiler);
|
|
265
|
+
_this = _callSuper(this, Compiler, [config]);
|
|
266
|
+
_defineProperty(_this, "inOutMap", function (inputOutputMap) {
|
|
267
|
+
var inOutList = [];
|
|
268
|
+
Object.keys(inputOutputMap).forEach(function (input) {
|
|
269
|
+
var output = inputOutputMap[input];
|
|
270
|
+
inOutList.push({
|
|
271
|
+
in: input,
|
|
272
|
+
out: output
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
return _this.build({
|
|
276
|
+
entryPoints: inOutList
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
_defineProperty(_this, "context", /*#__PURE__*/function () {
|
|
280
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(opt) {
|
|
281
|
+
var ctx;
|
|
282
|
+
return _regenerator().w(function (_context) {
|
|
283
|
+
while (1) switch (_context.n) {
|
|
284
|
+
case 0:
|
|
285
|
+
_context.n = 1;
|
|
286
|
+
return esbuild.context(_objectSpread2(_objectSpread2({}, _this.initOptions), opt));
|
|
287
|
+
case 1:
|
|
288
|
+
ctx = _context.v;
|
|
289
|
+
return _context.a(2, {
|
|
290
|
+
rebuild: function rebuild() {
|
|
291
|
+
return ctx.rebuild();
|
|
292
|
+
},
|
|
293
|
+
cancel: function cancel() {
|
|
294
|
+
return ctx.cancel();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}, _callee);
|
|
299
|
+
}));
|
|
300
|
+
return function (_x) {
|
|
301
|
+
return _ref.apply(this, arguments);
|
|
302
|
+
};
|
|
303
|
+
}());
|
|
304
|
+
_defineProperty(_this, "input", function (input) {
|
|
305
|
+
return {
|
|
306
|
+
output: function () {
|
|
307
|
+
var _output = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(outputConfig) {
|
|
308
|
+
var finalConfig;
|
|
309
|
+
return _regenerator().w(function (_context2) {
|
|
310
|
+
while (1) switch (_context2.n) {
|
|
311
|
+
case 0:
|
|
312
|
+
finalConfig = _objectSpread2(_objectSpread2({}, _this.initOptions), {}, {
|
|
313
|
+
entryPoints: lang.isArray(input) ? input : [input],
|
|
314
|
+
outfile: path.resolve(outputConfig.dir, outputConfig.filename),
|
|
315
|
+
format: outputConfig.format || 'esm'
|
|
316
|
+
});
|
|
317
|
+
return _context2.a(2, esbuild.build(finalConfig));
|
|
318
|
+
}
|
|
319
|
+
}, _callee2);
|
|
320
|
+
}));
|
|
321
|
+
function output(_x2) {
|
|
322
|
+
return _output.apply(this, arguments);
|
|
323
|
+
}
|
|
324
|
+
return output;
|
|
325
|
+
}()
|
|
326
|
+
};
|
|
327
|
+
});
|
|
328
|
+
_defineProperty(_this, "build", function (options) {
|
|
329
|
+
return esbuild.build(_objectSpread2(_objectSpread2({}, _this.initOptions), options));
|
|
330
|
+
});
|
|
331
|
+
_defineProperty(_this, "watch", /*#__PURE__*/function () {
|
|
332
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
333
|
+
var ctx, server;
|
|
334
|
+
return _regenerator().w(function (_context3) {
|
|
335
|
+
while (1) switch (_context3.n) {
|
|
336
|
+
case 0:
|
|
337
|
+
_context3.n = 1;
|
|
338
|
+
return esbuild.context(_this.initOptions);
|
|
339
|
+
case 1:
|
|
340
|
+
ctx = _context3.v;
|
|
341
|
+
_context3.n = 2;
|
|
342
|
+
return ctx.watch(options);
|
|
343
|
+
case 2:
|
|
344
|
+
server = _context3.v;
|
|
345
|
+
return _context3.a(2, server);
|
|
346
|
+
}
|
|
347
|
+
}, _callee3);
|
|
348
|
+
}));
|
|
349
|
+
return function (_x3) {
|
|
350
|
+
return _ref2.apply(this, arguments);
|
|
351
|
+
};
|
|
352
|
+
}());
|
|
353
|
+
_defineProperty(_this, "server", /*#__PURE__*/function () {
|
|
354
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(serverConfig) {
|
|
355
|
+
var ctx, server;
|
|
356
|
+
return _regenerator().w(function (_context4) {
|
|
357
|
+
while (1) switch (_context4.n) {
|
|
358
|
+
case 0:
|
|
359
|
+
_context4.n = 1;
|
|
360
|
+
return esbuild.context(_this.initOptions);
|
|
361
|
+
case 1:
|
|
362
|
+
ctx = _context4.v;
|
|
363
|
+
_context4.n = 2;
|
|
364
|
+
return ctx.serve(serverConfig);
|
|
365
|
+
case 2:
|
|
366
|
+
server = _context4.v;
|
|
367
|
+
return _context4.a(2, server);
|
|
368
|
+
}
|
|
369
|
+
}, _callee4);
|
|
370
|
+
}));
|
|
371
|
+
return function (_x4) {
|
|
372
|
+
return _ref3.apply(this, arguments);
|
|
373
|
+
};
|
|
374
|
+
}());
|
|
375
|
+
return _this;
|
|
376
|
+
}
|
|
377
|
+
_inherits(Compiler, _CompilerBase);
|
|
378
|
+
return _createClass(Compiler);
|
|
379
|
+
}(helper.CompilerBase);
|
|
380
|
+
var createCompiler = function createCompiler(baseConfig) {
|
|
381
|
+
var esBuildOptions = _objectSpread2({
|
|
382
|
+
bundle: true,
|
|
383
|
+
// 打包所有依赖
|
|
384
|
+
minify: true,
|
|
385
|
+
// 压缩代码
|
|
386
|
+
sourcemap: true,
|
|
387
|
+
// 生成 Source Map
|
|
388
|
+
platform: 'node',
|
|
389
|
+
// 运行平台('node' 或 'browser')
|
|
390
|
+
target: ['esnext'],
|
|
391
|
+
// 目标环境
|
|
392
|
+
format: 'esm',
|
|
393
|
+
// 输出格式('esm'、'cjs' 或 'iife')
|
|
394
|
+
external: ['react', 'react-dom'],
|
|
395
|
+
// 标记为外部依赖,不打包
|
|
396
|
+
loader: {
|
|
397
|
+
'.ts': 'ts' // TypeScript 文件加载器
|
|
398
|
+
},
|
|
399
|
+
plugins: []
|
|
400
|
+
}, baseConfig);
|
|
401
|
+
return new Compiler(esBuildOptions);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
var getDefine = function getDefine(params) {
|
|
405
|
+
var NODE_ENV = params.NODE_ENV;
|
|
406
|
+
return {
|
|
407
|
+
'process.env.NODE_ENV': "\"".concat(NODE_ENV || 'production', "\"")
|
|
408
|
+
};
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
var inputFileDirList = ['src/index', 'index'];
|
|
412
|
+
var inputFileTypeList = ['.ts', '.js', '.tsx', '.jsx'];
|
|
413
|
+
var getEntryPoints = function getEntryPoints(envParams, input) {
|
|
414
|
+
if (input) {
|
|
415
|
+
return input;
|
|
416
|
+
}
|
|
417
|
+
var autoInput = helper.findInput(envParams.workRootDir);
|
|
418
|
+
if (!autoInput) {
|
|
419
|
+
helper.cLog.error('init', 'error', '需要有一个入口文件 index 或者 src/index');
|
|
420
|
+
process.exit(1);
|
|
421
|
+
}
|
|
422
|
+
return [autoInput];
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
var getReactLoaderPreset = function getReactLoaderPreset() {
|
|
426
|
+
return {
|
|
427
|
+
'.js': 'jsx',
|
|
428
|
+
// 处理 JS 文件中的 JSX
|
|
429
|
+
'.ts': 'ts',
|
|
430
|
+
// 处理 TypeScript 文件
|
|
431
|
+
'.tsx': 'tsx',
|
|
432
|
+
// 处理 TypeScript + JSX 文件
|
|
433
|
+
'.css': 'css',
|
|
434
|
+
// 处理 CSS 文件
|
|
435
|
+
'.png': 'file',
|
|
436
|
+
// 处理 PNG 图片
|
|
437
|
+
'.svg': 'file',
|
|
438
|
+
// 处理 SVG 文件
|
|
439
|
+
'.json': 'json' // 处理 SVG 文件
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
var getNodeLoaderPreset = function getNodeLoaderPreset() {
|
|
443
|
+
return {
|
|
444
|
+
'.js': 'jsx',
|
|
445
|
+
// 处理 JS 文件中的 JSX
|
|
446
|
+
'.ts': 'ts' // 处理 TypeScript 文件
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
var htmlPresetStr = "\n<!DOCTYPE html>\n<html lang=\"zh-CN\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>cclr</title>\n <!-- \u5F15\u5165\u6837\u5F0F -->\n <% for (var i in define.headBeforeStyle) { %>\n <link\n href=\"<%= define.headBeforeStyle[i] %>\"\n rel=\"stylesheet\"\n />\n <% } %>\n\n <!-- \u5F15\u5165js -->\n <% for (var i in define.headAfterScript) { %>\n <script src=\"<%= define.headAfterScript[i] %>\"></script>\n <% } %>\n </head>\n <body>\n <div id=\"main\">welcome use cclr !!</div>\n </body>\n</html>\n";
|
|
451
|
+
|
|
452
|
+
var getEsbuildPluginHtml = function getEsbuildPluginHtml(params) {
|
|
453
|
+
var cdnConfig = params.cdnConfig,
|
|
454
|
+
entry = params.entry;
|
|
455
|
+
return esbuildPluginHtml.htmlPlugin({
|
|
456
|
+
files: [_objectSpread2({
|
|
457
|
+
filename: 'index.html',
|
|
458
|
+
entryPoints: [entry],
|
|
459
|
+
htmlTemplate: htmlPresetStr,
|
|
460
|
+
define: _objectSpread2({}, cdnConfig)
|
|
461
|
+
}, params)]
|
|
462
|
+
});
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
var getLessPlugin = function getLessPlugin() {
|
|
466
|
+
return esbuildPluginLess.lessLoader();
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
var getPostCssPlugin = function getPostCssPlugin() {
|
|
470
|
+
return postCssPlugin.default({
|
|
471
|
+
postcssPlugin: [autoprefixer // 自动添加浏览器前缀
|
|
472
|
+
]
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
var getSassPlugin = function getSassPlugin() {
|
|
477
|
+
return esbuildPluginSass();
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
var getNodeBuildConfigPreset = function getNodeBuildConfigPreset(options) {
|
|
481
|
+
return _objectSpread2({
|
|
482
|
+
bundle: true,
|
|
483
|
+
minify: true,
|
|
484
|
+
sourcemap: true,
|
|
485
|
+
target: ['es2020'],
|
|
486
|
+
platform: 'browser',
|
|
487
|
+
define: {
|
|
488
|
+
'process.env.NODE_ENV': '"production"'
|
|
489
|
+
},
|
|
490
|
+
loader: {
|
|
491
|
+
'.png': 'file',
|
|
492
|
+
'.svg': 'file'
|
|
493
|
+
},
|
|
494
|
+
plugins: []
|
|
495
|
+
}, options);
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
var getReactBuildConfigPreset = function getReactBuildConfigPreset() {
|
|
499
|
+
return {
|
|
500
|
+
entryPoints: ['src/index.ts'],
|
|
501
|
+
outdir: 'dist',
|
|
502
|
+
bundle: true,
|
|
503
|
+
minify: true,
|
|
504
|
+
sourcemap: true,
|
|
505
|
+
target: ['es2020'],
|
|
506
|
+
platform: 'browser',
|
|
507
|
+
external: ['react', 'react-dom'],
|
|
508
|
+
define: {
|
|
509
|
+
'process.env.NODE_ENV': '"production"'
|
|
510
|
+
},
|
|
511
|
+
loader: {
|
|
512
|
+
'.png': 'file',
|
|
513
|
+
'.svg': 'file'
|
|
514
|
+
},
|
|
515
|
+
plugins: []
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
var createContext = function createContext() {
|
|
520
|
+
return esbuild.context({});
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
var Ctx = /*#__PURE__*/function () {
|
|
524
|
+
function Ctx(configCtx) {
|
|
525
|
+
_classCallCheck(this, Ctx);
|
|
526
|
+
_defineProperty(this, "configCtx", void 0);
|
|
527
|
+
_defineProperty(this, "esbuildConfig", {});
|
|
528
|
+
_defineProperty(this, "envParams", {
|
|
529
|
+
action: 'build',
|
|
530
|
+
workRootDir: filePro.getCwd()
|
|
531
|
+
});
|
|
532
|
+
this.configCtx = configCtx;
|
|
533
|
+
}
|
|
534
|
+
return _createClass(Ctx, [{
|
|
535
|
+
key: "updateEnvParams",
|
|
536
|
+
value: function updateEnvParams(argv) {
|
|
537
|
+
this.envParams = _objectSpread2(_objectSpread2({}, this.envParams), argv);
|
|
538
|
+
}
|
|
539
|
+
}, {
|
|
540
|
+
key: "updateEsbuildConfig",
|
|
541
|
+
value: function updateEsbuildConfig(config) {
|
|
542
|
+
this.esbuildConfig = _objectSpread2(_objectSpread2({}, this.esbuildConfig), config);
|
|
543
|
+
}
|
|
544
|
+
}, {
|
|
545
|
+
key: "getDoraConfig",
|
|
546
|
+
value: function getDoraConfig() {
|
|
547
|
+
return this.configCtx.getDoraConfig();
|
|
548
|
+
}
|
|
549
|
+
}, {
|
|
550
|
+
key: "geTDoraConfigEsbuild",
|
|
551
|
+
value: function geTDoraConfigEsbuild() {
|
|
552
|
+
return this.configCtx.getDoraConfig().esbuildConfig || {};
|
|
553
|
+
}
|
|
554
|
+
}]);
|
|
555
|
+
}();
|
|
556
|
+
|
|
557
|
+
var extractEntry = function extractEntry(entryPoints) {
|
|
558
|
+
var files = [];
|
|
559
|
+
if (!entryPoints) return [];
|
|
560
|
+
if (lang.isString(entryPoints)) files.push(entryPoints);else if (lang.isArray(entryPoints)) entryPoints.forEach(function (entry) {
|
|
561
|
+
if (lang.isString(entry)) files.push(entry);
|
|
562
|
+
if (lang.isObject(entry) && entry.in) files.push(entry.in);
|
|
563
|
+
});else if (lang.isObject(entryPoints)) {
|
|
564
|
+
// 对象可能是 { import: '...' } 或 { import: ['...'] }
|
|
565
|
+
// 也可能是其它描述符
|
|
566
|
+
// 尝试提取 import 字段
|
|
567
|
+
|
|
568
|
+
Object.values(entryPoints).forEach(function (val) {
|
|
569
|
+
return files.push(val);
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
return files;
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
exports.Compiler = Compiler;
|
|
576
|
+
exports.Ctx = Ctx;
|
|
577
|
+
exports.builder = builder;
|
|
578
|
+
exports.createCompiler = createCompiler;
|
|
579
|
+
exports.createContext = createContext;
|
|
580
|
+
exports.extractEntry = extractEntry;
|
|
581
|
+
exports.getDefine = getDefine;
|
|
582
|
+
exports.getEntryPoints = getEntryPoints;
|
|
583
|
+
exports.getEsbuildPluginHtml = getEsbuildPluginHtml;
|
|
584
|
+
exports.getLessPlugin = getLessPlugin;
|
|
585
|
+
exports.getNodeBuildConfigPreset = getNodeBuildConfigPreset;
|
|
586
|
+
exports.getNodeLoaderPreset = getNodeLoaderPreset;
|
|
587
|
+
exports.getPostCssPlugin = getPostCssPlugin;
|
|
588
|
+
exports.getReactBuildConfigPreset = getReactBuildConfigPreset;
|
|
589
|
+
exports.getReactLoaderPreset = getReactLoaderPreset;
|
|
590
|
+
exports.getSassPlugin = getSassPlugin;
|
|
591
|
+
exports.inputFileDirList = inputFileDirList;
|
|
592
|
+
exports.inputFileTypeList = inputFileTypeList;
|