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