@rslib/core 0.0.11 → 0.0.13
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/dist/index.js +255 -143
- package/dist-types/config.d.ts +2 -2
- package/dist-types/plugins/shims.d.ts +3 -0
- package/dist-types/types/config/index.d.ts +14 -1
- package/dist-types/types/utils.d.ts +1 -0
- package/dist-types/utils/helper.d.ts +4 -2
- package/package.json +5 -5
- package/dist-types/plugins/cjsShim.d.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -112,12 +112,28 @@ function pick(obj, keys) {
|
|
|
112
112
|
return ret;
|
|
113
113
|
}, {});
|
|
114
114
|
}
|
|
115
|
-
function omit(obj,
|
|
115
|
+
function omit(obj, keysObj) {
|
|
116
116
|
return Object.keys(obj).reduce((ret, key)=>{
|
|
117
|
-
if (
|
|
117
|
+
if (true !== keysObj[key]) ret[key] = obj[key];
|
|
118
118
|
return ret;
|
|
119
119
|
}, {});
|
|
120
120
|
}
|
|
121
|
+
function isPluginIncluded(config, pluginName) {
|
|
122
|
+
return Boolean(config.plugins?.some((plugin)=>{
|
|
123
|
+
if ('object' == typeof plugin && null !== plugin && 'name' in plugin) return plugin.name === pluginName;
|
|
124
|
+
return false;
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
function checkMFPlugin(config) {
|
|
128
|
+
if ('mf' !== config.format) return true;
|
|
129
|
+
// https://github.com/module-federation/core/blob/4e5c4b96ee45899f3ba5904b8927768980d5ad0e/packages/rsbuild-plugin/src/cli/index.ts#L17
|
|
130
|
+
const added = isPluginIncluded(config, 'rsbuild:module-federation-enhanced');
|
|
131
|
+
if (!added) {
|
|
132
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green('format: "mf"')} should be used with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('@module-federation/rsbuild-plugin')}", consider installing and adding it to plugins. Check the documentation (https://module-federation.io/guide/basic/rsbuild.html#rslib-module) to get started with "mf" output.`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
return added;
|
|
136
|
+
}
|
|
121
137
|
// setup the logger level
|
|
122
138
|
if (process.env.DEBUG) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.level = 'verbose';
|
|
123
139
|
function initNodeEnv() {
|
|
@@ -134,7 +150,7 @@ function prepareCli() {
|
|
|
134
150
|
// Some package managers automatically output a blank line, some do not.
|
|
135
151
|
const { npm_execpath } = process.env;
|
|
136
152
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
137
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.
|
|
153
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.13\n`);
|
|
138
154
|
}
|
|
139
155
|
const DEFAULT_CONFIG_NAME = 'rslib.config';
|
|
140
156
|
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
@@ -173,17 +189,17 @@ const ENTRY_EXTENSIONS = [
|
|
|
173
189
|
const JS_EXTENSIONS_PATTERN = new RegExp(`\\.(${JS_EXTENSIONS.join('|')})$`);
|
|
174
190
|
const CSS_EXTENSIONS_PATTERN = new RegExp(`\\.(${CSS_EXTENSIONS.join('|')})$`);
|
|
175
191
|
const ENTRY_EXTENSIONS_PATTERN = new RegExp(`\\.(${ENTRY_EXTENSIONS.join('|')})$`);
|
|
176
|
-
const
|
|
192
|
+
const RemoveCssExtractAssetPlugin_pluginName = 'REMOVE_CSS_EXTRACT_ASSET_PLUGIN';
|
|
177
193
|
class RemoveCssExtractAssetPlugin {
|
|
178
|
-
name =
|
|
194
|
+
name = RemoveCssExtractAssetPlugin_pluginName;
|
|
179
195
|
options;
|
|
180
196
|
constructor(options){
|
|
181
197
|
this.options = options;
|
|
182
198
|
}
|
|
183
199
|
apply(compiler) {
|
|
184
200
|
const include = this.options.include;
|
|
185
|
-
compiler.hooks.thisCompilation.tap(
|
|
186
|
-
compilation.hooks.chunkAsset.tap(
|
|
201
|
+
compiler.hooks.thisCompilation.tap(RemoveCssExtractAssetPlugin_pluginName, (compilation)=>{
|
|
202
|
+
compilation.hooks.chunkAsset.tap(RemoveCssExtractAssetPlugin_pluginName, (_chunk, filename)=>{
|
|
187
203
|
const asset = compilation.getAsset(filename);
|
|
188
204
|
if (!asset) return;
|
|
189
205
|
const needRemove = Boolean(asset.name.match(include));
|
|
@@ -291,7 +307,7 @@ const composeCssConfig = (rootDir, bundle = true)=>{
|
|
|
291
307
|
};
|
|
292
308
|
const importMetaUrlShim = `/*#__PURE__*/ (function () {
|
|
293
309
|
return typeof document === 'undefined'
|
|
294
|
-
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
310
|
+
? new (module.require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
295
311
|
: (document.currentScript && document.currentScript.src) ||
|
|
296
312
|
new URL('main.js', document.baseURI).href;
|
|
297
313
|
})()`;
|
|
@@ -299,8 +315,8 @@ const importMetaUrlShim = `/*#__PURE__*/ (function () {
|
|
|
299
315
|
// - Replace `import.meta.url` with `importMetaUrl`.
|
|
300
316
|
// - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
|
|
301
317
|
// This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
|
|
302
|
-
const
|
|
303
|
-
name: 'rsbuild-
|
|
318
|
+
const pluginCjsImportMetaUrlShim = ()=>({
|
|
319
|
+
name: 'rsbuild:cjs-import-meta-url-shim',
|
|
304
320
|
setup (api) {
|
|
305
321
|
api.modifyEnvironmentConfig((config)=>{
|
|
306
322
|
config.source.define = {
|
|
@@ -310,6 +326,25 @@ const pluginCjsShim = ()=>({
|
|
|
310
326
|
});
|
|
311
327
|
}
|
|
312
328
|
});
|
|
329
|
+
const requireShim = `// Rslib ESM shims
|
|
330
|
+
import __rslib_shim_module__ from 'module';
|
|
331
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
332
|
+
`;
|
|
333
|
+
const pluginEsmRequireShim = ()=>({
|
|
334
|
+
name: 'rsbuild:esm-require-shim',
|
|
335
|
+
setup (api) {
|
|
336
|
+
api.modifyRspackConfig((config)=>{
|
|
337
|
+
config.plugins ??= [];
|
|
338
|
+
config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
339
|
+
banner: requireShim,
|
|
340
|
+
// Just before minify stage, to perform tree shaking.
|
|
341
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
|
|
342
|
+
raw: true,
|
|
343
|
+
include: /\.(js|cjs)$/
|
|
344
|
+
}));
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
});
|
|
313
348
|
const getDefaultExtension = (options)=>{
|
|
314
349
|
const { format, pkgJson, autoExtension } = options;
|
|
315
350
|
let jsExtension = '.js';
|
|
@@ -376,115 +411,104 @@ const RSPACK_TARGET_UNLISTED_MODERN_ECMA_VERSIONS = [
|
|
|
376
411
|
* https://github.com/rspack-contrib/browserslist-to-es-version
|
|
377
412
|
* TODO: align with Rsbuild, we may should align with SWC
|
|
378
413
|
*/ const ESX_TO_BROWSERSLIST = {
|
|
414
|
+
es5: {
|
|
415
|
+
chrome: '5.0.0',
|
|
416
|
+
edge: '12.0.0',
|
|
417
|
+
firefox: '2.0.0',
|
|
418
|
+
ie: '9.0.0',
|
|
419
|
+
ios: '6.0.0',
|
|
420
|
+
node: '0.4.0',
|
|
421
|
+
opera: '10.10.0',
|
|
422
|
+
safari: '3.1.0'
|
|
423
|
+
},
|
|
379
424
|
es6: {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
],
|
|
388
|
-
Opera: '50.0.0',
|
|
389
|
-
Safari: '13.0.0'
|
|
425
|
+
chrome: '63.0.0',
|
|
426
|
+
edge: '79.0.0',
|
|
427
|
+
firefox: '67.0.0',
|
|
428
|
+
ios: '13.0.0',
|
|
429
|
+
node: '13.2.0',
|
|
430
|
+
opera: '50.0.0',
|
|
431
|
+
safari: '13.0.0'
|
|
390
432
|
},
|
|
391
433
|
es2015: {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
434
|
+
chrome: '63.0.0',
|
|
435
|
+
edge: '79.0.0',
|
|
436
|
+
firefox: '67.0.0',
|
|
437
|
+
ios: '13.0.0',
|
|
438
|
+
node: '13.2.0',
|
|
439
|
+
opera: '50.0.0',
|
|
440
|
+
safari: '13.0.0'
|
|
399
441
|
},
|
|
400
442
|
es2016: {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
443
|
+
chrome: '63.0.0',
|
|
444
|
+
edge: '79.0.0',
|
|
445
|
+
firefox: '67.0.0',
|
|
446
|
+
ios: '13.0.0',
|
|
447
|
+
node: '13.2.0',
|
|
448
|
+
opera: '50.0.0',
|
|
449
|
+
safari: '13.0.0'
|
|
408
450
|
},
|
|
409
451
|
es2017: {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
452
|
+
chrome: '63.0.0',
|
|
453
|
+
edge: '79.0.0',
|
|
454
|
+
firefox: '67.0.0',
|
|
455
|
+
ios: '13.0.0',
|
|
456
|
+
node: '13.2.0',
|
|
457
|
+
opera: '50.0.0',
|
|
458
|
+
safari: '13.0.0'
|
|
417
459
|
},
|
|
418
460
|
es2018: {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
'node > 21.3.0'
|
|
427
|
-
],
|
|
428
|
-
Opera: '51.0.0',
|
|
429
|
-
Safari: '16.4.0'
|
|
461
|
+
chrome: '64.0.0',
|
|
462
|
+
edge: '79.0.0',
|
|
463
|
+
firefox: '78.0.0',
|
|
464
|
+
ios: '16.4.0',
|
|
465
|
+
node: '13.2.0',
|
|
466
|
+
opera: '51.0.0',
|
|
467
|
+
safari: '16.4.0'
|
|
430
468
|
},
|
|
431
469
|
es2019: {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
470
|
+
chrome: '66.0.0',
|
|
471
|
+
edge: '79.0.0',
|
|
472
|
+
firefox: '78.0.0',
|
|
473
|
+
ios: '16.4.0',
|
|
474
|
+
node: '13.2.0',
|
|
475
|
+
opera: '53.0.0',
|
|
476
|
+
safari: '16.4.0'
|
|
439
477
|
},
|
|
440
478
|
es2020: {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
479
|
+
chrome: '91.0.0',
|
|
480
|
+
edge: '91.0.0',
|
|
481
|
+
firefox: '80.0.0',
|
|
482
|
+
ios: '16.4.0',
|
|
483
|
+
node: '16.1.0',
|
|
484
|
+
opera: '77.0.0',
|
|
485
|
+
safari: '16.4.0'
|
|
448
486
|
},
|
|
449
487
|
es2021: {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
488
|
+
chrome: '91.0.0',
|
|
489
|
+
edge: '91.0.0',
|
|
490
|
+
firefox: '80.0.0',
|
|
491
|
+
ios: '16.4.0',
|
|
492
|
+
node: '16.1.0',
|
|
493
|
+
opera: '77.0.0',
|
|
494
|
+
safari: '16.4.0'
|
|
457
495
|
},
|
|
458
496
|
es2022: {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
Opera: '80.0.0',
|
|
465
|
-
Safari: '16.4.0'
|
|
497
|
+
chrome: '91.0.0',
|
|
498
|
+
firefox: '93.0.0',
|
|
499
|
+
ios: '16.4.0',
|
|
500
|
+
node: '16.11.0',
|
|
501
|
+
safari: '16.4.0'
|
|
466
502
|
},
|
|
467
503
|
es2023: {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
Opera: '62.0.0',
|
|
474
|
-
Safari: '13.1.0'
|
|
504
|
+
chrome: '91.0.0',
|
|
505
|
+
firefox: '93.0.0',
|
|
506
|
+
ios: '16.4.0',
|
|
507
|
+
node: '16.11.0',
|
|
508
|
+
safari: '16.4.0'
|
|
475
509
|
},
|
|
476
510
|
es2024: calcEsnextBrowserslistByTarget,
|
|
477
|
-
esnext: calcEsnextBrowserslistByTarget
|
|
478
|
-
es5: {
|
|
479
|
-
Chrome: '5.0.0',
|
|
480
|
-
Edge: '12.0.0',
|
|
481
|
-
Firefox: '2.0.0',
|
|
482
|
-
ie: '9.0.0',
|
|
483
|
-
iOS: '6.0.0',
|
|
484
|
-
Node: '0.4.0',
|
|
485
|
-
Opera: '10.10.0',
|
|
486
|
-
Safari: '3.1.0'
|
|
487
|
-
}
|
|
511
|
+
esnext: calcEsnextBrowserslistByTarget
|
|
488
512
|
};
|
|
489
513
|
function transformSyntaxToRspackTarget(syntax) {
|
|
490
514
|
const handleSyntaxItem = (syntaxItem)=>{
|
|
@@ -1391,7 +1415,9 @@ const composeAutoExternalConfig = (options)=>{
|
|
|
1391
1415
|
}
|
|
1392
1416
|
} : {};
|
|
1393
1417
|
};
|
|
1394
|
-
function composeMinifyConfig(
|
|
1418
|
+
function composeMinifyConfig(config) {
|
|
1419
|
+
const minify = config.output?.minify;
|
|
1420
|
+
const format = config.format;
|
|
1395
1421
|
if (void 0 !== minify) // User's minify configuration will be merged afterwards.
|
|
1396
1422
|
return {};
|
|
1397
1423
|
// When minify is not specified, Rslib will use a sane default for minify options.
|
|
@@ -1409,7 +1435,8 @@ function composeMinifyConfig(minify) {
|
|
|
1409
1435
|
defaults: false,
|
|
1410
1436
|
unused: true,
|
|
1411
1437
|
dead_code: true,
|
|
1412
|
-
toplevel
|
|
1438
|
+
// remoteEntry's global variable will be tree-shaken if `toplevel` is enabled in "mf" format
|
|
1439
|
+
toplevel: 'mf' !== format
|
|
1413
1440
|
},
|
|
1414
1441
|
format: {
|
|
1415
1442
|
comments: 'all'
|
|
@@ -1533,13 +1560,17 @@ async function createConstantRsbuildConfig() {
|
|
|
1533
1560
|
}
|
|
1534
1561
|
});
|
|
1535
1562
|
}
|
|
1536
|
-
const composeFormatConfig = (format)=>{
|
|
1563
|
+
const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson })=>{
|
|
1537
1564
|
const jsParserOptions = {
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1565
|
+
cjs: {
|
|
1566
|
+
requireResolve: false,
|
|
1567
|
+
requireDynamic: false,
|
|
1568
|
+
requireAsExpression: false
|
|
1569
|
+
},
|
|
1570
|
+
esm: {
|
|
1571
|
+
importMeta: false,
|
|
1572
|
+
importDynamic: false
|
|
1573
|
+
}
|
|
1543
1574
|
};
|
|
1544
1575
|
switch(format){
|
|
1545
1576
|
case 'esm':
|
|
@@ -1548,7 +1579,10 @@ const composeFormatConfig = (format)=>{
|
|
|
1548
1579
|
rspack: {
|
|
1549
1580
|
module: {
|
|
1550
1581
|
parser: {
|
|
1551
|
-
javascript:
|
|
1582
|
+
javascript: {
|
|
1583
|
+
...jsParserOptions.esm,
|
|
1584
|
+
...jsParserOptions.cjs
|
|
1585
|
+
}
|
|
1552
1586
|
}
|
|
1553
1587
|
},
|
|
1554
1588
|
optimization: {
|
|
@@ -1573,14 +1607,14 @@ const composeFormatConfig = (format)=>{
|
|
|
1573
1607
|
};
|
|
1574
1608
|
case 'cjs':
|
|
1575
1609
|
return {
|
|
1576
|
-
plugins: [
|
|
1577
|
-
pluginCjsShim()
|
|
1578
|
-
],
|
|
1579
1610
|
tools: {
|
|
1580
1611
|
rspack: {
|
|
1581
1612
|
module: {
|
|
1582
1613
|
parser: {
|
|
1583
|
-
javascript:
|
|
1614
|
+
javascript: {
|
|
1615
|
+
...jsParserOptions.esm,
|
|
1616
|
+
...jsParserOptions.cjs
|
|
1617
|
+
}
|
|
1584
1618
|
}
|
|
1585
1619
|
},
|
|
1586
1620
|
output: {
|
|
@@ -1597,20 +1631,45 @@ const composeFormatConfig = (format)=>{
|
|
|
1597
1631
|
}
|
|
1598
1632
|
};
|
|
1599
1633
|
case 'umd':
|
|
1634
|
+
{
|
|
1635
|
+
if (false === bundle) throw new Error('When using "umd" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.');
|
|
1636
|
+
const config = {
|
|
1637
|
+
tools: {
|
|
1638
|
+
rspack: {
|
|
1639
|
+
module: {
|
|
1640
|
+
parser: {
|
|
1641
|
+
javascript: {
|
|
1642
|
+
importMeta: false
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
},
|
|
1646
|
+
output: {
|
|
1647
|
+
asyncChunks: false,
|
|
1648
|
+
library: umdName ? {
|
|
1649
|
+
type: 'umd',
|
|
1650
|
+
name: umdName
|
|
1651
|
+
} : {
|
|
1652
|
+
type: 'umd'
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
return config;
|
|
1659
|
+
}
|
|
1660
|
+
case 'mf':
|
|
1600
1661
|
return {
|
|
1601
1662
|
tools: {
|
|
1602
1663
|
rspack: {
|
|
1603
|
-
module: {
|
|
1604
|
-
parser: {
|
|
1605
|
-
javascript: {
|
|
1606
|
-
importMeta: false
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
},
|
|
1610
1664
|
output: {
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1665
|
+
uniqueName: pkgJson.name
|
|
1666
|
+
},
|
|
1667
|
+
// TODO when we provide dev mode for rslib mf format, this should be modified to as the same with config.mode
|
|
1668
|
+
// can not set nodeEnv to false, because mf format should build shared module.
|
|
1669
|
+
// If nodeEnv is false, the process.env.NODE_ENV in third-party packages's will not be replaced
|
|
1670
|
+
// now we have not provide dev mode for users, so we can always set nodeEnv as 'production'
|
|
1671
|
+
optimization: {
|
|
1672
|
+
nodeEnv: 'production'
|
|
1614
1673
|
}
|
|
1615
1674
|
}
|
|
1616
1675
|
}
|
|
@@ -1619,6 +1678,47 @@ const composeFormatConfig = (format)=>{
|
|
|
1619
1678
|
throw new Error(`Unsupported format: ${format}`);
|
|
1620
1679
|
}
|
|
1621
1680
|
};
|
|
1681
|
+
const composeShimsConfig = (format, shims)=>{
|
|
1682
|
+
const resolvedShims = {
|
|
1683
|
+
cjs: {
|
|
1684
|
+
'import.meta.url': shims?.cjs?.['import.meta.url'] ?? true
|
|
1685
|
+
},
|
|
1686
|
+
esm: {
|
|
1687
|
+
__filename: shims?.esm?.__filename ?? false,
|
|
1688
|
+
__dirname: shims?.esm?.__dirname ?? false,
|
|
1689
|
+
require: shims?.esm?.require ?? false
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
switch(format){
|
|
1693
|
+
case 'esm':
|
|
1694
|
+
return {
|
|
1695
|
+
tools: {
|
|
1696
|
+
rspack: {
|
|
1697
|
+
node: {
|
|
1698
|
+
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`
|
|
1699
|
+
__dirname: !!resolvedShims.esm.__dirname && 'node-module',
|
|
1700
|
+
__filename: !!resolvedShims.esm.__filename && 'node-module'
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
},
|
|
1704
|
+
plugins: [
|
|
1705
|
+
resolvedShims.esm.require && pluginEsmRequireShim()
|
|
1706
|
+
].filter(Boolean)
|
|
1707
|
+
};
|
|
1708
|
+
case 'cjs':
|
|
1709
|
+
return {
|
|
1710
|
+
plugins: [
|
|
1711
|
+
resolvedShims.cjs['import.meta.url'] && pluginCjsImportMetaUrlShim()
|
|
1712
|
+
].filter(Boolean)
|
|
1713
|
+
};
|
|
1714
|
+
case 'umd':
|
|
1715
|
+
return {};
|
|
1716
|
+
case 'mf':
|
|
1717
|
+
return {};
|
|
1718
|
+
default:
|
|
1719
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1622
1722
|
const composeModuleImportWarn = (request)=>`The externalized commonjs request ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green(`"${request}"`)} will use ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"module"')} external type in ESM format. If you want to specify other external type, considering set the request and type with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"output.externals"')}.`;
|
|
1623
1723
|
const composeExternalsConfig = (format, externals)=>{
|
|
1624
1724
|
// TODO: Define the internal externals config in Rsbuild's externals instead
|
|
@@ -1627,12 +1727,14 @@ const composeExternalsConfig = (format, externals)=>{
|
|
|
1627
1727
|
const externalsTypeMap = {
|
|
1628
1728
|
esm: 'module-import',
|
|
1629
1729
|
cjs: 'commonjs',
|
|
1630
|
-
umd: 'umd'
|
|
1730
|
+
umd: 'umd',
|
|
1731
|
+
mf: 'var'
|
|
1631
1732
|
};
|
|
1632
1733
|
switch(format){
|
|
1633
1734
|
case 'esm':
|
|
1634
1735
|
case 'cjs':
|
|
1635
1736
|
case 'umd':
|
|
1737
|
+
case 'mf':
|
|
1636
1738
|
return {
|
|
1637
1739
|
output: externals ? {
|
|
1638
1740
|
externals
|
|
@@ -1755,7 +1857,7 @@ const composeEntryConfig = async (entries, bundle, root, cssModulesAuto)=>{
|
|
|
1755
1857
|
lcp
|
|
1756
1858
|
};
|
|
1757
1859
|
};
|
|
1758
|
-
const composeBundleConfig = (jsExtension, redirect, cssModulesAuto, bundle
|
|
1860
|
+
const composeBundleConfig = (jsExtension, redirect, cssModulesAuto, bundle)=>{
|
|
1759
1861
|
if (bundle) return {};
|
|
1760
1862
|
const isStyleRedirect = redirect.style ?? true;
|
|
1761
1863
|
return {
|
|
@@ -1879,16 +1981,23 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
1879
1981
|
return defaultConfig;
|
|
1880
1982
|
};
|
|
1881
1983
|
async function composeLibRsbuildConfig(config, configPath) {
|
|
1984
|
+
checkMFPlugin(config);
|
|
1882
1985
|
const rootPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath);
|
|
1883
1986
|
const pkgJson = readPackageJson(rootPath);
|
|
1884
1987
|
const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
|
|
1885
1988
|
const cssModulesAuto = config.output?.cssModules?.auto ?? true;
|
|
1886
|
-
const { format, banner = {}, footer = {}, autoExtension = true, autoExternal = true, externalHelpers = false, redirect = {} } = config;
|
|
1887
|
-
const
|
|
1989
|
+
const { format, shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal = true, externalHelpers = false, redirect = {}, umdName } = config;
|
|
1990
|
+
const shimsConfig = composeShimsConfig(format, shims);
|
|
1991
|
+
const formatConfig = composeFormatConfig({
|
|
1992
|
+
format: format,
|
|
1993
|
+
pkgJson: pkgJson,
|
|
1994
|
+
bundle,
|
|
1995
|
+
umdName
|
|
1996
|
+
});
|
|
1888
1997
|
const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
|
|
1889
1998
|
const externalsConfig = composeExternalsConfig(format, config.output?.externals);
|
|
1890
1999
|
const { config: autoExtensionConfig, jsExtension, dtsExtension } = composeAutoExtensionConfig(config, autoExtension, pkgJson);
|
|
1891
|
-
const bundleConfig = composeBundleConfig(jsExtension, redirect, cssModulesAuto,
|
|
2000
|
+
const bundleConfig = composeBundleConfig(jsExtension, redirect, cssModulesAuto, bundle);
|
|
1892
2001
|
const targetConfig = composeTargetConfig(config.output?.target);
|
|
1893
2002
|
const syntaxConfig = composeSyntaxConfig(config?.syntax, config.output?.target);
|
|
1894
2003
|
const autoExternalConfig = composeAutoExternalConfig({
|
|
@@ -1900,10 +2009,10 @@ async function composeLibRsbuildConfig(config, configPath) {
|
|
|
1900
2009
|
const cssConfig = composeCssConfig(lcp, config.bundle);
|
|
1901
2010
|
const dtsConfig = await composeDtsConfig(config, dtsExtension);
|
|
1902
2011
|
const externalsWarnConfig = composeExternalsWarnConfig(format, autoExternalConfig?.output?.externals, externalsConfig?.output?.externals);
|
|
1903
|
-
const minifyConfig = composeMinifyConfig(config
|
|
2012
|
+
const minifyConfig = composeMinifyConfig(config);
|
|
1904
2013
|
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
|
|
1905
2014
|
const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
|
|
1906
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, cssConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
|
|
2015
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, shimsConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, cssConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
|
|
1907
2016
|
}
|
|
1908
2017
|
async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
1909
2018
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
@@ -1933,18 +2042,20 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
|
1933
2042
|
// We should state in the document that the built-in configuration should not be changed optionally
|
|
1934
2043
|
// In compose process of 2, we may read some config from 1, and reassemble the related config,
|
|
1935
2044
|
// so before final mergeRsbuildConfig, we reset some specified fields
|
|
1936
|
-
config: (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(constantRsbuildConfig, libRsbuildConfig, omit(userConfig,
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2045
|
+
config: (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(constantRsbuildConfig, libRsbuildConfig, omit(userConfig, {
|
|
2046
|
+
bundle: true,
|
|
2047
|
+
format: true,
|
|
2048
|
+
autoExtension: true,
|
|
2049
|
+
autoExternal: true,
|
|
2050
|
+
redirect: true,
|
|
2051
|
+
syntax: true,
|
|
2052
|
+
externalHelpers: true,
|
|
2053
|
+
banner: true,
|
|
2054
|
+
footer: true,
|
|
2055
|
+
dts: true,
|
|
2056
|
+
shims: true,
|
|
2057
|
+
umdName: true
|
|
2058
|
+
}))
|
|
1948
2059
|
};
|
|
1949
2060
|
});
|
|
1950
2061
|
const composedRsbuildConfig = await Promise.all(libConfigPromises);
|
|
@@ -1960,7 +2071,8 @@ async function initRsbuild(rslibConfig) {
|
|
|
1960
2071
|
const formatIndex = {
|
|
1961
2072
|
esm: 0,
|
|
1962
2073
|
cjs: 0,
|
|
1963
|
-
umd: 0
|
|
2074
|
+
umd: 0,
|
|
2075
|
+
mf: 0
|
|
1964
2076
|
};
|
|
1965
2077
|
for (const { format, config } of rsbuildConfigObject){
|
|
1966
2078
|
const currentFormatCount = formatCount[format];
|
|
@@ -1984,7 +2096,7 @@ const applyCommonOptions = (command)=>{
|
|
|
1984
2096
|
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file');
|
|
1985
2097
|
};
|
|
1986
2098
|
function runCli() {
|
|
1987
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.
|
|
2099
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.13");
|
|
1988
2100
|
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
1989
2101
|
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
1990
2102
|
[
|
|
@@ -2026,6 +2138,6 @@ function runCli() {
|
|
|
2026
2138
|
});
|
|
2027
2139
|
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
2028
2140
|
}
|
|
2029
|
-
const src_version = "0.0.
|
|
2141
|
+
const src_version = "0.0.13";
|
|
2030
2142
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
2031
2143
|
export { build, defineConfig, loadConfig, prepareCli, runCli, src_version as version, __webpack_exports__logger as logger };
|
package/dist-types/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RsbuildConfig, type RsbuildInstance } from '@rsbuild/core';
|
|
2
|
-
import type { AutoExternal, BannerAndFooter, Format, PkgJson, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn } from './types';
|
|
2
|
+
import type { AutoExternal, BannerAndFooter, Format, LibConfig, PkgJson, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* This function helps you to autocomplete configuration types.
|
|
5
5
|
* It accepts a Rslib config object, or a function that returns a config.
|
|
@@ -18,7 +18,7 @@ export declare const composeAutoExternalConfig: (options: {
|
|
|
18
18
|
pkgJson?: PkgJson;
|
|
19
19
|
userExternals?: NonNullable<RsbuildConfig["output"]>["externals"];
|
|
20
20
|
}) => RsbuildConfig;
|
|
21
|
-
export declare function composeMinifyConfig(
|
|
21
|
+
export declare function composeMinifyConfig(config: LibConfig): RsbuildConfig;
|
|
22
22
|
export declare function composeBannerFooterConfig(banner: BannerAndFooter, footer: BannerAndFooter): RsbuildConfig;
|
|
23
23
|
export declare function composeDecoratorsConfig(compilerOptions?: Record<string, any>, version?: NonNullable<NonNullable<RsbuildConfig['source']>['decorators']>['version']): RsbuildConfig;
|
|
24
24
|
export declare function createConstantRsbuildConfig(): Promise<RsbuildConfig>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
2
|
import type { PluginDtsOptions } from 'rsbuild-plugin-dts';
|
|
3
|
-
export type Format = 'esm' | 'cjs' | 'umd';
|
|
3
|
+
export type Format = 'esm' | 'cjs' | 'umd' | 'mf';
|
|
4
4
|
export type FixedEcmaVersions = 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023';
|
|
5
5
|
export type LatestEcmaVersions = 'es2024' | 'esnext';
|
|
6
6
|
export type EcmaScriptVersion = FixedEcmaVersions | LatestEcmaVersions;
|
|
@@ -19,6 +19,16 @@ export type BannerAndFooter = {
|
|
|
19
19
|
css?: string;
|
|
20
20
|
dts?: string;
|
|
21
21
|
};
|
|
22
|
+
export type Shims = {
|
|
23
|
+
cjs?: {
|
|
24
|
+
'import.meta.url'?: boolean;
|
|
25
|
+
};
|
|
26
|
+
esm?: {
|
|
27
|
+
__filename?: boolean;
|
|
28
|
+
__dirname?: boolean;
|
|
29
|
+
require?: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
22
32
|
export type Redirect = {
|
|
23
33
|
style?: boolean;
|
|
24
34
|
};
|
|
@@ -33,8 +43,11 @@ export interface LibConfig extends RsbuildConfig {
|
|
|
33
43
|
externalHelpers?: boolean;
|
|
34
44
|
banner?: BannerAndFooter;
|
|
35
45
|
footer?: BannerAndFooter;
|
|
46
|
+
shims?: Shims;
|
|
36
47
|
dts?: Dts;
|
|
48
|
+
umdName?: string;
|
|
37
49
|
}
|
|
50
|
+
export type LibOnlyConfig = Omit<LibConfig, keyof RsbuildConfig>;
|
|
38
51
|
export interface RslibConfig extends RsbuildConfig {
|
|
39
52
|
lib: LibConfig[];
|
|
40
53
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import color from 'picocolors';
|
|
2
|
-
import type { PkgJson } from '../types';
|
|
2
|
+
import type { LibConfig, PkgJson } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Node.js built-in modules.
|
|
5
5
|
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
|
|
@@ -10,5 +10,7 @@ export declare const readPackageJson: (rootPath: string) => undefined | PkgJson;
|
|
|
10
10
|
export declare const isObject: (obj: unknown) => obj is Record<string, any>;
|
|
11
11
|
export declare const isEmptyObject: (obj: object) => boolean;
|
|
12
12
|
export declare function pick<T, U extends keyof T>(obj: T, keys: ReadonlyArray<U>): Pick<T, U>;
|
|
13
|
-
export declare function omit<T extends object, U extends keyof T>(obj: T,
|
|
13
|
+
export declare function omit<T extends object, U extends keyof T>(obj: T, keysObj: Record<U, boolean>): Omit<T, keyof U>;
|
|
14
|
+
export declare function isPluginIncluded(config: LibConfig, pluginName: string): boolean;
|
|
15
|
+
export declare function checkMFPlugin(config: LibConfig): boolean;
|
|
14
16
|
export { color };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rslib/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "The Rspack-based library build tool.",
|
|
5
5
|
"homepage": "https://lib.rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"compiled"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@rsbuild/core": "1.0.
|
|
36
|
-
"rsbuild-plugin-dts": "0.0.
|
|
35
|
+
"@rsbuild/core": "~1.0.14",
|
|
36
|
+
"rsbuild-plugin-dts": "0.0.13"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rspack/core": "1.0.8",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"commander": "^12.1.0",
|
|
42
42
|
"fast-glob": "^3.3.2",
|
|
43
43
|
"fs-extra": "^11.2.0",
|
|
44
|
-
"memfs": "^4.
|
|
44
|
+
"memfs": "^4.14.0",
|
|
45
45
|
"picocolors": "1.1.0",
|
|
46
46
|
"prebundle": "1.2.2",
|
|
47
|
-
"rslib": "npm:@rslib/core@0.0.
|
|
47
|
+
"rslib": "npm:@rslib/core@0.0.12",
|
|
48
48
|
"rslog": "^1.2.3",
|
|
49
49
|
"tsconfck": "3.1.4",
|
|
50
50
|
"typescript": "^5.6.3",
|