@unpackjs/core 4.5.0 → 4.6.0

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.
Files changed (78) hide show
  1. package/dist/index.js +210 -296
  2. package/dist-types/createUnpack.d.ts.map +1 -1
  3. package/dist-types/plugins/splitChunks.d.ts +3 -0
  4. package/dist-types/plugins/splitChunks.d.ts.map +1 -0
  5. package/dist-types/plugins/svgIcons.d.ts +2 -8
  6. package/dist-types/plugins/svgIcons.d.ts.map +1 -1
  7. package/dist-types/plugins/unocss.d.ts +2 -5
  8. package/dist-types/plugins/unocss.d.ts.map +1 -1
  9. package/dist-types/progressBar.d.ts +0 -2
  10. package/dist-types/progressBar.d.ts.map +1 -1
  11. package/dist-types/rspack-config/buildAnalyze.d.ts +6 -0
  12. package/dist-types/rspack-config/buildAnalyze.d.ts.map +1 -0
  13. package/dist-types/rspack-config/cache.d.ts +7 -0
  14. package/dist-types/rspack-config/cache.d.ts.map +1 -0
  15. package/dist-types/rspack-config/css.d.ts +6 -0
  16. package/dist-types/rspack-config/css.d.ts.map +1 -0
  17. package/dist-types/rspack-config/detectCircular.d.ts +6 -0
  18. package/dist-types/rspack-config/detectCircular.d.ts.map +1 -0
  19. package/dist-types/rspack-config/helpers.d.ts.map +1 -0
  20. package/dist-types/rspack-config/html.d.ts +6 -0
  21. package/dist-types/rspack-config/html.d.ts.map +1 -0
  22. package/dist-types/rspack-config/index.d.ts +3 -0
  23. package/dist-types/rspack-config/index.d.ts.map +1 -0
  24. package/dist-types/rspack-config/loaders/transformLoader.d.ts.map +1 -0
  25. package/dist-types/rspack-config/loaders/typedCssModulesLoader.d.ts.map +1 -0
  26. package/dist-types/rspack-config/nativeCss.d.ts +6 -0
  27. package/dist-types/rspack-config/nativeCss.d.ts.map +1 -0
  28. package/dist-types/rspack-config/plugins/jsMinify.d.ts.map +1 -0
  29. package/dist-types/rspack-config/plugins/progress/helpers.d.ts.map +1 -0
  30. package/dist-types/rspack-config/plugins/progress/index.d.ts.map +1 -0
  31. package/dist-types/rspack-config/plugins/registerHooks.d.ts.map +1 -0
  32. package/dist-types/rspack-config/typeCheck.d.ts +6 -0
  33. package/dist-types/rspack-config/typeCheck.d.ts.map +1 -0
  34. package/dist-types/run/dev.d.ts.map +1 -1
  35. package/dist-types/types/config.d.ts +23 -20
  36. package/dist-types/types/config.d.ts.map +1 -1
  37. package/dist-types/types/index.d.ts +0 -1
  38. package/dist-types/types/index.d.ts.map +1 -1
  39. package/dist-types/types/plugin.d.ts +5 -5
  40. package/dist-types/types/plugin.d.ts.map +1 -1
  41. package/dist-types/types/thirdParty.d.ts.map +1 -1
  42. package/package.json +2 -2
  43. package/dist-types/bundler-config/buildAnalyze.d.ts +0 -6
  44. package/dist-types/bundler-config/buildAnalyze.d.ts.map +0 -1
  45. package/dist-types/bundler-config/cache.d.ts +0 -7
  46. package/dist-types/bundler-config/cache.d.ts.map +0 -1
  47. package/dist-types/bundler-config/chunkSplit.d.ts +0 -6
  48. package/dist-types/bundler-config/chunkSplit.d.ts.map +0 -1
  49. package/dist-types/bundler-config/css.d.ts +0 -6
  50. package/dist-types/bundler-config/css.d.ts.map +0 -1
  51. package/dist-types/bundler-config/detectCircular.d.ts +0 -6
  52. package/dist-types/bundler-config/detectCircular.d.ts.map +0 -1
  53. package/dist-types/bundler-config/helpers.d.ts.map +0 -1
  54. package/dist-types/bundler-config/html.d.ts +0 -6
  55. package/dist-types/bundler-config/html.d.ts.map +0 -1
  56. package/dist-types/bundler-config/index.d.ts +0 -3
  57. package/dist-types/bundler-config/index.d.ts.map +0 -1
  58. package/dist-types/bundler-config/loaders/transformLoader.d.ts.map +0 -1
  59. package/dist-types/bundler-config/loaders/typedCssModulesLoader.d.ts.map +0 -1
  60. package/dist-types/bundler-config/nativeCss.d.ts +0 -6
  61. package/dist-types/bundler-config/nativeCss.d.ts.map +0 -1
  62. package/dist-types/bundler-config/plugins/jsMinify.d.ts.map +0 -1
  63. package/dist-types/bundler-config/plugins/progress/helpers.d.ts.map +0 -1
  64. package/dist-types/bundler-config/plugins/progress/index.d.ts.map +0 -1
  65. package/dist-types/bundler-config/plugins/registerHooks.d.ts.map +0 -1
  66. package/dist-types/bundler-config/typeCheck.d.ts +0 -6
  67. package/dist-types/bundler-config/typeCheck.d.ts.map +0 -1
  68. package/dist-types/spinner.d.ts +0 -9
  69. package/dist-types/spinner.d.ts.map +0 -1
  70. package/dist-types/types/chunkSplit.d.ts +0 -23
  71. package/dist-types/types/chunkSplit.d.ts.map +0 -1
  72. /package/dist-types/{bundler-config → rspack-config}/helpers.d.ts +0 -0
  73. /package/dist-types/{bundler-config → rspack-config}/loaders/transformLoader.d.ts +0 -0
  74. /package/dist-types/{bundler-config → rspack-config}/loaders/typedCssModulesLoader.d.ts +0 -0
  75. /package/dist-types/{bundler-config → rspack-config}/plugins/jsMinify.d.ts +0 -0
  76. /package/dist-types/{bundler-config → rspack-config}/plugins/progress/helpers.d.ts +0 -0
  77. /package/dist-types/{bundler-config → rspack-config}/plugins/progress/index.d.ts +0 -0
  78. /package/dist-types/{bundler-config → rspack-config}/plugins/registerHooks.d.ts +0 -0
