@doracli/webpack-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 +545 -0
- package/lib/esm/index.js +538 -0
- package/lib/type/index.d.ts +20 -0
- package/package.json +47 -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,545 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var helper = require('@doracli/helper');
|
|
4
|
+
var webpack = require('@doracli/webpack');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var lang = require('@cclr/lang');
|
|
7
|
+
|
|
8
|
+
var updateDevtool = function updateDevtool(ctx) {
|
|
9
|
+
var devtool = webpack.getDevtool(ctx.envParams);
|
|
10
|
+
ctx.updateWebpackConfig({
|
|
11
|
+
devtool: devtool
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// export const getExternals = (ctx: Ctx): TExternals => {
|
|
16
|
+
// const { externals } = ctx.geTDoraConfigWebpack();
|
|
17
|
+
// if (externals) return externals;
|
|
18
|
+
|
|
19
|
+
// return [];
|
|
20
|
+
// };
|
|
21
|
+
|
|
22
|
+
var updateExternals = function updateExternals(ctx) {
|
|
23
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
24
|
+
userExternals = _ctx$getDoraConfig.externals;
|
|
25
|
+
var externals = webpack.getExternals(userExternals);
|
|
26
|
+
ctx.updateWebpackConfig({
|
|
27
|
+
externals: externals
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
var updateEntry = function updateEntry(ctx) {
|
|
32
|
+
var entry = webpack.getEntry(ctx.envParams);
|
|
33
|
+
ctx.updateWebpackConfig({
|
|
34
|
+
entry: entry
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var updateMode = function updateMode(ctx) {
|
|
39
|
+
var mode = webpack.getMode(ctx.envParams);
|
|
40
|
+
ctx.updateWebpackConfig({
|
|
41
|
+
mode: mode
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var updateModule = function updateModule(ctx) {
|
|
46
|
+
return new Promise(function ($return, $error) {
|
|
47
|
+
var module = webpack.getReactModulePreset(ctx.envParams);
|
|
48
|
+
ctx.updateWebpackConfig({
|
|
49
|
+
module: module
|
|
50
|
+
});
|
|
51
|
+
return $return();
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var updateOptimization = function updateOptimization(ctx) {
|
|
56
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
57
|
+
minimize = _ctx$getDoraConfig.minimize;
|
|
58
|
+
var optimization = webpack.getOptimization({
|
|
59
|
+
minimize: minimize
|
|
60
|
+
});
|
|
61
|
+
ctx.updateWebpackConfig({
|
|
62
|
+
optimization: optimization
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
var updateOutput = function updateOutput(ctx) {
|
|
67
|
+
var output = webpack.getOutput(ctx.envParams);
|
|
68
|
+
ctx.updateWebpackConfig({
|
|
69
|
+
output: output
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var ActionMap = {
|
|
74
|
+
build: helper.EnvEnum.prod,
|
|
75
|
+
server: helper.EnvEnum.dev,
|
|
76
|
+
lib: helper.EnvEnum.prod
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
var updatePlugins = function updatePlugins(ctx) {
|
|
80
|
+
return new Promise(function ($return, $error) {
|
|
81
|
+
var cdnConfig, _ctx$getDoraConfig, minimize, plugins;
|
|
82
|
+
return Promise.resolve(helper.parseCdnConfig(ctx.configCtx.getCdnConfig(), ActionMap[ctx.envParams.action])).then(function ($await_1) {
|
|
83
|
+
try {
|
|
84
|
+
cdnConfig = $await_1;
|
|
85
|
+
_ctx$getDoraConfig = ctx.getDoraConfig(), minimize = _ctx$getDoraConfig.minimize;
|
|
86
|
+
plugins = webpack.getReactPluginsPreset(ctx.envParams, {
|
|
87
|
+
HtmlWebpackPluginOptions: cdnConfig,
|
|
88
|
+
minimize: minimize
|
|
89
|
+
});
|
|
90
|
+
return $return(ctx.updateWebpackConfig({
|
|
91
|
+
plugins: plugins
|
|
92
|
+
}));
|
|
93
|
+
} catch ($boundEx) {
|
|
94
|
+
return $error($boundEx);
|
|
95
|
+
}
|
|
96
|
+
}, $error);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
function _arrayLikeToArray(r, a) {
|
|
101
|
+
(null == a || a > r.length) && (a = r.length);
|
|
102
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
103
|
+
return n;
|
|
104
|
+
}
|
|
105
|
+
function _arrayWithoutHoles(r) {
|
|
106
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
107
|
+
}
|
|
108
|
+
function _defineProperty(e, r, t) {
|
|
109
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
110
|
+
value: t,
|
|
111
|
+
enumerable: true,
|
|
112
|
+
configurable: true,
|
|
113
|
+
writable: true
|
|
114
|
+
}) : e[r] = t, e;
|
|
115
|
+
}
|
|
116
|
+
function _iterableToArray(r) {
|
|
117
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
118
|
+
}
|
|
119
|
+
function _nonIterableSpread() {
|
|
120
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
121
|
+
}
|
|
122
|
+
function ownKeys(e, r) {
|
|
123
|
+
var t = Object.keys(e);
|
|
124
|
+
if (Object.getOwnPropertySymbols) {
|
|
125
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
126
|
+
r && (o = o.filter(function (r) {
|
|
127
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
128
|
+
})), t.push.apply(t, o);
|
|
129
|
+
}
|
|
130
|
+
return t;
|
|
131
|
+
}
|
|
132
|
+
function _objectSpread2(e) {
|
|
133
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
134
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
135
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
136
|
+
_defineProperty(e, r, t[r]);
|
|
137
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
138
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return e;
|
|
142
|
+
}
|
|
143
|
+
function _toConsumableArray(r) {
|
|
144
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
145
|
+
}
|
|
146
|
+
function _toPrimitive(t, r) {
|
|
147
|
+
if ("object" != typeof t || !t) return t;
|
|
148
|
+
var e = t[Symbol.toPrimitive];
|
|
149
|
+
if (void 0 !== e) {
|
|
150
|
+
var i = e.call(t, r);
|
|
151
|
+
if ("object" != typeof i) return i;
|
|
152
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
153
|
+
}
|
|
154
|
+
return ("string" === r ? String : Number)(t);
|
|
155
|
+
}
|
|
156
|
+
function _toPropertyKey(t) {
|
|
157
|
+
var i = _toPrimitive(t, "string");
|
|
158
|
+
return "symbol" == typeof i ? i : i + "";
|
|
159
|
+
}
|
|
160
|
+
function _unsupportedIterableToArray(r, a) {
|
|
161
|
+
if (r) {
|
|
162
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
163
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
164
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 获取webpack的resolve配置
|
|
170
|
+
* @param userResolve
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
var updateResolve = function updateResolve(ctx) {
|
|
174
|
+
var tsConfig = ctx.configCtx.getTsConfig();
|
|
175
|
+
var _ctx$geTDoraConfigWeb = ctx.geTDoraConfigWebpack(),
|
|
176
|
+
userConfigResolve = _ctx$geTDoraConfigWeb.resolve;
|
|
177
|
+
var injectAlias = lang.get(userConfigResolve, 'alias', {});
|
|
178
|
+
var injectExtensions = lang.get(userConfigResolve, 'extensions', []);
|
|
179
|
+
var tsAlias = helper.getTsPathAlias(tsConfig);
|
|
180
|
+
var resolveObj = {
|
|
181
|
+
extensions: Array.from(new Set(['.ts', '.tsx', '.js', '.jsx'].concat(_toConsumableArray(injectExtensions)))),
|
|
182
|
+
alias: _objectSpread2(_objectSpread2({
|
|
183
|
+
'@src': path.resolve('src'),
|
|
184
|
+
'@': path.resolve('src')
|
|
185
|
+
}, tsAlias), injectAlias)
|
|
186
|
+
};
|
|
187
|
+
ctx.updateWebpackConfig({
|
|
188
|
+
resolve: resolveObj
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
var updateResolveLoader = function updateResolveLoader(ctx) {
|
|
193
|
+
var resolveLoader = webpack.getResolveLoader();
|
|
194
|
+
ctx.updateWebpackConfig({
|
|
195
|
+
resolveLoader: resolveLoader
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
var initWebpackConfig = function initWebpackConfig(ctx) {
|
|
200
|
+
return new Promise(function ($return, $error) {
|
|
201
|
+
return Promise.resolve(updateMode(ctx)).then(function ($await_1) {
|
|
202
|
+
try {
|
|
203
|
+
return Promise.resolve(updateEntry(ctx)).then(function ($await_2) {
|
|
204
|
+
try {
|
|
205
|
+
return Promise.resolve(updateOutput(ctx)).then(function ($await_3) {
|
|
206
|
+
try {
|
|
207
|
+
return Promise.resolve(updateDevtool(ctx)).then(function ($await_4) {
|
|
208
|
+
try {
|
|
209
|
+
return Promise.resolve(updateExternals(ctx)).then(function ($await_5) {
|
|
210
|
+
try {
|
|
211
|
+
return Promise.resolve(updateResolve(ctx)).then(function ($await_6) {
|
|
212
|
+
try {
|
|
213
|
+
return Promise.resolve(updateResolveLoader(ctx)).then(function ($await_7) {
|
|
214
|
+
try {
|
|
215
|
+
return Promise.resolve(updateOptimization(ctx)).then(function ($await_8) {
|
|
216
|
+
try {
|
|
217
|
+
return Promise.resolve(updateModule(ctx)).then(function ($await_9) {
|
|
218
|
+
try {
|
|
219
|
+
return Promise.resolve(updatePlugins(ctx)).then(function ($await_10) {
|
|
220
|
+
try {
|
|
221
|
+
return $return();
|
|
222
|
+
} catch ($boundEx) {
|
|
223
|
+
return $error($boundEx);
|
|
224
|
+
}
|
|
225
|
+
}, $error);
|
|
226
|
+
} catch ($boundEx) {
|
|
227
|
+
return $error($boundEx);
|
|
228
|
+
}
|
|
229
|
+
}, $error);
|
|
230
|
+
} catch ($boundEx) {
|
|
231
|
+
return $error($boundEx);
|
|
232
|
+
}
|
|
233
|
+
}, $error);
|
|
234
|
+
} catch ($boundEx) {
|
|
235
|
+
return $error($boundEx);
|
|
236
|
+
}
|
|
237
|
+
}, $error);
|
|
238
|
+
} catch ($boundEx) {
|
|
239
|
+
return $error($boundEx);
|
|
240
|
+
}
|
|
241
|
+
}, $error);
|
|
242
|
+
} catch ($boundEx) {
|
|
243
|
+
return $error($boundEx);
|
|
244
|
+
}
|
|
245
|
+
}, $error);
|
|
246
|
+
} catch ($boundEx) {
|
|
247
|
+
return $error($boundEx);
|
|
248
|
+
}
|
|
249
|
+
}, $error);
|
|
250
|
+
} catch ($boundEx) {
|
|
251
|
+
return $error($boundEx);
|
|
252
|
+
}
|
|
253
|
+
}, $error);
|
|
254
|
+
} catch ($boundEx) {
|
|
255
|
+
return $error($boundEx);
|
|
256
|
+
}
|
|
257
|
+
}, $error);
|
|
258
|
+
} catch ($boundEx) {
|
|
259
|
+
return $error($boundEx);
|
|
260
|
+
}
|
|
261
|
+
}, $error);
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
var buildBase = function buildBase(ctx) {
|
|
266
|
+
return new Promise(function ($return, $error) {
|
|
267
|
+
var timeEnd, res;
|
|
268
|
+
return Promise.resolve(initWebpackConfig(ctx)).then(function ($await_1) {
|
|
269
|
+
try {
|
|
270
|
+
timeEnd = helper.cLog.time('build');
|
|
271
|
+
return Promise.resolve(webpack.build(ctx.webpackConfig)).then(function ($await_2) {
|
|
272
|
+
try {
|
|
273
|
+
res = $await_2;
|
|
274
|
+
timeEnd();
|
|
275
|
+
return $return(res);
|
|
276
|
+
} catch ($boundEx) {
|
|
277
|
+
return $error($boundEx);
|
|
278
|
+
}
|
|
279
|
+
}, $error);
|
|
280
|
+
} catch ($boundEx) {
|
|
281
|
+
return $error($boundEx);
|
|
282
|
+
}
|
|
283
|
+
}, $error);
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
var buildSingle = function buildSingle(configCtx, envParams) {
|
|
288
|
+
return new Promise(function ($return, $error) {
|
|
289
|
+
var ctx, res, _ref, err, stats, _stats$compilation;
|
|
290
|
+
ctx = new webpack.Ctx(configCtx);
|
|
291
|
+
ctx.updateEnvParams(envParams);
|
|
292
|
+
return Promise.resolve(buildBase(ctx)).then(function ($await_1) {
|
|
293
|
+
try {
|
|
294
|
+
res = $await_1;
|
|
295
|
+
_ref = res || {}, err = _ref.err, stats = _ref.stats;
|
|
296
|
+
if (err) {
|
|
297
|
+
helper.cLog.error('build', 'build_error', 'webpack构建失败,捕获到错误');
|
|
298
|
+
console.error(err);
|
|
299
|
+
return $return();
|
|
300
|
+
}
|
|
301
|
+
if (stats !== null && stats !== void 0 && stats.hasErrors()) {
|
|
302
|
+
helper.cLog.error('build', 'build_error', 'webpack构建失败,捕获到状态错误');
|
|
303
|
+
stats === null || stats === void 0 || (_stats$compilation = stats.compilation) === null || _stats$compilation === void 0 || (_stats$compilation = _stats$compilation.errors) === null || _stats$compilation === void 0 || _stats$compilation.forEach(function (error) {
|
|
304
|
+
console.error(error);
|
|
305
|
+
});
|
|
306
|
+
return $return();
|
|
307
|
+
}
|
|
308
|
+
helper.cLog.info('build', 'build_success', 'webpack构建成功');
|
|
309
|
+
return $return();
|
|
310
|
+
} catch ($boundEx) {
|
|
311
|
+
return $error($boundEx);
|
|
312
|
+
}
|
|
313
|
+
}, $error);
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
var version = "0.0.0";
|
|
318
|
+
|
|
319
|
+
/** 生产预设配置 */
|
|
320
|
+
var presetDoracliDefaultConfig = {
|
|
321
|
+
output: {
|
|
322
|
+
path: './dist'
|
|
323
|
+
},
|
|
324
|
+
formatList: ['cjs'],
|
|
325
|
+
alias: {},
|
|
326
|
+
externals: [],
|
|
327
|
+
internals: [],
|
|
328
|
+
minimize: true,
|
|
329
|
+
clear: false,
|
|
330
|
+
copy: {},
|
|
331
|
+
dts: {}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/** 生产预设配置 */
|
|
335
|
+
var presetDoracliBuildConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
336
|
+
minimize: true,
|
|
337
|
+
clear: true
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
var buildEntry = function buildEntry(cmd) {
|
|
341
|
+
return new Promise(function ($return, $error) {
|
|
342
|
+
var envParams, configCtx;
|
|
343
|
+
envParams = {
|
|
344
|
+
action: 'build',
|
|
345
|
+
workRootDir: process.cwd()
|
|
346
|
+
};
|
|
347
|
+
configCtx = new helper.ConfigCtx();
|
|
348
|
+
configCtx.setCmd(cmd);
|
|
349
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
350
|
+
return Promise.resolve(helper.collectConfig(configCtx, ActionMap[envParams.action], {
|
|
351
|
+
doraConfig: presetDoracliBuildConfig
|
|
352
|
+
})).then(function ($await_1) {
|
|
353
|
+
try {
|
|
354
|
+
return $return(buildSingle(configCtx, envParams));
|
|
355
|
+
} catch ($boundEx) {
|
|
356
|
+
return $error($boundEx);
|
|
357
|
+
}
|
|
358
|
+
}, $error);
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/** 生产预设配置 */
|
|
363
|
+
var presetDoracliDevConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
364
|
+
clear: true,
|
|
365
|
+
minimize: false
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
var devEntry = function devEntry(cmd) {
|
|
369
|
+
return new Promise(function ($return, $error) {
|
|
370
|
+
var envParams, configCtx;
|
|
371
|
+
envParams = {
|
|
372
|
+
action: 'build',
|
|
373
|
+
workRootDir: process.cwd()
|
|
374
|
+
};
|
|
375
|
+
configCtx = new helper.ConfigCtx();
|
|
376
|
+
configCtx.setCmd(cmd);
|
|
377
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
378
|
+
return Promise.resolve(helper.collectConfig(configCtx, ActionMap[envParams.action], {
|
|
379
|
+
doraConfig: presetDoracliDevConfig
|
|
380
|
+
})).then(function ($await_1) {
|
|
381
|
+
try {
|
|
382
|
+
return $return(buildSingle(configCtx, envParams));
|
|
383
|
+
} catch ($boundEx) {
|
|
384
|
+
return $error($boundEx);
|
|
385
|
+
}
|
|
386
|
+
}, $error);
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/** 生产预设配置 */
|
|
391
|
+
var presetDoracliServerConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
392
|
+
clear: false,
|
|
393
|
+
minimize: false,
|
|
394
|
+
webpackConfig: {
|
|
395
|
+
serviceConfig: {
|
|
396
|
+
open: true
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
var updateDevServer = function updateDevServer(ctx) {
|
|
402
|
+
var userServiceConfig = ctx.geTDoraConfigWebpack().serviceConfig || {};
|
|
403
|
+
ctx.updateDevServerConfig(webpack.getDevServer(userServiceConfig));
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
var serverBase = function serverBase(ctx) {
|
|
407
|
+
return new Promise(function ($return, $error) {
|
|
408
|
+
var compiler;
|
|
409
|
+
return Promise.resolve(initWebpackConfig(ctx)).then(function ($await_1) {
|
|
410
|
+
try {
|
|
411
|
+
return Promise.resolve(updateDevServer(ctx)).then(function ($await_2) {
|
|
412
|
+
try {
|
|
413
|
+
compiler = webpack.createCompiler(ctx.webpackConfig);
|
|
414
|
+
return Promise.resolve(webpack.service(ctx.devServerConfig, compiler)).then(function ($await_3) {
|
|
415
|
+
try {
|
|
416
|
+
return $return();
|
|
417
|
+
} catch ($boundEx) {
|
|
418
|
+
return $error($boundEx);
|
|
419
|
+
}
|
|
420
|
+
}, $error);
|
|
421
|
+
} catch ($boundEx) {
|
|
422
|
+
return $error($boundEx);
|
|
423
|
+
}
|
|
424
|
+
}, $error);
|
|
425
|
+
} catch ($boundEx) {
|
|
426
|
+
return $error($boundEx);
|
|
427
|
+
}
|
|
428
|
+
}, $error);
|
|
429
|
+
});
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
var serverSingle = function serverSingle(configCtx, envParams) {
|
|
433
|
+
return new Promise(function ($return, $error) {
|
|
434
|
+
var ctx;
|
|
435
|
+
ctx = new webpack.Ctx(configCtx);
|
|
436
|
+
ctx.updateEnvParams(envParams);
|
|
437
|
+
return Promise.resolve(serverBase(ctx)).then(function ($await_1) {
|
|
438
|
+
try {
|
|
439
|
+
helper.cLog.info('server', 'success', 'webpack 服务启动成功~');
|
|
440
|
+
return $return();
|
|
441
|
+
} catch ($boundEx) {
|
|
442
|
+
return $error($boundEx);
|
|
443
|
+
}
|
|
444
|
+
}, $error);
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
var serverEntry = function serverEntry(cmd) {
|
|
449
|
+
return new Promise(function ($return, $error) {
|
|
450
|
+
var envParams, configCtx, cdnConfig;
|
|
451
|
+
envParams = {
|
|
452
|
+
action: 'server',
|
|
453
|
+
workRootDir: process.cwd()
|
|
454
|
+
};
|
|
455
|
+
configCtx = new helper.ConfigCtx();
|
|
456
|
+
configCtx.setCmd(cmd);
|
|
457
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
458
|
+
return Promise.resolve(helper.collectConfig(configCtx, ActionMap[envParams.action], {
|
|
459
|
+
doraConfig: presetDoracliServerConfig
|
|
460
|
+
})).then(function ($await_1) {
|
|
461
|
+
try {
|
|
462
|
+
return Promise.resolve(helper.resolveCdnConfig(envParams.workRootDir, ActionMap[envParams.action])).then(function ($await_2) {
|
|
463
|
+
try {
|
|
464
|
+
cdnConfig = $await_2 || {};
|
|
465
|
+
configCtx.setCdnConfig(cdnConfig);
|
|
466
|
+
return $return(serverSingle(configCtx, envParams));
|
|
467
|
+
} catch ($boundEx) {
|
|
468
|
+
return $error($boundEx);
|
|
469
|
+
}
|
|
470
|
+
}, $error);
|
|
471
|
+
} catch ($boundEx) {
|
|
472
|
+
return $error($boundEx);
|
|
473
|
+
}
|
|
474
|
+
}, $error);
|
|
475
|
+
});
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
var childCommands = [{
|
|
479
|
+
command: 'server',
|
|
480
|
+
description: 'run a project by dev',
|
|
481
|
+
options: [{
|
|
482
|
+
name: 'format',
|
|
483
|
+
simpleName: 'f',
|
|
484
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
485
|
+
description: 'set output module type'
|
|
486
|
+
}, {
|
|
487
|
+
name: 'workRootDir',
|
|
488
|
+
simpleName: 'r',
|
|
489
|
+
type: '[string]',
|
|
490
|
+
description: 'set work root path',
|
|
491
|
+
defaultValue: './'
|
|
492
|
+
}],
|
|
493
|
+
action: function action(env) {
|
|
494
|
+
serverEntry(env);
|
|
495
|
+
}
|
|
496
|
+
}, {
|
|
497
|
+
command: 'build',
|
|
498
|
+
description: 'run a project by build',
|
|
499
|
+
options: [{
|
|
500
|
+
name: 'format',
|
|
501
|
+
simpleName: 'f',
|
|
502
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
503
|
+
description: 'set output module type'
|
|
504
|
+
}, {
|
|
505
|
+
name: 'workRootDir',
|
|
506
|
+
simpleName: 'r',
|
|
507
|
+
type: '[string]',
|
|
508
|
+
description: 'set work root path',
|
|
509
|
+
defaultValue: './'
|
|
510
|
+
}],
|
|
511
|
+
action: function action(env) {
|
|
512
|
+
buildEntry(env);
|
|
513
|
+
}
|
|
514
|
+
}, {
|
|
515
|
+
command: 'dev',
|
|
516
|
+
description: 'run a project by build',
|
|
517
|
+
options: [{
|
|
518
|
+
name: 'format',
|
|
519
|
+
simpleName: 'f',
|
|
520
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
521
|
+
description: 'set output module type'
|
|
522
|
+
}, {
|
|
523
|
+
name: 'workRootDir',
|
|
524
|
+
simpleName: 'r',
|
|
525
|
+
type: '[string]',
|
|
526
|
+
description: 'set work root path',
|
|
527
|
+
defaultValue: './'
|
|
528
|
+
}],
|
|
529
|
+
action: function action(env) {
|
|
530
|
+
devEntry(env);
|
|
531
|
+
}
|
|
532
|
+
}];
|
|
533
|
+
var commandOptions = {
|
|
534
|
+
name: 'magic',
|
|
535
|
+
usage: 'magic <command> [option]',
|
|
536
|
+
version: version,
|
|
537
|
+
childCommands: childCommands
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
exports.buildBase = buildBase;
|
|
541
|
+
exports.buildSingle = buildSingle;
|
|
542
|
+
exports.childCommands = childCommands;
|
|
543
|
+
exports.commandOptions = commandOptions;
|
|
544
|
+
exports.serverBase = serverBase;
|
|
545
|
+
exports.serverSingle = serverSingle;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { EnvEnum, parseCdnConfig, getTsPathAlias, cLog, ConfigCtx, collectConfig, resolveCdnConfig } from '@doracli/helper';
|
|
2
|
+
import { getDevtool, getExternals, getEntry, getMode, getReactModulePreset, getOptimization, getOutput, getReactPluginsPreset, getResolveLoader, build, Ctx, getDevServer, createCompiler, service } from '@doracli/webpack';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { get } from '@cclr/lang';
|
|
5
|
+
|
|
6
|
+
var updateDevtool = function updateDevtool(ctx) {
|
|
7
|
+
var devtool = getDevtool(ctx.envParams);
|
|
8
|
+
ctx.updateWebpackConfig({
|
|
9
|
+
devtool: devtool
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// export const getExternals = (ctx: Ctx): TExternals => {
|
|
14
|
+
// const { externals } = ctx.geTDoraConfigWebpack();
|
|
15
|
+
// if (externals) return externals;
|
|
16
|
+
|
|
17
|
+
// return [];
|
|
18
|
+
// };
|
|
19
|
+
|
|
20
|
+
var updateExternals = function updateExternals(ctx) {
|
|
21
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
22
|
+
userExternals = _ctx$getDoraConfig.externals;
|
|
23
|
+
var externals = getExternals(userExternals);
|
|
24
|
+
ctx.updateWebpackConfig({
|
|
25
|
+
externals: externals
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var updateEntry = function updateEntry(ctx) {
|
|
30
|
+
var entry = getEntry(ctx.envParams);
|
|
31
|
+
ctx.updateWebpackConfig({
|
|
32
|
+
entry: entry
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var updateMode = function updateMode(ctx) {
|
|
37
|
+
var mode = getMode(ctx.envParams);
|
|
38
|
+
ctx.updateWebpackConfig({
|
|
39
|
+
mode: mode
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var updateModule = function updateModule(ctx) {
|
|
44
|
+
return new Promise(function ($return, $error) {
|
|
45
|
+
var module = getReactModulePreset(ctx.envParams);
|
|
46
|
+
ctx.updateWebpackConfig({
|
|
47
|
+
module: module
|
|
48
|
+
});
|
|
49
|
+
return $return();
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var updateOptimization = function updateOptimization(ctx) {
|
|
54
|
+
var _ctx$getDoraConfig = ctx.getDoraConfig(),
|
|
55
|
+
minimize = _ctx$getDoraConfig.minimize;
|
|
56
|
+
var optimization = getOptimization({
|
|
57
|
+
minimize: minimize
|
|
58
|
+
});
|
|
59
|
+
ctx.updateWebpackConfig({
|
|
60
|
+
optimization: optimization
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
var updateOutput = function updateOutput(ctx) {
|
|
65
|
+
var output = getOutput(ctx.envParams);
|
|
66
|
+
ctx.updateWebpackConfig({
|
|
67
|
+
output: output
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var ActionMap = {
|
|
72
|
+
build: EnvEnum.prod,
|
|
73
|
+
server: EnvEnum.dev,
|
|
74
|
+
lib: EnvEnum.prod
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var updatePlugins = function updatePlugins(ctx) {
|
|
78
|
+
return new Promise(function ($return, $error) {
|
|
79
|
+
var cdnConfig, _ctx$getDoraConfig, minimize, plugins;
|
|
80
|
+
return Promise.resolve(parseCdnConfig(ctx.configCtx.getCdnConfig(), ActionMap[ctx.envParams.action])).then(function ($await_1) {
|
|
81
|
+
try {
|
|
82
|
+
cdnConfig = $await_1;
|
|
83
|
+
_ctx$getDoraConfig = ctx.getDoraConfig(), minimize = _ctx$getDoraConfig.minimize;
|
|
84
|
+
plugins = getReactPluginsPreset(ctx.envParams, {
|
|
85
|
+
HtmlWebpackPluginOptions: cdnConfig,
|
|
86
|
+
minimize: minimize
|
|
87
|
+
});
|
|
88
|
+
return $return(ctx.updateWebpackConfig({
|
|
89
|
+
plugins: plugins
|
|
90
|
+
}));
|
|
91
|
+
} catch ($boundEx) {
|
|
92
|
+
return $error($boundEx);
|
|
93
|
+
}
|
|
94
|
+
}, $error);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function _arrayLikeToArray(r, a) {
|
|
99
|
+
(null == a || a > r.length) && (a = r.length);
|
|
100
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
101
|
+
return n;
|
|
102
|
+
}
|
|
103
|
+
function _arrayWithoutHoles(r) {
|
|
104
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
105
|
+
}
|
|
106
|
+
function _defineProperty(e, r, t) {
|
|
107
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
108
|
+
value: t,
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true
|
|
112
|
+
}) : e[r] = t, e;
|
|
113
|
+
}
|
|
114
|
+
function _iterableToArray(r) {
|
|
115
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
116
|
+
}
|
|
117
|
+
function _nonIterableSpread() {
|
|
118
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
119
|
+
}
|
|
120
|
+
function ownKeys(e, r) {
|
|
121
|
+
var t = Object.keys(e);
|
|
122
|
+
if (Object.getOwnPropertySymbols) {
|
|
123
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
124
|
+
r && (o = o.filter(function (r) {
|
|
125
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
126
|
+
})), t.push.apply(t, o);
|
|
127
|
+
}
|
|
128
|
+
return t;
|
|
129
|
+
}
|
|
130
|
+
function _objectSpread2(e) {
|
|
131
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
132
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
133
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
134
|
+
_defineProperty(e, r, t[r]);
|
|
135
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
136
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return e;
|
|
140
|
+
}
|
|
141
|
+
function _toConsumableArray(r) {
|
|
142
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
143
|
+
}
|
|
144
|
+
function _toPrimitive(t, r) {
|
|
145
|
+
if ("object" != typeof t || !t) return t;
|
|
146
|
+
var e = t[Symbol.toPrimitive];
|
|
147
|
+
if (void 0 !== e) {
|
|
148
|
+
var i = e.call(t, r);
|
|
149
|
+
if ("object" != typeof i) return i;
|
|
150
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
151
|
+
}
|
|
152
|
+
return ("string" === r ? String : Number)(t);
|
|
153
|
+
}
|
|
154
|
+
function _toPropertyKey(t) {
|
|
155
|
+
var i = _toPrimitive(t, "string");
|
|
156
|
+
return "symbol" == typeof i ? i : i + "";
|
|
157
|
+
}
|
|
158
|
+
function _unsupportedIterableToArray(r, a) {
|
|
159
|
+
if (r) {
|
|
160
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
161
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
162
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 获取webpack的resolve配置
|
|
168
|
+
* @param userResolve
|
|
169
|
+
* @returns
|
|
170
|
+
*/
|
|
171
|
+
var updateResolve = function updateResolve(ctx) {
|
|
172
|
+
var tsConfig = ctx.configCtx.getTsConfig();
|
|
173
|
+
var _ctx$geTDoraConfigWeb = ctx.geTDoraConfigWebpack(),
|
|
174
|
+
userConfigResolve = _ctx$geTDoraConfigWeb.resolve;
|
|
175
|
+
var injectAlias = get(userConfigResolve, 'alias', {});
|
|
176
|
+
var injectExtensions = get(userConfigResolve, 'extensions', []);
|
|
177
|
+
var tsAlias = getTsPathAlias(tsConfig);
|
|
178
|
+
var resolveObj = {
|
|
179
|
+
extensions: Array.from(new Set(['.ts', '.tsx', '.js', '.jsx'].concat(_toConsumableArray(injectExtensions)))),
|
|
180
|
+
alias: _objectSpread2(_objectSpread2({
|
|
181
|
+
'@src': resolve('src'),
|
|
182
|
+
'@': resolve('src')
|
|
183
|
+
}, tsAlias), injectAlias)
|
|
184
|
+
};
|
|
185
|
+
ctx.updateWebpackConfig({
|
|
186
|
+
resolve: resolveObj
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
var updateResolveLoader = function updateResolveLoader(ctx) {
|
|
191
|
+
var resolveLoader = getResolveLoader();
|
|
192
|
+
ctx.updateWebpackConfig({
|
|
193
|
+
resolveLoader: resolveLoader
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
var initWebpackConfig = function initWebpackConfig(ctx) {
|
|
198
|
+
return new Promise(function ($return, $error) {
|
|
199
|
+
return Promise.resolve(updateMode(ctx)).then(function ($await_1) {
|
|
200
|
+
try {
|
|
201
|
+
return Promise.resolve(updateEntry(ctx)).then(function ($await_2) {
|
|
202
|
+
try {
|
|
203
|
+
return Promise.resolve(updateOutput(ctx)).then(function ($await_3) {
|
|
204
|
+
try {
|
|
205
|
+
return Promise.resolve(updateDevtool(ctx)).then(function ($await_4) {
|
|
206
|
+
try {
|
|
207
|
+
return Promise.resolve(updateExternals(ctx)).then(function ($await_5) {
|
|
208
|
+
try {
|
|
209
|
+
return Promise.resolve(updateResolve(ctx)).then(function ($await_6) {
|
|
210
|
+
try {
|
|
211
|
+
return Promise.resolve(updateResolveLoader(ctx)).then(function ($await_7) {
|
|
212
|
+
try {
|
|
213
|
+
return Promise.resolve(updateOptimization(ctx)).then(function ($await_8) {
|
|
214
|
+
try {
|
|
215
|
+
return Promise.resolve(updateModule(ctx)).then(function ($await_9) {
|
|
216
|
+
try {
|
|
217
|
+
return Promise.resolve(updatePlugins(ctx)).then(function ($await_10) {
|
|
218
|
+
try {
|
|
219
|
+
return $return();
|
|
220
|
+
} catch ($boundEx) {
|
|
221
|
+
return $error($boundEx);
|
|
222
|
+
}
|
|
223
|
+
}, $error);
|
|
224
|
+
} catch ($boundEx) {
|
|
225
|
+
return $error($boundEx);
|
|
226
|
+
}
|
|
227
|
+
}, $error);
|
|
228
|
+
} catch ($boundEx) {
|
|
229
|
+
return $error($boundEx);
|
|
230
|
+
}
|
|
231
|
+
}, $error);
|
|
232
|
+
} catch ($boundEx) {
|
|
233
|
+
return $error($boundEx);
|
|
234
|
+
}
|
|
235
|
+
}, $error);
|
|
236
|
+
} catch ($boundEx) {
|
|
237
|
+
return $error($boundEx);
|
|
238
|
+
}
|
|
239
|
+
}, $error);
|
|
240
|
+
} catch ($boundEx) {
|
|
241
|
+
return $error($boundEx);
|
|
242
|
+
}
|
|
243
|
+
}, $error);
|
|
244
|
+
} catch ($boundEx) {
|
|
245
|
+
return $error($boundEx);
|
|
246
|
+
}
|
|
247
|
+
}, $error);
|
|
248
|
+
} catch ($boundEx) {
|
|
249
|
+
return $error($boundEx);
|
|
250
|
+
}
|
|
251
|
+
}, $error);
|
|
252
|
+
} catch ($boundEx) {
|
|
253
|
+
return $error($boundEx);
|
|
254
|
+
}
|
|
255
|
+
}, $error);
|
|
256
|
+
} catch ($boundEx) {
|
|
257
|
+
return $error($boundEx);
|
|
258
|
+
}
|
|
259
|
+
}, $error);
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
var buildBase = function buildBase(ctx) {
|
|
264
|
+
return new Promise(function ($return, $error) {
|
|
265
|
+
var timeEnd, res;
|
|
266
|
+
return Promise.resolve(initWebpackConfig(ctx)).then(function ($await_1) {
|
|
267
|
+
try {
|
|
268
|
+
timeEnd = cLog.time('build');
|
|
269
|
+
return Promise.resolve(build(ctx.webpackConfig)).then(function ($await_2) {
|
|
270
|
+
try {
|
|
271
|
+
res = $await_2;
|
|
272
|
+
timeEnd();
|
|
273
|
+
return $return(res);
|
|
274
|
+
} catch ($boundEx) {
|
|
275
|
+
return $error($boundEx);
|
|
276
|
+
}
|
|
277
|
+
}, $error);
|
|
278
|
+
} catch ($boundEx) {
|
|
279
|
+
return $error($boundEx);
|
|
280
|
+
}
|
|
281
|
+
}, $error);
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
var buildSingle = function buildSingle(configCtx, envParams) {
|
|
286
|
+
return new Promise(function ($return, $error) {
|
|
287
|
+
var ctx, res, _ref, err, stats, _stats$compilation;
|
|
288
|
+
ctx = new Ctx(configCtx);
|
|
289
|
+
ctx.updateEnvParams(envParams);
|
|
290
|
+
return Promise.resolve(buildBase(ctx)).then(function ($await_1) {
|
|
291
|
+
try {
|
|
292
|
+
res = $await_1;
|
|
293
|
+
_ref = res || {}, err = _ref.err, stats = _ref.stats;
|
|
294
|
+
if (err) {
|
|
295
|
+
cLog.error('build', 'build_error', 'webpack构建失败,捕获到错误');
|
|
296
|
+
console.error(err);
|
|
297
|
+
return $return();
|
|
298
|
+
}
|
|
299
|
+
if (stats !== null && stats !== void 0 && stats.hasErrors()) {
|
|
300
|
+
cLog.error('build', 'build_error', 'webpack构建失败,捕获到状态错误');
|
|
301
|
+
stats === null || stats === void 0 || (_stats$compilation = stats.compilation) === null || _stats$compilation === void 0 || (_stats$compilation = _stats$compilation.errors) === null || _stats$compilation === void 0 || _stats$compilation.forEach(function (error) {
|
|
302
|
+
console.error(error);
|
|
303
|
+
});
|
|
304
|
+
return $return();
|
|
305
|
+
}
|
|
306
|
+
cLog.info('build', 'build_success', 'webpack构建成功');
|
|
307
|
+
return $return();
|
|
308
|
+
} catch ($boundEx) {
|
|
309
|
+
return $error($boundEx);
|
|
310
|
+
}
|
|
311
|
+
}, $error);
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
var version = "0.0.0";
|
|
316
|
+
|
|
317
|
+
/** 生产预设配置 */
|
|
318
|
+
var presetDoracliDefaultConfig = {
|
|
319
|
+
output: {
|
|
320
|
+
path: './dist'
|
|
321
|
+
},
|
|
322
|
+
formatList: ['cjs'],
|
|
323
|
+
alias: {},
|
|
324
|
+
externals: [],
|
|
325
|
+
internals: [],
|
|
326
|
+
minimize: true,
|
|
327
|
+
clear: false,
|
|
328
|
+
copy: {},
|
|
329
|
+
dts: {}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/** 生产预设配置 */
|
|
333
|
+
var presetDoracliBuildConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
334
|
+
minimize: true,
|
|
335
|
+
clear: true
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
var buildEntry = function buildEntry(cmd) {
|
|
339
|
+
return new Promise(function ($return, $error) {
|
|
340
|
+
var envParams, configCtx;
|
|
341
|
+
envParams = {
|
|
342
|
+
action: 'build',
|
|
343
|
+
workRootDir: process.cwd()
|
|
344
|
+
};
|
|
345
|
+
configCtx = new ConfigCtx();
|
|
346
|
+
configCtx.setCmd(cmd);
|
|
347
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
348
|
+
return Promise.resolve(collectConfig(configCtx, ActionMap[envParams.action], {
|
|
349
|
+
doraConfig: presetDoracliBuildConfig
|
|
350
|
+
})).then(function ($await_1) {
|
|
351
|
+
try {
|
|
352
|
+
return $return(buildSingle(configCtx, envParams));
|
|
353
|
+
} catch ($boundEx) {
|
|
354
|
+
return $error($boundEx);
|
|
355
|
+
}
|
|
356
|
+
}, $error);
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
/** 生产预设配置 */
|
|
361
|
+
var presetDoracliDevConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
362
|
+
clear: true,
|
|
363
|
+
minimize: false
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
var devEntry = function devEntry(cmd) {
|
|
367
|
+
return new Promise(function ($return, $error) {
|
|
368
|
+
var envParams, configCtx;
|
|
369
|
+
envParams = {
|
|
370
|
+
action: 'build',
|
|
371
|
+
workRootDir: process.cwd()
|
|
372
|
+
};
|
|
373
|
+
configCtx = new ConfigCtx();
|
|
374
|
+
configCtx.setCmd(cmd);
|
|
375
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
376
|
+
return Promise.resolve(collectConfig(configCtx, ActionMap[envParams.action], {
|
|
377
|
+
doraConfig: presetDoracliDevConfig
|
|
378
|
+
})).then(function ($await_1) {
|
|
379
|
+
try {
|
|
380
|
+
return $return(buildSingle(configCtx, envParams));
|
|
381
|
+
} catch ($boundEx) {
|
|
382
|
+
return $error($boundEx);
|
|
383
|
+
}
|
|
384
|
+
}, $error);
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/** 生产预设配置 */
|
|
389
|
+
var presetDoracliServerConfig = _objectSpread2(_objectSpread2({}, presetDoracliDefaultConfig), {}, {
|
|
390
|
+
clear: false,
|
|
391
|
+
minimize: false,
|
|
392
|
+
webpackConfig: {
|
|
393
|
+
serviceConfig: {
|
|
394
|
+
open: true
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
var updateDevServer = function updateDevServer(ctx) {
|
|
400
|
+
var userServiceConfig = ctx.geTDoraConfigWebpack().serviceConfig || {};
|
|
401
|
+
ctx.updateDevServerConfig(getDevServer(userServiceConfig));
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
var serverBase = function serverBase(ctx) {
|
|
405
|
+
return new Promise(function ($return, $error) {
|
|
406
|
+
var compiler;
|
|
407
|
+
return Promise.resolve(initWebpackConfig(ctx)).then(function ($await_1) {
|
|
408
|
+
try {
|
|
409
|
+
return Promise.resolve(updateDevServer(ctx)).then(function ($await_2) {
|
|
410
|
+
try {
|
|
411
|
+
compiler = createCompiler(ctx.webpackConfig);
|
|
412
|
+
return Promise.resolve(service(ctx.devServerConfig, compiler)).then(function ($await_3) {
|
|
413
|
+
try {
|
|
414
|
+
return $return();
|
|
415
|
+
} catch ($boundEx) {
|
|
416
|
+
return $error($boundEx);
|
|
417
|
+
}
|
|
418
|
+
}, $error);
|
|
419
|
+
} catch ($boundEx) {
|
|
420
|
+
return $error($boundEx);
|
|
421
|
+
}
|
|
422
|
+
}, $error);
|
|
423
|
+
} catch ($boundEx) {
|
|
424
|
+
return $error($boundEx);
|
|
425
|
+
}
|
|
426
|
+
}, $error);
|
|
427
|
+
});
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
var serverSingle = function serverSingle(configCtx, envParams) {
|
|
431
|
+
return new Promise(function ($return, $error) {
|
|
432
|
+
var ctx;
|
|
433
|
+
ctx = new Ctx(configCtx);
|
|
434
|
+
ctx.updateEnvParams(envParams);
|
|
435
|
+
return Promise.resolve(serverBase(ctx)).then(function ($await_1) {
|
|
436
|
+
try {
|
|
437
|
+
cLog.info('server', 'success', 'webpack 服务启动成功~');
|
|
438
|
+
return $return();
|
|
439
|
+
} catch ($boundEx) {
|
|
440
|
+
return $error($boundEx);
|
|
441
|
+
}
|
|
442
|
+
}, $error);
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
var serverEntry = function serverEntry(cmd) {
|
|
447
|
+
return new Promise(function ($return, $error) {
|
|
448
|
+
var envParams, configCtx, cdnConfig;
|
|
449
|
+
envParams = {
|
|
450
|
+
action: 'server',
|
|
451
|
+
workRootDir: process.cwd()
|
|
452
|
+
};
|
|
453
|
+
configCtx = new ConfigCtx();
|
|
454
|
+
configCtx.setCmd(cmd);
|
|
455
|
+
configCtx.setWorkRoot(envParams.workRootDir);
|
|
456
|
+
return Promise.resolve(collectConfig(configCtx, ActionMap[envParams.action], {
|
|
457
|
+
doraConfig: presetDoracliServerConfig
|
|
458
|
+
})).then(function ($await_1) {
|
|
459
|
+
try {
|
|
460
|
+
return Promise.resolve(resolveCdnConfig(envParams.workRootDir, ActionMap[envParams.action])).then(function ($await_2) {
|
|
461
|
+
try {
|
|
462
|
+
cdnConfig = $await_2 || {};
|
|
463
|
+
configCtx.setCdnConfig(cdnConfig);
|
|
464
|
+
return $return(serverSingle(configCtx, envParams));
|
|
465
|
+
} catch ($boundEx) {
|
|
466
|
+
return $error($boundEx);
|
|
467
|
+
}
|
|
468
|
+
}, $error);
|
|
469
|
+
} catch ($boundEx) {
|
|
470
|
+
return $error($boundEx);
|
|
471
|
+
}
|
|
472
|
+
}, $error);
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
var childCommands = [{
|
|
477
|
+
command: 'server',
|
|
478
|
+
description: 'run a project by dev',
|
|
479
|
+
options: [{
|
|
480
|
+
name: 'format',
|
|
481
|
+
simpleName: 'f',
|
|
482
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
483
|
+
description: 'set output module type'
|
|
484
|
+
}, {
|
|
485
|
+
name: 'workRootDir',
|
|
486
|
+
simpleName: 'r',
|
|
487
|
+
type: '[string]',
|
|
488
|
+
description: 'set work root path',
|
|
489
|
+
defaultValue: './'
|
|
490
|
+
}],
|
|
491
|
+
action: function action(env) {
|
|
492
|
+
serverEntry(env);
|
|
493
|
+
}
|
|
494
|
+
}, {
|
|
495
|
+
command: 'build',
|
|
496
|
+
description: 'run a project by build',
|
|
497
|
+
options: [{
|
|
498
|
+
name: 'format',
|
|
499
|
+
simpleName: 'f',
|
|
500
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
501
|
+
description: 'set output module type'
|
|
502
|
+
}, {
|
|
503
|
+
name: 'workRootDir',
|
|
504
|
+
simpleName: 'r',
|
|
505
|
+
type: '[string]',
|
|
506
|
+
description: 'set work root path',
|
|
507
|
+
defaultValue: './'
|
|
508
|
+
}],
|
|
509
|
+
action: function action(env) {
|
|
510
|
+
buildEntry(env);
|
|
511
|
+
}
|
|
512
|
+
}, {
|
|
513
|
+
command: 'dev',
|
|
514
|
+
description: 'run a project by build',
|
|
515
|
+
options: [{
|
|
516
|
+
name: 'format',
|
|
517
|
+
simpleName: 'f',
|
|
518
|
+
type: "['amd','cjs','es','iife','system','umd','commonjs','esm','module','systemjs']",
|
|
519
|
+
description: 'set output module type'
|
|
520
|
+
}, {
|
|
521
|
+
name: 'workRootDir',
|
|
522
|
+
simpleName: 'r',
|
|
523
|
+
type: '[string]',
|
|
524
|
+
description: 'set work root path',
|
|
525
|
+
defaultValue: './'
|
|
526
|
+
}],
|
|
527
|
+
action: function action(env) {
|
|
528
|
+
devEntry(env);
|
|
529
|
+
}
|
|
530
|
+
}];
|
|
531
|
+
var commandOptions = {
|
|
532
|
+
name: 'magic',
|
|
533
|
+
usage: 'magic <command> [option]',
|
|
534
|
+
version: version,
|
|
535
|
+
childCommands: childCommands
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
export { buildBase, buildSingle, childCommands, commandOptions, serverBase, serverSingle };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Stats } from 'webpack';
|
|
2
|
+
import { Ctx, TEnvParams } from '@doracli/webpack';
|
|
3
|
+
import { ConfigCtx } from '@doracli/helper';
|
|
4
|
+
import { TChildCommandOption, TCommandOption } from '@doracli/commander';
|
|
5
|
+
|
|
6
|
+
declare const buildBase: (ctx: Ctx) => Promise<{
|
|
7
|
+
err?: Error | null | undefined;
|
|
8
|
+
stats?: Stats | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
declare const buildSingle: (configCtx: ConfigCtx, envParams: TEnvParams) => Promise<void>;
|
|
12
|
+
|
|
13
|
+
declare const childCommands: TChildCommandOption[];
|
|
14
|
+
declare const commandOptions: TCommandOption;
|
|
15
|
+
|
|
16
|
+
declare const serverBase: (ctx: Ctx) => Promise<void>;
|
|
17
|
+
|
|
18
|
+
declare const serverSingle: (configCtx: ConfigCtx, envParams: TEnvParams) => Promise<void>;
|
|
19
|
+
|
|
20
|
+
export { buildBase, buildSingle, childCommands, commandOptions, serverBase, serverSingle };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@doracli/webpack-react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "package by webpack",
|
|
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
|
+
"dwr": "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/helper": "^0.0.1",
|
|
39
|
+
"@doracli/type": "^0.0.1",
|
|
40
|
+
"@doracli/webpack": "^0.0.1"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "40ab496f25042487a671979074515f3345c96453",
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"webpack": "^5.102.1",
|
|
45
|
+
"webpack-dev-server": "^5.2.2"
|
|
46
|
+
}
|
|
47
|
+
}
|