@doracli/esbuild-react 0.0.1
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/LICENSE +21 -0
- package/README.md +6 -0
- package/bin/enter.mjs +3 -0
- package/lib/cjs/index.js +187 -0
- package/lib/esm/index.js +185 -0
- package/lib/type/index.d.ts +6 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2029 zhangzhiguo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/bin/enter.mjs
ADDED
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var esbuild = require('@doracli/esbuild');
|
|
4
|
+
var helper = require('@doracli/helper');
|
|
5
|
+
var filePro = require('@dorabag/file-pro');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
var clear = function clear(ctx) {
|
|
9
|
+
return new Promise(function ($return, $error) {
|
|
10
|
+
var _ctx$getDoraConfig, clear, output, _ref, path;
|
|
11
|
+
_ctx$getDoraConfig = ctx.getDoraConfig(), clear = _ctx$getDoraConfig.clear, output = _ctx$getDoraConfig.output;
|
|
12
|
+
_ref = output || {}, path = _ref.path;
|
|
13
|
+
var $Try_1_Post = function () {
|
|
14
|
+
try {
|
|
15
|
+
return $return();
|
|
16
|
+
} catch ($boundEx) {
|
|
17
|
+
return $error($boundEx);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var $Try_1_Catch = function (_error) {
|
|
21
|
+
try {
|
|
22
|
+
helper.cLog.warn('clear', 'warn', "\u6E05\u7A7A\u76EE\u6807\u6587\u4EF6\u5939\u5931\u8D25: ".concat(path));
|
|
23
|
+
return $Try_1_Post();
|
|
24
|
+
} catch ($boundEx) {
|
|
25
|
+
return $error($boundEx);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
if (!clear) return $return();
|
|
30
|
+
if (!path) return $return();
|
|
31
|
+
return Promise.resolve(filePro.isValidDir(path)).then(function ($await_2) {
|
|
32
|
+
try {
|
|
33
|
+
if (!$await_2) return $return();
|
|
34
|
+
return Promise.resolve(filePro.cleanTargets(path)).then(function ($await_3) {
|
|
35
|
+
try {
|
|
36
|
+
return $Try_1_Post();
|
|
37
|
+
} catch ($boundEx) {
|
|
38
|
+
return $Try_1_Catch($boundEx);
|
|
39
|
+
}
|
|
40
|
+
}, $Try_1_Catch);
|
|
41
|
+
} catch ($boundEx) {
|
|
42
|
+
return $Try_1_Catch($boundEx);
|
|
43
|
+
}
|
|
44
|
+
}, $Try_1_Catch);
|
|
45
|
+
} catch (_error) {
|
|
46
|
+
$Try_1_Catch();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var ActionMap = {
|
|
52
|
+
build: helper.EnvEnum.prod
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var updateDefine = function updateDefine(ctx) {
|
|
56
|
+
var action = ctx.envParams.action;
|
|
57
|
+
ctx.updateEsbuildConfig({
|
|
58
|
+
define: esbuild.getDefine({
|
|
59
|
+
NODE_ENV: ActionMap[action] || helper.EnvEnum.prod
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
var updateEntryPoints = function updateEntryPoints(ctx) {
|
|
65
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
66
|
+
input = _ctx$getDoraConfig.input;
|
|
67
|
+
if (input) {
|
|
68
|
+
ctx.updateEsbuildConfig({
|
|
69
|
+
entryPoints: [input]
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
ctx.updateEsbuildConfig({
|
|
74
|
+
entryPoints: esbuild.getEntryPoints(ctx.envParams)
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var updateLoader = function updateLoader(ctx) {
|
|
79
|
+
ctx.updateEsbuildConfig({
|
|
80
|
+
loader: esbuild.getReactLoaderPreset()
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
var updateOutput = function updateOutput(ctx) {
|
|
85
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
86
|
+
output = _ctx$getDoraConfig.output;
|
|
87
|
+
var workRootDir = ctx.envParams.workRootDir;
|
|
88
|
+
var path$1 = output.path,
|
|
89
|
+
file = output.file;
|
|
90
|
+
ctx.updateEsbuildConfig({
|
|
91
|
+
outfile: path.join(workRootDir, path$1, file || 'index.js')
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
var updatePlugin = function updatePlugin(ctx) {
|
|
96
|
+
var plugins = [];
|
|
97
|
+
plugins.push(esbuild.getLessPlugin(), esbuild.getPostCssPlugin());
|
|
98
|
+
ctx.updateEsbuildConfig({
|
|
99
|
+
plugins: plugins
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
var updateTrivial = function updateTrivial(ctx) {
|
|
104
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
105
|
+
minimize = _ctx$getDoraConfig.minimize;
|
|
106
|
+
ctx.updateEsbuildConfig({
|
|
107
|
+
minify: minimize,
|
|
108
|
+
bundle: true,
|
|
109
|
+
platform: 'browser',
|
|
110
|
+
target: ['es2020'],
|
|
111
|
+
resolveExtensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
|
|
112
|
+
logLevel: 'info'
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
var initEsbuildConfig = function initEsbuildConfig(ctx) {
|
|
117
|
+
return new Promise(function ($return, $error) {
|
|
118
|
+
updateEntryPoints(ctx);
|
|
119
|
+
updateOutput(ctx);
|
|
120
|
+
updateDefine(ctx);
|
|
121
|
+
updateLoader(ctx);
|
|
122
|
+
updatePlugin(ctx);
|
|
123
|
+
updateTrivial(ctx);
|
|
124
|
+
return $return();
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
var buildBase = function buildBase(ctx) {
|
|
129
|
+
return new Promise(function ($return, $error) {
|
|
130
|
+
var timeEnd, res;
|
|
131
|
+
return Promise.resolve(initEsbuildConfig(ctx)).then(function ($await_1) {
|
|
132
|
+
try {
|
|
133
|
+
return Promise.resolve(clear(ctx)).then(function ($await_2) {
|
|
134
|
+
try {
|
|
135
|
+
timeEnd = helper.cLog.time('build');
|
|
136
|
+
return Promise.resolve(esbuild.builder(ctx.esbuildConfig)).then(function ($await_3) {
|
|
137
|
+
try {
|
|
138
|
+
res = $await_3;
|
|
139
|
+
timeEnd();
|
|
140
|
+
return $return(res);
|
|
141
|
+
} catch ($boundEx) {
|
|
142
|
+
return $error($boundEx);
|
|
143
|
+
}
|
|
144
|
+
}, $error);
|
|
145
|
+
} catch ($boundEx) {
|
|
146
|
+
return $error($boundEx);
|
|
147
|
+
}
|
|
148
|
+
}, $error);
|
|
149
|
+
} catch ($boundEx) {
|
|
150
|
+
return $error($boundEx);
|
|
151
|
+
}
|
|
152
|
+
}, $error);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
var buildSingle = function buildSingle(configCtx, envParams) {
|
|
157
|
+
return new Promise(function ($return, $error) {
|
|
158
|
+
var ctx, res, _ref, errors;
|
|
159
|
+
ctx = new esbuild.Ctx(configCtx);
|
|
160
|
+
ctx.updateEnvParams(envParams);
|
|
161
|
+
return Promise.resolve(buildBase(ctx)).then(function ($await_1) {
|
|
162
|
+
try {
|
|
163
|
+
res = $await_1;
|
|
164
|
+
_ref = res || {}, errors = _ref.errors;
|
|
165
|
+
if (errors !== null && errors !== void 0 && errors.length) {
|
|
166
|
+
helper.cLog.error('build', 'error', 'esbuld构建失败,捕获到错误');
|
|
167
|
+
errors.forEach(function (message) {
|
|
168
|
+
var detail = message.detail,
|
|
169
|
+
id = message.id,
|
|
170
|
+
location = message.location,
|
|
171
|
+
notes = message.notes,
|
|
172
|
+
pluginName = message.pluginName,
|
|
173
|
+
text = message.text;
|
|
174
|
+
console.log(id, location, pluginName, detail, notes, text);
|
|
175
|
+
});
|
|
176
|
+
return $return();
|
|
177
|
+
}
|
|
178
|
+
helper.cLog.info('build', 'success', 'esbuld构建成功');
|
|
179
|
+
return $return();
|
|
180
|
+
} catch ($boundEx) {
|
|
181
|
+
return $error($boundEx);
|
|
182
|
+
}
|
|
183
|
+
}, $error);
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
exports.buildSingle = buildSingle;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { getDefine, getEntryPoints, getReactLoaderPreset, getLessPlugin, getPostCssPlugin, builder, Ctx } from '@doracli/esbuild';
|
|
2
|
+
import { cLog, EnvEnum } from '@doracli/helper';
|
|
3
|
+
import { isValidDir, cleanTargets } from '@dorabag/file-pro';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
var clear = function clear(ctx) {
|
|
7
|
+
return new Promise(function ($return, $error) {
|
|
8
|
+
var _ctx$getDoraConfig, clear, output, _ref, path;
|
|
9
|
+
_ctx$getDoraConfig = ctx.getDoraConfig(), clear = _ctx$getDoraConfig.clear, output = _ctx$getDoraConfig.output;
|
|
10
|
+
_ref = output || {}, path = _ref.path;
|
|
11
|
+
var $Try_1_Post = function () {
|
|
12
|
+
try {
|
|
13
|
+
return $return();
|
|
14
|
+
} catch ($boundEx) {
|
|
15
|
+
return $error($boundEx);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var $Try_1_Catch = function (_error) {
|
|
19
|
+
try {
|
|
20
|
+
cLog.warn('clear', 'warn', "\u6E05\u7A7A\u76EE\u6807\u6587\u4EF6\u5939\u5931\u8D25: ".concat(path));
|
|
21
|
+
return $Try_1_Post();
|
|
22
|
+
} catch ($boundEx) {
|
|
23
|
+
return $error($boundEx);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
try {
|
|
27
|
+
if (!clear) return $return();
|
|
28
|
+
if (!path) return $return();
|
|
29
|
+
return Promise.resolve(isValidDir(path)).then(function ($await_2) {
|
|
30
|
+
try {
|
|
31
|
+
if (!$await_2) return $return();
|
|
32
|
+
return Promise.resolve(cleanTargets(path)).then(function ($await_3) {
|
|
33
|
+
try {
|
|
34
|
+
return $Try_1_Post();
|
|
35
|
+
} catch ($boundEx) {
|
|
36
|
+
return $Try_1_Catch($boundEx);
|
|
37
|
+
}
|
|
38
|
+
}, $Try_1_Catch);
|
|
39
|
+
} catch ($boundEx) {
|
|
40
|
+
return $Try_1_Catch($boundEx);
|
|
41
|
+
}
|
|
42
|
+
}, $Try_1_Catch);
|
|
43
|
+
} catch (_error) {
|
|
44
|
+
$Try_1_Catch();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var ActionMap = {
|
|
50
|
+
build: EnvEnum.prod
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var updateDefine = function updateDefine(ctx) {
|
|
54
|
+
var action = ctx.envParams.action;
|
|
55
|
+
ctx.updateEsbuildConfig({
|
|
56
|
+
define: getDefine({
|
|
57
|
+
NODE_ENV: ActionMap[action] || EnvEnum.prod
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
var updateEntryPoints = function updateEntryPoints(ctx) {
|
|
63
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
64
|
+
input = _ctx$getDoraConfig.input;
|
|
65
|
+
if (input) {
|
|
66
|
+
ctx.updateEsbuildConfig({
|
|
67
|
+
entryPoints: [input]
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
ctx.updateEsbuildConfig({
|
|
72
|
+
entryPoints: getEntryPoints(ctx.envParams)
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
var updateLoader = function updateLoader(ctx) {
|
|
77
|
+
ctx.updateEsbuildConfig({
|
|
78
|
+
loader: getReactLoaderPreset()
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var updateOutput = function updateOutput(ctx) {
|
|
83
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
84
|
+
output = _ctx$getDoraConfig.output;
|
|
85
|
+
var workRootDir = ctx.envParams.workRootDir;
|
|
86
|
+
var path = output.path,
|
|
87
|
+
file = output.file;
|
|
88
|
+
ctx.updateEsbuildConfig({
|
|
89
|
+
outfile: join(workRootDir, path, file || 'index.js')
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
var updatePlugin = function updatePlugin(ctx) {
|
|
94
|
+
var plugins = [];
|
|
95
|
+
plugins.push(getLessPlugin(), getPostCssPlugin());
|
|
96
|
+
ctx.updateEsbuildConfig({
|
|
97
|
+
plugins: plugins
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var updateTrivial = function updateTrivial(ctx) {
|
|
102
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
103
|
+
minimize = _ctx$getDoraConfig.minimize;
|
|
104
|
+
ctx.updateEsbuildConfig({
|
|
105
|
+
minify: minimize,
|
|
106
|
+
bundle: true,
|
|
107
|
+
platform: 'browser',
|
|
108
|
+
target: ['es2020'],
|
|
109
|
+
resolveExtensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
|
|
110
|
+
logLevel: 'info'
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
var initEsbuildConfig = function initEsbuildConfig(ctx) {
|
|
115
|
+
return new Promise(function ($return, $error) {
|
|
116
|
+
updateEntryPoints(ctx);
|
|
117
|
+
updateOutput(ctx);
|
|
118
|
+
updateDefine(ctx);
|
|
119
|
+
updateLoader(ctx);
|
|
120
|
+
updatePlugin(ctx);
|
|
121
|
+
updateTrivial(ctx);
|
|
122
|
+
return $return();
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var buildBase = function buildBase(ctx) {
|
|
127
|
+
return new Promise(function ($return, $error) {
|
|
128
|
+
var timeEnd, res;
|
|
129
|
+
return Promise.resolve(initEsbuildConfig(ctx)).then(function ($await_1) {
|
|
130
|
+
try {
|
|
131
|
+
return Promise.resolve(clear(ctx)).then(function ($await_2) {
|
|
132
|
+
try {
|
|
133
|
+
timeEnd = cLog.time('build');
|
|
134
|
+
return Promise.resolve(builder(ctx.esbuildConfig)).then(function ($await_3) {
|
|
135
|
+
try {
|
|
136
|
+
res = $await_3;
|
|
137
|
+
timeEnd();
|
|
138
|
+
return $return(res);
|
|
139
|
+
} catch ($boundEx) {
|
|
140
|
+
return $error($boundEx);
|
|
141
|
+
}
|
|
142
|
+
}, $error);
|
|
143
|
+
} catch ($boundEx) {
|
|
144
|
+
return $error($boundEx);
|
|
145
|
+
}
|
|
146
|
+
}, $error);
|
|
147
|
+
} catch ($boundEx) {
|
|
148
|
+
return $error($boundEx);
|
|
149
|
+
}
|
|
150
|
+
}, $error);
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
var buildSingle = function buildSingle(configCtx, envParams) {
|
|
155
|
+
return new Promise(function ($return, $error) {
|
|
156
|
+
var ctx, res, _ref, errors;
|
|
157
|
+
ctx = new Ctx(configCtx);
|
|
158
|
+
ctx.updateEnvParams(envParams);
|
|
159
|
+
return Promise.resolve(buildBase(ctx)).then(function ($await_1) {
|
|
160
|
+
try {
|
|
161
|
+
res = $await_1;
|
|
162
|
+
_ref = res || {}, errors = _ref.errors;
|
|
163
|
+
if (errors !== null && errors !== void 0 && errors.length) {
|
|
164
|
+
cLog.error('build', 'error', 'esbuld构建失败,捕获到错误');
|
|
165
|
+
errors.forEach(function (message) {
|
|
166
|
+
var detail = message.detail,
|
|
167
|
+
id = message.id,
|
|
168
|
+
location = message.location,
|
|
169
|
+
notes = message.notes,
|
|
170
|
+
pluginName = message.pluginName,
|
|
171
|
+
text = message.text;
|
|
172
|
+
console.log(id, location, pluginName, detail, notes, text);
|
|
173
|
+
});
|
|
174
|
+
return $return();
|
|
175
|
+
}
|
|
176
|
+
cLog.info('build', 'success', 'esbuld构建成功');
|
|
177
|
+
return $return();
|
|
178
|
+
} catch ($boundEx) {
|
|
179
|
+
return $error($boundEx);
|
|
180
|
+
}
|
|
181
|
+
}, $error);
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export { buildSingle };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@doracli/esbuild-react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "package by esbuild-react",
|
|
5
|
+
"author": "cclr <18843152354@163.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./lib/esm/index.js",
|
|
11
|
+
"require": "./lib/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"types": "lib/type/index.d.ts",
|
|
14
|
+
"bin": {
|
|
15
|
+
"desr": "bin/enter.mjs"
|
|
16
|
+
},
|
|
17
|
+
"directories": {
|
|
18
|
+
"lib": "lib"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"lib",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"g:test": "vitest run",
|
|
31
|
+
"build": "ccf build"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@cclr/lang": "^0.1.28",
|
|
35
|
+
"@cclr/utils": "^0.1.28",
|
|
36
|
+
"@dorabag/file-pro": "^1.0.10",
|
|
37
|
+
"@doracli/commander": "0.0.1",
|
|
38
|
+
"@doracli/esbuild": "0.0.1",
|
|
39
|
+
"@doracli/helper": "0.0.1",
|
|
40
|
+
"@doracli/type": "0.0.1"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "40ab496f25042487a671979074515f3345c96453"
|
|
43
|
+
}
|