package/dist/index.js CHANGED
@@ -20,7 +20,6 @@ import { parse } from "stacktrace-parser";
20
20
  import node_zlib from "node:zlib";
21
21
  import magic_string from "magic-string";
22
22
  import { expand } from "dotenv-expand";
23
- import node_assert from "node:assert";
24
23
  import { RspackDevServer } from "@rspack/dev-server";
25
24
  import { exec, spawn } from "node:child_process";
26
25
  import chokidar from "chokidar";
@@ -122,7 +121,7 @@ let CSS_MODULES_LOCAL_IDENT_NAME = '[path][name]__[local]--[hash:5]', CSS_MODULE
122
121
  </body>
123
122
  </html>`, JS_REGEX = /\.[jt]s$/, JSX_REGEX = /\.[jt]sx$/, SCRIPT_REGEX = /\.[jt]sx?$/;
124
123
  var utils_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
125
- let { merge: mergeConfig } = __webpack_require__("compiled/webpack-merge"), { default: launchEditor } = __webpack_require__("compiled/launch-editor"), getNodeEnv = ()=>process.env.NODE_ENV, setNodeEnv = (env)=>{
124
+ let { merge: utils_mergeConfig } = __webpack_require__("compiled/webpack-merge"), { default: launchEditor } = __webpack_require__("compiled/launch-editor"), getNodeEnv = ()=>process.env.NODE_ENV, setNodeEnv = (env)=>{
126
125
  process.env.NODE_ENV = env;
127
126
  }, setDevServer = (isDevServer)=>{
128
127
  process.env.DEV_SERVER = isDevServer ? 'true' : 'false';
@@ -638,7 +637,7 @@ let COMPRESSIBLE_REGEX = /\.(?:js|css|html|json|svg|txt|xml|xhtml|wasm|manifest|
638
637
  'react-router-dom': 'ReactRouterDOM'
639
638
  };
640
639
  return externalAlias[pkgName] ? externalAlias[pkgName] : pkgName.replace(/^@/, '').split(/[/\-.]/).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
641
- }, getExternalValue = (pkgName)=>`window ${getExternalLibraryName(pkgName)}`, normalizeSvg = (content)=>content.replace(/<\?xml[\s\S]*?\?>/gi, '').replace(/<!DOCTYPE[\s\S]*?>/gi, '').replace(/<!--[\s\S]*?-->/g, '').trim(), extractSvgContent = (content)=>{
640
+ }, getExternalValue = (pkgName)=>`window ${getExternalLibraryName(pkgName)}`, MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\/])?([^\\/]+)/, normalizeSvg = (content)=>content.replace(/<\?xml[\s\S]*?\?>/gi, '').replace(/<!DOCTYPE[\s\S]*?>/gi, '').replace(/<!--[\s\S]*?-->/g, '').trim(), extractSvgContent = (content)=>{
642
641
  let match = content.match(/<svg\b([^>]*)>/i), viewBoxMatch = match?.[1]?.match(/viewBox\s*=\s*["']([^"']+)["']/i);
643
642
  return {
644
643
  inner: content.replace(/^[\s\S]*?<svg\b[^>]*>/i, '').replace(/<\/svg>[\s\S]*$/i, '').trim(),
@@ -783,7 +782,7 @@ async function applyCacheConfig({ config, unpackConfig, envFilePaths }) {
783
782
  let cacheConfig = isPlainObject(unpackConfig.performance.cache) ? unpackConfig.performance.cache : {}, buildDependencies = await getBuildDependencies(unpackConfig.root);
784
783
  buildDependencies.userBuildDependencies = cacheConfig.buildDependencies || [], buildDependencies.envFilePaths = envFilePaths;
785
784
  let cacheDirectory = node_path.resolve(unpackConfig.root, cacheConfig.cacheDirectory || `${unpackConfig._context.cachePath}/cache`, utils_isDevServer() ? 'dev' : 'build');
786
- return mergeConfig(config, {
785
+ return utils_mergeConfig(config, {
787
786
  cache: {
788
787
  type: 'persistent',
789
788
  buildDependencies: Object.values(buildDependencies).flat(),
@@ -794,91 +793,6 @@ async function applyCacheConfig({ config, unpackConfig, envFilePaths }) {
794
793
  }
795
794
  });
796
795
  }
797
- globalScope[TRANSFORM_TIMING_STORE] = transformTimingMap;
798
- let MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\/])?([^\\/]+)/, SPLIT_STRATEGY_DISPATCHER = {
799
- 'split-by-module': function(ctx) {
800
- let { forceSplittingGroups, defaultConfig } = ctx;
801
- return {
802
- ...defaultConfig,
803
- minSize: 0,
804
- maxInitialRequests: 1 / 0,
805
- cacheGroups: {
806
- ...defaultConfig.cacheGroups,
807
- ...forceSplittingGroups,
808
- vendors: {
809
- priority: -9,
810
- test: NODE_MODULES_REGEX,
811
- name: (module)=>module ? function(modulePath) {
812
- let handleModuleContext = modulePath?.match(MODULE_PATH_REGEX);
813
- if (!handleModuleContext) return;
814
- let [, scope, name] = handleModuleContext;
815
- return [
816
- 'npm',
817
- (scope ?? '').replace('@', ''),
818
- name
819
- ].filter(Boolean).join('.');
820
- }(module.context) : void 0
821
- }
822
- }
823
- };
824
- },
825
- 'split-by-size': function(ctx) {
826
- let { forceSplittingGroups, defaultConfig, chunkSplit } = ctx;
827
- return node_assert('split-by-size' === chunkSplit.strategy), {
828
- ...defaultConfig,
829
- minSize: chunkSplit.minSize ?? 50000,
830
- maxSize: chunkSplit.maxSize ?? 500000,
831
- cacheGroups: {
832
- ...defaultConfig.cacheGroups,
833
- ...forceSplittingGroups
834
- }
835
- };
836
- },
837
- custom: function(ctx) {
838
- let userSplitChunks, { forceSplittingGroups, defaultConfig, chunkSplit } = ctx;
839
- if ('splitChunks' in chunkSplit && (userSplitChunks = chunkSplit.splitChunks), void 0 === userSplitChunks) return {
840
- ...defaultConfig,
841
- cacheGroups: {
842
- ...defaultConfig.cacheGroups,
843
- ...forceSplittingGroups
844
- }
845
- };
846
- if (!1 === userSplitChunks) return Object.keys(forceSplittingGroups).length > 0 && {
847
- chunks: 'all',
848
- cacheGroups: {
849
- ...forceSplittingGroups
850
- }
851
- };
852
- let baseConfig = userSplitChunks;
853
- return {
854
- ...baseConfig,
855
- cacheGroups: {
856
- ...baseConfig.cacheGroups || {},
857
- ...forceSplittingGroups
858
- }
859
- };
860
- },
861
- 'all-in-one': function(_ctx) {
862
- return !1;
863
- },
864
- 'single-vendor': function(ctx) {
865
- let { defaultConfig, forceSplittingGroups } = ctx;
866
- return {
867
- ...defaultConfig,
868
- cacheGroups: {
869
- ...defaultConfig.cacheGroups,
870
- singleVendor: {
871
- test: NODE_MODULES_REGEX,
872
- priority: 0,
873
- chunks: 'all',
874
- name: 'vendor',
875
- enforce: !0
876
- },
877
- ...forceSplittingGroups
878
- }
879
- };
880
- }
881
- };
882
796
  async function getEntry(root, customEntry) {
883
797
  let entry;
884
798
  if (entry = customEntry ? node_path.resolve(root, customEntry) : (await external_tinyglobby_glob('(index|main).{js,ts,jsx,tsx}', {
@@ -887,6 +801,7 @@ async function getEntry(root, customEntry) {
887
801
  }))[0], !node_fs.existsSync(entry)) throw Error('could not find entry file');
888
802
  return entry;
889
803
  }
804
+ globalScope[TRANSFORM_TIMING_STORE] = transformTimingMap;
890
805
  let getOutputFilename = ({ type, hash, async })=>{
891
806
  let FILENAME = utils_isProd() && !1 !== hash ? PROD_DEFAULT_FILENAME : DEV_DEFAULT_FILENAME;
892
807
  return async ? 'js' === type ? FILENAME.jsAsync : FILENAME.cssAsync : FILENAME[type];
@@ -915,7 +830,7 @@ let getOutputFilename = ({ type, hash, async })=>{
915
830
  }
916
831
  }), getLessLoader = (unpackConfig)=>({
917
832
  loader: getCompiledPkgPath('less-loader'),
918
- options: mergeConfig({
833
+ options: utils_mergeConfig({
919
834
  lessOptions: {
920
835
  javascriptEnabled: !0
921
836
  },
@@ -955,7 +870,7 @@ class JsMinifyPlugin {
955
870
  apply(compiler) {
956
871
  let meta = JSON.stringify({
957
872
  name: jsMinify_PLUGIN_NAME,
958
- version: "4.5.0",
873
+ version: "4.6.0",
959
874
  options: this.minifyOptions
960
875
  });
961
876
  compiler.hooks.compilation.tap(jsMinify_PLUGIN_NAME, (compilation)=>{
@@ -990,36 +905,11 @@ class JsMinifyPlugin {
990
905
  }));
991
906
  }
992
907
  }
993
- class Spinner {
994
- chars = [
995
- '⠋',
996
- '⠙',
997
- '⠹',
998
- '⠸',
999
- '⠼',
1000
- '⠴',
1001
- '⠦',
1002
- '⠧',
1003
- '⠇',
1004
- '⠏'
1005
- ];
1006
- currentIndex = 0;
1007
- lastUpdateTime = 0;
1008
- interval = 100;
1009
- getCurrentChar() {
1010
- let now = Date.now();
1011
- return now - this.lastUpdateTime >= this.interval && (this.currentIndex = (this.currentIndex + 1) % this.chars.length, this.lastUpdateTime = now), this.chars[this.currentIndex];
1012
- }
1013
- reset() {
1014
- this.currentIndex = 0, this.lastUpdateTime = 0;
1015
- }
1016
- }
1017
908
  class ProgressBar {
1018
909
  prefix = 'transforming';
1019
- spinner = new Spinner();
1020
910
  update({ percentage, message = '' }) {
1021
- let { columns: terminalWidth } = process.stdout, loadingChar = this.spinner.getCurrentChar(), messageWidth = terminalWidth - this.prefix.length - (1 === percentage ? 10 : 9);
1022
- logUpdate(`${loadingChar} ${this.prefix} (${Math.floor(100 * percentage)}%) ${colors.dim(message.slice(0, messageWidth).padEnd(messageWidth, ' '))}`), 1 === percentage && clearLine();
911
+ let { columns: terminalWidth } = process.stdout, messageWidth = terminalWidth - this.prefix.length - (1 === percentage ? 10 : 9);
912
+ logUpdate(`${this.prefix} (${Math.floor(100 * percentage)}%) ${colors.dim(message.slice(0, messageWidth).padEnd(messageWidth, ' '))}`), 1 === percentage && clearLine();
1023
913
  }
1024
914
  }
1025
915
  function isLikelyFile(filePath) {
@@ -1222,20 +1112,20 @@ async function applyTypeCheckConfig({ config, unpackConfig }) {
1222
1112
  }
1223
1113
  })), config;
1224
1114
  }
1225
- var bundler_config_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
1226
- async function getBundlerConfig(originalUnpackConfig) {
1115
+ var rspack_config_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
1116
+ async function getRspackConfig(originalUnpackConfig) {
1227
1117
  setCurrentUnpackConfig(originalUnpackConfig);
1228
- let { plugins, bundlerConfig, ...rest } = originalUnpackConfig;
1118
+ let { plugins, rspack: rspackConfig, ...rest } = originalUnpackConfig;
1229
1119
  await applyPluginsByHook('config', async (impl)=>{
1230
1120
  rest = await impl(rest, {
1231
1121
  ...originalUnpackConfig._context,
1232
- mergeConfig: mergeConfig
1122
+ mergeConfig: utils_mergeConfig
1233
1123
  });
1234
1124
  });
1235
1125
  let unpackConfig = {
1236
1126
  ...rest,
1237
1127
  plugins,
1238
- bundlerConfig
1128
+ rspack: rspackConfig
1239
1129
  };
1240
1130
  setCurrentUnpackConfig(unpackConfig), await applyPluginsByHook('configResolved', async (impl)=>{
1241
1131
  await impl(unpackConfig, originalUnpackConfig._context);
@@ -1396,12 +1286,12 @@ async function getBundlerConfig(originalUnpackConfig) {
1396
1286
  moduleIds: isDev() ? 'named' : 'deterministic',
1397
1287
  minimize: !!unpackConfig.build?.minify && utils_isProd(),
1398
1288
  minimizer: [
1399
- new JsMinifyPlugin(mergeConfig({
1289
+ new JsMinifyPlugin(utils_mergeConfig({
1400
1290
  compress: {
1401
1291
  target: unpackConfig.build.target
1402
1292
  }
1403
1293
  }, minifyOptions.oxc || {})),
1404
- new rspack.LightningCssMinimizerRspackPlugin(mergeConfig({
1294
+ new rspack.LightningCssMinimizerRspackPlugin(utils_mergeConfig({
1405
1295
  minimizerOptions: {
1406
1296
  targets: esVersionToBrowserslist(unpackConfig.build.target)
1407
1297
  }
@@ -1423,7 +1313,7 @@ async function getBundlerConfig(originalUnpackConfig) {
1423
1313
  enforce: 'pre',
1424
1314
  use: [
1425
1315
  {
1426
- loader: node_path.resolve(bundler_config_dirname, './transformLoader.js'),
1316
+ loader: node_path.resolve(rspack_config_dirname, './transformLoader.js'),
1427
1317
  options: {
1428
1318
  handler,
1429
1319
  pluginName: plugin.name
@@ -1431,169 +1321,137 @@ async function getBundlerConfig(originalUnpackConfig) {
1431
1321
  }
1432
1322
  ]
1433
1323
  });
1434
- }), config = (({ config, unpackConfig })=>{
1435
- let { chunkSplit } = unpackConfig.performance || {};
1436
- if (chunkSplit?.strategy) {
1437
- let forceSplittingGroups = {};
1438
- chunkSplit?.forceSplitting && (forceSplittingGroups = function(forceSplitting, strategy) {
1439
- let cacheGroups = {};
1440
- for (let [key, regexp] of Array.isArray(forceSplitting) ? forceSplitting.map((regexp, index)=>[
1441
- `force-split-${index}`,
1442
- regexp
1443
- ]) : Object.entries(forceSplitting))cacheGroups[key] = {
1444
- test: regexp,
1445
- name: key,
1446
- chunks: 'all',
1447
- priority: +('single-vendor' === strategy),
1448
- enforce: !0
1449
- };
1450
- return cacheGroups;
1451
- }(chunkSplit.forceSplitting, chunkSplit.strategy)), set(config, [
1452
- 'optimization',
1453
- 'splitChunks'
1454
- ], SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
1455
- defaultConfig: {
1456
- chunks: 'all'
1324
+ }), config = unpackConfig.css?.native ? function({ config, unpackConfig }) {
1325
+ config.output.cssFilename = getOutputFilename({
1326
+ type: 'css',
1327
+ hash: unpackConfig.build?.filenameHash
1328
+ }), config.output.cssChunkFilename = getOutputFilename({
1329
+ type: 'css',
1330
+ hash: unpackConfig.build?.filenameHash,
1331
+ async: !0
1332
+ }), set(config, [
1333
+ 'module',
1334
+ 'parser',
1335
+ 'css/module'
1336
+ ], {
1337
+ namedExports: !1
1338
+ }), set(config, [
1339
+ 'module',
1340
+ 'generator',
1341
+ 'css/module'
1342
+ ], {
1343
+ localIdentName: CSS_MODULES_LOCAL_IDENT_NAME,
1344
+ exportsConvention: CSS_MODULES_EXPORTS_CONVENTION
1345
+ });
1346
+ let createStyleRule = (test, items)=>{
1347
+ let use = items.filter(Boolean);
1348
+ return {
1349
+ test,
1350
+ oneOf: [
1351
+ (({ use })=>({
1352
+ resourceQuery: /[?&]module(?:[=&]|$)/,
1353
+ use: [
1354
+ isDev() && {
1355
+ loader: node_path.resolve(nativeCss_dirname, './typedCssModulesLoader.js')
1356
+ },
1357
+ ...use
1358
+ ].filter(Boolean),
1359
+ type: 'css/module'
1360
+ }))({
1361
+ use
1362
+ }),
1363
+ {
1364
+ use,
1365
+ type: 'css'
1366
+ }
1367
+ ]
1368
+ };
1369
+ };
1370
+ return config.module.rules.push(createStyleRule(/\.css$/i, [
1371
+ getCssLoader(unpackConfig),
1372
+ unpackConfig.css?.tailwindcss && {
1373
+ loader: require.resolve('@tailwindcss/webpack')
1374
+ }
1375
+ ])), config.module.rules.push(createStyleRule(/\.less$/i, [
1376
+ getCssLoader(unpackConfig),
1377
+ getLessLoader(unpackConfig)
1378
+ ])), config.module.rules.push(createStyleRule(/\.s[ac]ss$/i, [
1379
+ getCssLoader(unpackConfig),
1380
+ getSassLoader(unpackConfig)
1381
+ ])), config;
1382
+ }({
1383
+ config,
1384
+ unpackConfig
1385
+ }) : function({ config, unpackConfig }) {
1386
+ let getCommonRules = ({ importLoaders })=>[
1387
+ utils_isDevServer() ? {
1388
+ loader: getCompiledPkgPath('style-loader')
1389
+ } : {
1390
+ loader: rspack.CssExtractRspackPlugin.loader,
1391
+ options: {
1392
+ defaultExport: !0
1393
+ }
1457
1394
  },
1458
- forceSplittingGroups,
1459
- chunkSplit
1460
- }));
1461
- }
1462
- return config;
1463
- })({
1464
- config: config = unpackConfig.css?.native ? function({ config, unpackConfig }) {
1465
- config.output.cssFilename = getOutputFilename({
1395
+ isDev() && {
1396
+ loader: node_path.resolve(css_dirname, './typedCssModulesLoader.js')
1397
+ },
1398
+ {
1399
+ loader: getCompiledPkgPath('css-loader'),
1400
+ options: {
1401
+ importLoaders,
1402
+ modules: {
1403
+ auto: (_, resourceQuery)=>resourceQuery?.includes('module'),
1404
+ localIdentName: CSS_MODULES_LOCAL_IDENT_NAME,
1405
+ exportLocalsConvention: CSS_MODULES_EXPORTS_CONVENTION,
1406
+ namedExport: !1
1407
+ },
1408
+ sourceMap: unpackConfig.css?.sourceMap
1409
+ }
1410
+ }
1411
+ ].filter(Boolean);
1412
+ return utils_isDevServer() || config.plugins.push(new rspack.CssExtractRspackPlugin({
1413
+ filename: getOutputFilename({
1466
1414
  type: 'css',
1467
1415
  hash: unpackConfig.build?.filenameHash
1468
- }), config.output.cssChunkFilename = getOutputFilename({
1416
+ }),
1417
+ chunkFilename: getOutputFilename({
1469
1418
  type: 'css',
1470
1419
  hash: unpackConfig.build?.filenameHash,
1471
1420
  async: !0
1472
- }), set(config, [
1473
- 'module',
1474
- 'parser',
1475
- 'css/module'
1476
- ], {
1477
- namedExports: !1
1478
- }), set(config, [
1479
- 'module',
1480
- 'generator',
1481
- 'css/module'
1482
- ], {
1483
- localIdentName: CSS_MODULES_LOCAL_IDENT_NAME,
1484
- exportsConvention: CSS_MODULES_EXPORTS_CONVENTION
1485
- });
1486
- let createStyleRule = (test, items)=>{
1487
- let use = items.filter(Boolean);
1488
- return {
1489
- test,
1490
- oneOf: [
1491
- (({ use })=>({
1492
- resourceQuery: /[?&]module(?:[=&]|$)/,
1493
- use: [
1494
- isDev() && {
1495
- loader: node_path.resolve(nativeCss_dirname, './typedCssModulesLoader.js')
1496
- },
1497
- ...use
1498
- ].filter(Boolean),
1499
- type: 'css/module'
1500
- }))({
1501
- use
1502
- }),
1503
- {
1504
- use,
1505
- type: 'css'
1506
- }
1507
- ]
1508
- };
1509
- };
1510
- return config.module.rules.push(createStyleRule(/\.css$/i, [
1421
+ }),
1422
+ ignoreOrder: !0
1423
+ })), config.module.rules.push({
1424
+ test: /\.less$/i,
1425
+ use: [
1426
+ ...getCommonRules({
1427
+ importLoaders: 2
1428
+ }),
1429
+ getCssLoader(unpackConfig),
1430
+ getLessLoader(unpackConfig)
1431
+ ]
1432
+ }), config.module.rules.push({
1433
+ test: /\.css$/i,
1434
+ use: [
1435
+ ...getCommonRules({
1436
+ importLoaders: unpackConfig.css?.tailwindcss ? 2 : 1
1437
+ }),
1511
1438
  getCssLoader(unpackConfig),
1512
1439
  unpackConfig.css?.tailwindcss && {
1513
1440
  loader: require.resolve('@tailwindcss/webpack')
1514
1441
  }
1515
- ])), config.module.rules.push(createStyleRule(/\.less$/i, [
1516
- getCssLoader(unpackConfig),
1517
- getLessLoader(unpackConfig)
1518
- ])), config.module.rules.push(createStyleRule(/\.s[ac]ss$/i, [
1442
+ ].filter(Boolean)
1443
+ }), config.module.rules.push({
1444
+ test: /\.s[ac]ss$/i,
1445
+ use: [
1446
+ ...getCommonRules({
1447
+ importLoaders: 2
1448
+ }),
1519
1449
  getCssLoader(unpackConfig),
1520
1450
  getSassLoader(unpackConfig)
1521
- ])), config;
1522
- }({
1523
- config,
1524
- unpackConfig
1525
- }) : function({ config, unpackConfig }) {
1526
- let getCommonRules = ({ importLoaders })=>[
1527
- utils_isDevServer() ? {
1528
- loader: getCompiledPkgPath('style-loader')
1529
- } : {
1530
- loader: rspack.CssExtractRspackPlugin.loader,
1531
- options: {
1532
- defaultExport: !0
1533
- }
1534
- },
1535
- isDev() && {
1536
- loader: node_path.resolve(css_dirname, './typedCssModulesLoader.js')
1537
- },
1538
- {
1539
- loader: getCompiledPkgPath('css-loader'),
1540
- options: {
1541
- importLoaders,
1542
- modules: {
1543
- auto: (_, resourceQuery)=>resourceQuery?.includes('module'),
1544
- localIdentName: CSS_MODULES_LOCAL_IDENT_NAME,
1545
- exportLocalsConvention: CSS_MODULES_EXPORTS_CONVENTION,
1546
- namedExport: !1
1547
- },
1548
- sourceMap: unpackConfig.css?.sourceMap
1549
- }
1550
- }
1551
- ].filter(Boolean);
1552
- return utils_isDevServer() || config.plugins.push(new rspack.CssExtractRspackPlugin({
1553
- filename: getOutputFilename({
1554
- type: 'css',
1555
- hash: unpackConfig.build?.filenameHash
1556
- }),
1557
- chunkFilename: getOutputFilename({
1558
- type: 'css',
1559
- hash: unpackConfig.build?.filenameHash,
1560
- async: !0
1561
- }),
1562
- ignoreOrder: !0
1563
- })), config.module.rules.push({
1564
- test: /\.less$/i,
1565
- use: [
1566
- ...getCommonRules({
1567
- importLoaders: 2
1568
- }),
1569
- getCssLoader(unpackConfig),
1570
- getLessLoader(unpackConfig)
1571
- ]
1572
- }), config.module.rules.push({
1573
- test: /\.css$/i,
1574
- use: [
1575
- ...getCommonRules({
1576
- importLoaders: unpackConfig.css?.tailwindcss ? 2 : 1
1577
- }),
1578
- getCssLoader(unpackConfig),
1579
- unpackConfig.css?.tailwindcss && {
1580
- loader: require.resolve('@tailwindcss/webpack')
1581
- }
1582
- ].filter(Boolean)
1583
- }), config.module.rules.push({
1584
- test: /\.s[ac]ss$/i,
1585
- use: [
1586
- ...getCommonRules({
1587
- importLoaders: 2
1588
- }),
1589
- getCssLoader(unpackConfig),
1590
- getSassLoader(unpackConfig)
1591
- ]
1592
- }), config;
1593
- }({
1594
- config,
1595
- unpackConfig
1596
- }),
1451
+ ]
1452
+ }), config;
1453
+ }({
1454
+ config,
1597
1455
  unpackConfig
1598
1456
  }), unpackConfig.mpa || (config = await applyHtmlConfig({
1599
1457
  config,
@@ -1641,18 +1499,18 @@ async function getBundlerConfig(originalUnpackConfig) {
1641
1499
  }({
1642
1500
  config,
1643
1501
  unpackConfig
1644
- })), await applyPluginsByHook('bundlerConfig', async (impl)=>{
1502
+ })), await applyPluginsByHook('rspackConfig', async (impl)=>{
1645
1503
  config = await impl(config, {
1646
1504
  ...originalUnpackConfig._context,
1647
1505
  unpackConfig,
1648
- mergeConfig: mergeConfig
1506
+ mergeConfig: utils_mergeConfig
1649
1507
  });
1650
- }), unpackConfig.bundlerConfig && (config = isFunction(unpackConfig.bundlerConfig) ? await unpackConfig.bundlerConfig(config, {
1651
- mergeConfig: mergeConfig
1652
- }) : mergeConfig(config, unpackConfig.bundlerConfig)), config;
1508
+ }), unpackConfig.rspack && (config = isFunction(unpackConfig.rspack) ? await unpackConfig.rspack(config, {
1509
+ mergeConfig: utils_mergeConfig
1510
+ }) : utils_mergeConfig(config, unpackConfig.rspack)), config;
1653
1511
  }
1654
1512
  async function unpackBuild(unpackConfig) {
1655
- let compiler = rspack(await getBundlerConfig(unpackConfig)), handler = (err, stats)=>{
1513
+ let compiler = rspack(await getRspackConfig(unpackConfig)), handler = (err, stats)=>{
1656
1514
  if (err) {
1657
1515
  console.error(err.stack || err), err.details && console.error(err.details);
1658
1516
  return;
@@ -1728,7 +1586,7 @@ function execAsync(command, options) {
1728
1586
  });
1729
1587
  }
1730
1588
  async function unpackDev(unpackConfig) {
1731
- let compiler = rspack(await getBundlerConfig(unpackConfig)), port = await getPort(unpackConfig.server?.port), proxyConfig = unpackConfig.server?.proxy;
1589
+ let compiler = rspack(await getRspackConfig(unpackConfig)), port = await getPort(unpackConfig.server?.port), proxyConfig = unpackConfig.server?.proxy;
1732
1590
  isPlainObject(proxyConfig) && (proxyConfig = Object.entries(proxyConfig).map(([contextStr, target])=>{
1733
1591
  let baseConfig = {
1734
1592
  context: contextStr.split(','),
@@ -1770,7 +1628,7 @@ async function unpackDev(unpackConfig) {
1770
1628
  ...middlewares
1771
1629
  ]);
1772
1630
  let server = new RspackDevServer(devServerOptions, compiler);
1773
- await server.start(), logger_logger.greet(` ${colors.brand(`${colors.bold(unpackConfig._context.callerName.toUpperCase())} v4.5.0`)} ${colors.dim('ready in')} ${colors.bold(Math.ceil(performance.now() - getUnpackStartTime()))} ${colors.dim('ms')}\n`), printServerUrls({
1631
+ await server.start(), logger_logger.greet(` ${colors.brand(`${colors.bold(unpackConfig._context.callerName.toUpperCase())} v4.6.0`)} ${colors.dim('ready in')} ${colors.bold(Math.ceil(performance.now() - getUnpackStartTime()))} ${colors.dim('ms')}\n`), printServerUrls({
1774
1632
  port,
1775
1633
  host: unpackConfig.server.host,
1776
1634
  base: unpackConfig.base
@@ -1784,13 +1642,16 @@ async function unpackDev(unpackConfig) {
1784
1642
  function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'unpack' }) {
1785
1643
  let _context = {
1786
1644
  callerName,
1787
- version: "4.5.0",
1645
+ version: "4.6.0",
1788
1646
  cachePath: 'node_modules/.unpack'
1789
1647
  }, resolveConfig = (mode)=>{
1790
1648
  let rootPath, outputPath, basePath, cachedTraceMap, fs, isValidMethodName, parseFrame, formatOriginalLocation, formatFullStack, resolveErrorLocationAndStack, root, alias, shouldTransformDeepImport, preJsAssets, jsAssets, cssAssets, bundledDepsCachePath, deepImportPkgPattern, deepImportRegex, plugin, root1, uno, generated, configOrPathFromUnpackConfig, defaultsFromUnpackConfig, VIRTUAL_UNO_CSS_ID, rootDir, isMpa, unoConfig, configFilePath, unpackConfigPath, tokens, requestedLayers, tasks, unocssCacheDir, tokensCachePath, layersCachePath, timeCachePath, configHashCachePath, generatedCachePath, bundlerCacheDir, cachedTokensSize, cachedLayersSize, isCompiling, resolveUnocssConfig, flushTasks, getVirtualModuleContent, hash, restoreSkipCode, applyUnoTransformers, optionsFromUnpackConfig, rootPath1, registerCode, namesCode, defaultConfig = {
1791
1649
  root: cwd,
1792
1650
  base: '/',
1793
1651
  sourceMap: 'production' !== mode && 'cheap-module-source-map',
1652
+ splitChunks: {
1653
+ preset: 'single-vendor'
1654
+ },
1794
1655
  build: {
1795
1656
  outDir: 'dist',
1796
1657
  minify: !0,
@@ -1809,9 +1670,6 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
1809
1670
  sourceMap: !1
1810
1671
  },
1811
1672
  performance: {
1812
- chunkSplit: {
1813
- strategy: 'single-vendor'
1814
- },
1815
1673
  printFileSize: !0
1816
1674
  },
1817
1675
  typeCheck: !0,
@@ -2446,7 +2304,7 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
2446
2304
  },
2447
2305
  ...middlewares
2448
2306
  ],
2449
- bundlerConfig: (config)=>{
2307
+ rspackConfig: (config)=>{
2450
2308
  let PLUGIN_NAME = 'InjectAssetsPlugin';
2451
2309
  return config.plugins.push({
2452
2310
  apply: (compiler)=>{
@@ -2542,7 +2400,7 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
2542
2400
  let configFile = node_path.join(root, file);
2543
2401
  if (node_fs.existsSync(configFile)) return configFile;
2544
2402
  }
2545
- })(rootDir, configFilePath), configFromOption = mergeConfig(configFromOption, await loadConfigFromFile(configFilePath)), resolvedDefaults && (configFromOption = mergeConfig(resolvedDefaults, configFromOption)), configFromOption;
2403
+ })(rootDir, configFilePath), configFromOption = utils_mergeConfig(configFromOption, await loadConfigFromFile(configFilePath)), resolvedDefaults && (configFromOption = utils_mergeConfig(resolvedDefaults, configFromOption)), configFromOption;
2546
2404
  }, flushTasks = async ()=>{
2547
2405
  if (!tasks.length) return;
2548
2406
  logger_logger.debug(colors.yellow(`[unocss] Extract token from ${tasks.length} modules.`));
@@ -2708,11 +2566,67 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
2708
2566
  },
2709
2567
  resolveId: (id)=>id.startsWith('virtual:svg-icons-') ? '\0' + id : null,
2710
2568
  load: (id)=>'\0virtual:svg-icons-register' === id ? registerCode || 'export default null' : '\0virtual:svg-icons-names' === id ? namesCode || 'export default []' : null
2711
- })
2569
+ }),
2570
+ {
2571
+ name: 'unpack:split-chunks',
2572
+ rspackConfig (config, { unpackConfig, mergeConfig }) {
2573
+ if (!1 === unpackConfig.splitChunks) return mergeConfig(config, {
2574
+ optimization: {
2575
+ splitChunks: !1
2576
+ }
2577
+ });
2578
+ let { preset = 'none', ...rest } = unpackConfig.splitChunks;
2579
+ return mergeConfig(config, {
2580
+ optimization: {
2581
+ splitChunks: {
2582
+ ...function(preset) {
2583
+ if (!preset) return {};
2584
+ switch(preset){
2585
+ case 'single-vendor':
2586
+ return {
2587
+ cacheGroups: {
2588
+ singleVendor: {
2589
+ test: NODE_MODULES_REGEX,
2590
+ priority: 0,
2591
+ chunks: 'all',
2592
+ name: 'vendor',
2593
+ enforce: !0
2594
+ }
2595
+ }
2596
+ };
2597
+ case 'per-package':
2598
+ return {
2599
+ minSize: 0,
2600
+ maxInitialRequests: 1 / 0,
2601
+ cacheGroups: {
2602
+ vendors: {
2603
+ priority: -9,
2604
+ test: NODE_MODULES_REGEX,
2605
+ name: (module)=>module ? function(modulePath) {
2606
+ let handleModuleContext = modulePath?.match(MODULE_PATH_REGEX);
2607
+ if (!handleModuleContext) return;
2608
+ let [, scope, name] = handleModuleContext;
2609
+ return `npm-${scope ? `${scope.replace('@', '')}_` : ''}${name}`;
2610
+ }(module.context) : void 0
2611
+ }
2612
+ }
2613
+ };
2614
+ case 'none':
2615
+ return {};
2616
+ default:
2617
+ throw Error(`Unknown splitChunks preset: ${preset}`);
2618
+ }
2619
+ }(preset),
2620
+ ...rest
2621
+ }
2622
+ }
2623
+ });
2624
+ }
2625
+ }
2712
2626
  ]
2713
2627
  };
2714
2628
  return {
2715
- ...mergeConfig(defaultConfig, userConfig),
2629
+ ...utils_mergeConfig(defaultConfig, userConfig),
2716
2630
  _context
2717
2631
  };
2718
2632
  };
@@ -2721,7 +2635,7 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
2721
2635
  let mode = watch ? 'development' : 'production';
2722
2636
  setNodeEnv(mode);
2723
2637
  let config = resolveConfig(mode);
2724
- console.log(colors.brand(`${callerName} v4.5.0`), colors.cyan(`building for ${mode}...`)), await unpackBuild(config);
2638
+ console.log(colors.brand(`${callerName} v4.6.0`), colors.cyan(`building for ${mode}...`)), await unpackBuild(config);
2725
2639
  },
2726
2640
  dev: async ()=>{
2727
2641
  setUnpackStartTime(performance.now());
@@ -2872,7 +2786,7 @@ function runCLI() {
2872
2786
  logger_logger.clear(), logger_logger.info(`${node_path.basename(file)} changed, restarting server...`), await watcher.close(), await cleanUpBeforeRestart(), startServer(options);
2873
2787
  });
2874
2788
  });
2875
- devCommand.option('-o, --open [url]', 'Open browser on startup').option('--port <port>', 'Specify port').option('--host', 'Expose hostname').action(startServer), cli.help(), cli.version("4.5.0"), cli.parse();
2789
+ devCommand.option('-o, --open [url]', 'Open browser on startup').option('--port <port>', 'Specify port').option('--host', 'Expose hostname').action(startServer), cli.help(), cli.version("4.6.0"), cli.parse();
2876
2790
  }
2877
2791
  var src_CSS_MODULES_NAMED_EXPORT = !1;
2878
- export { ALL_INTERFACES_IPV4, CSS_MODULES_EXPORTS_CONVENTION, CSS_MODULES_LOCAL_IDENT_NAME, DEV_DEFAULT_FILENAME, JSX_REGEX, JS_REGEX, LOCALHOST, NODE_MODULES_REGEX, PROD_DEFAULT_FILENAME, SCRIPT_REGEX, TEMPLATE_CONTENT, addRestartCleaner, applyHtmlTagDescriptors, cleanUpBeforeRestart, clearLine, colors, convertBasicAnsiColors, createChokidar, createUnpack, debounce, defineConfig, emptyDir, ensureDir, esVersionToBrowserslist, external_tinyglobby_glob as glob, findExists, getAddressUrls, getCompiledPkgPath, getCurrentUnpackConfig, getFilesContentHash, getHtmlTemplateOrContent, getIpv4Interfaces, getNodeEnv, getOrSetDefault, getPathInJs, getPort, getTime, getUnpackStartTime, getUserDepPath, getUserDepVersion, globSync, isBoolean, isDebug, isDev, isEmptyDir, isFileExists, isFileSync, isFunction, isNodeVersionAtLeast, isObject, isPlainObject, isRegExp, isString, isUndefined, isWin, launchEditor, loadConfig, loadConfigFromFile, logUpdate, logger_LogColor as LogColor, logger_logger as logger, mergeConfig, normalizePublicPath, openBrowser, pLimit, pathExists, pathToExportIdentifier, prettyTime, printServerUrls, removeDir, renderHtmlTagDescriptor, resolveConfigPath, rspack, runCLI, set, setCurrentUnpackConfig, setDevServer, setNodeEnv, setUnpackStartTime, src_CSS_MODULES_NAMED_EXPORT as CSS_MODULES_NAMED_EXPORT, trackPerformance, utils_isDevServer as isDevServer, utils_isProd as isProd };
2792
+ export { ALL_INTERFACES_IPV4, CSS_MODULES_EXPORTS_CONVENTION, CSS_MODULES_LOCAL_IDENT_NAME, DEV_DEFAULT_FILENAME, JSX_REGEX, JS_REGEX, LOCALHOST, NODE_MODULES_REGEX, PROD_DEFAULT_FILENAME, SCRIPT_REGEX, TEMPLATE_CONTENT, addRestartCleaner, applyHtmlTagDescriptors, cleanUpBeforeRestart, clearLine, colors, convertBasicAnsiColors, createChokidar, createUnpack, debounce, defineConfig, emptyDir, ensureDir, esVersionToBrowserslist, external_tinyglobby_glob as glob, findExists, getAddressUrls, getCompiledPkgPath, getCurrentUnpackConfig, getFilesContentHash, getHtmlTemplateOrContent, getIpv4Interfaces, getNodeEnv, getOrSetDefault, getPathInJs, getPort, getTime, getUnpackStartTime, getUserDepPath, getUserDepVersion, globSync, isBoolean, isDebug, isDev, isEmptyDir, isFileExists, isFileSync, isFunction, isNodeVersionAtLeast, isObject, isPlainObject, isRegExp, isString, isUndefined, isWin, launchEditor, loadConfig, loadConfigFromFile, logUpdate, logger_LogColor as LogColor, logger_logger as logger, normalizePublicPath, openBrowser, pLimit, pathExists, pathToExportIdentifier, prettyTime, printServerUrls, removeDir, renderHtmlTagDescriptor, resolveConfigPath, rspack, runCLI, set, setCurrentUnpackConfig, setDevServer, setNodeEnv, setUnpackStartTime, src_CSS_MODULES_NAMED_EXPORT as CSS_MODULES_NAMED_EXPORT, trackPerformance, utils_isDevServer as isDevServer, utils_isProd as isProd, utils_mergeConfig as mergeConfig };