@rsbuild/core 1.0.1-beta.3 → 1.0.1-beta.4

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.cjs CHANGED
@@ -398,12 +398,12 @@ function formatStats(stats, options = {}) {
398
398
  }
399
399
  return {};
400
400
  }
401
- function isEmptyDir(path17) {
402
- const files = import_node_fs.default.readdirSync(path17);
401
+ function isEmptyDir(path19) {
402
+ const files = import_node_fs.default.readdirSync(path19);
403
403
  return files.length === 0 || files.length === 1 && files[0] === ".git";
404
404
  }
405
- async function pathExists(path17) {
406
- return import_node_fs.default.promises.access(path17).then(() => true).catch(() => false);
405
+ async function pathExists(path19) {
406
+ return import_node_fs.default.promises.access(path19).then(() => true).catch(() => false);
407
407
  }
408
408
  async function isFileExists(file) {
409
409
  return import_node_fs.default.promises.access(file, import_node_fs.default.constants.F_OK).then(() => true).catch(() => false);
@@ -681,9 +681,9 @@ ${import_picocolors2.default.yellow(tips.join("\n"))}`;
681
681
  }
682
682
  return false;
683
683
  };
684
- urlJoin = (base, path17) => {
684
+ urlJoin = (base, path19) => {
685
685
  const fullUrl = new URL(base);
686
- fullUrl.pathname = import_node_path2.posix.join(fullUrl.pathname, path17);
686
+ fullUrl.pathname = import_node_path2.posix.join(fullUrl.pathname, path19);
687
687
  return fullUrl.toString();
688
688
  };
689
689
  canParse = (url2) => {
@@ -794,8 +794,8 @@ var init_mergeConfig = __esm({
794
794
  }
795
795
  return OVERRIDE_PATHS.includes(key);
796
796
  };
797
- merge = (x, y, path17 = "") => {
798
- if (isOverridePath(path17)) {
797
+ merge = (x, y, path19 = "") => {
798
+ if (isOverridePath(path19)) {
799
799
  return y ?? x;
800
800
  }
801
801
  if (x === void 0) {
@@ -817,7 +817,7 @@ var init_mergeConfig = __esm({
817
817
  const merged = {};
818
818
  const keys = /* @__PURE__ */ new Set([...Object.keys(x), ...Object.keys(y)]);
819
819
  for (const key of keys) {
820
- const childPath = path17 ? `${path17}.${key}` : key;
820
+ const childPath = path19 ? `${path19}.${key}` : key;
821
821
  merged[key] = merge(x[key], y[key], childPath);
822
822
  }
823
823
  return merged;
@@ -923,10 +923,10 @@ async function watchFiles(files) {
923
923
  }
924
924
  async function loadConfig({
925
925
  cwd = process.cwd(),
926
- path: path17,
926
+ path: path19,
927
927
  envMode
928
928
  } = {}) {
929
- const configFilePath = resolveConfigPath(cwd, path17);
929
+ const configFilePath = resolveConfigPath(cwd, path19);
930
930
  if (!configFilePath) {
931
931
  return {
932
932
  content: {},
@@ -1460,23 +1460,6 @@ function getHTMLPathByEntry(entryName, config) {
1460
1460
  const filename = config.html.outputStructure === "flat" ? `${entryName}.html` : `${entryName}/index.html`;
1461
1461
  return removeLeadingSlash(`${config.output.distPath.html}/${filename}`);
1462
1462
  }
1463
- function applyTransformPlugin(chain, transformer) {
1464
- const name = "RsbuildTransformPlugin";
1465
- if (chain.plugins.get(name)) {
1466
- return;
1467
- }
1468
- class RsbuildTransformPlugin {
1469
- apply(compiler) {
1470
- compiler.__rsbuildTransformer = transformer;
1471
- compiler.hooks.thisCompilation.tap(name, (compilation) => {
1472
- compilation.hooks.childCompiler.tap(name, (childCompiler) => {
1473
- childCompiler.__rsbuildTransformer = transformer;
1474
- });
1475
- });
1476
- }
1477
- }
1478
- chain.plugin(name).use(RsbuildTransformPlugin);
1479
- }
1480
1463
  function getPluginAPI({
1481
1464
  context,
1482
1465
  pluginManager
@@ -1523,6 +1506,40 @@ function getPluginAPI({
1523
1506
  };
1524
1507
  let transformId = 0;
1525
1508
  const transformer = {};
1509
+ const processAssetsFns = [];
1510
+ hooks.modifyBundlerChain.tap((chain, { target, environment }) => {
1511
+ const pluginName = "RsbuildCorePlugin";
1512
+ class RsbuildCorePlugin {
1513
+ apply(compiler) {
1514
+ compiler.__rsbuildTransformer = transformer;
1515
+ compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
1516
+ compilation.hooks.childCompiler.tap(pluginName, (childCompiler) => {
1517
+ childCompiler.__rsbuildTransformer = transformer;
1518
+ });
1519
+ });
1520
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
1521
+ for (const { descriptor, handler } of processAssetsFns) {
1522
+ if (descriptor.targets && !descriptor.targets.includes(target)) {
1523
+ return;
1524
+ }
1525
+ compilation.hooks.processAssets.tapPromise(
1526
+ {
1527
+ name: pluginName,
1528
+ stage: mapProcessAssetsStage(compiler, descriptor.stage)
1529
+ },
1530
+ async (assets) => handler({
1531
+ assets,
1532
+ compiler,
1533
+ compilation,
1534
+ environment
1535
+ })
1536
+ );
1537
+ }
1538
+ });
1539
+ }
1540
+ }
1541
+ chain.plugin(pluginName).use(RsbuildCorePlugin);
1542
+ });
1526
1543
  const transform = (descriptor, handler) => {
1527
1544
  const id = `rsbuild-transform-${transformId++}`;
1528
1545
  transformer[id] = handler;
@@ -1542,10 +1559,15 @@ function getPluginAPI({
1542
1559
  }
1543
1560
  const loaderName = descriptor.raw ? "transformRawLoader.cjs" : "transformLoader.cjs";
1544
1561
  const loaderPath = (0, import_node_path7.join)(LOADER_PATH, loaderName);
1545
- rule.use(id).loader(loaderPath).options({ id });
1546
- applyTransformPlugin(chain, transformer);
1562
+ rule.use(id).loader(loaderPath).options({
1563
+ id,
1564
+ getEnvironment: () => environment
1565
+ });
1547
1566
  });
1548
1567
  };
1568
+ const processAssets = (descriptor, handler) => {
1569
+ processAssetsFns.push({ descriptor, handler });
1570
+ };
1549
1571
  process.on("exit", () => {
1550
1572
  hooks.onExit.call();
1551
1573
  });
@@ -1554,6 +1576,7 @@ function getPluginAPI({
1554
1576
  expose,
1555
1577
  transform,
1556
1578
  useExposed,
1579
+ processAssets,
1557
1580
  getRsbuildConfig,
1558
1581
  getNormalizedConfig,
1559
1582
  isPluginExists: pluginManager.isPluginExists,
@@ -1578,7 +1601,7 @@ function getPluginAPI({
1578
1601
  modifyEnvironmentConfig: hooks.modifyEnvironmentConfig.tap
1579
1602
  };
1580
1603
  }
1581
- var import_node_path7;
1604
+ var import_node_path7, mapProcessAssetsStage;
1582
1605
  var init_initPlugins = __esm({
1583
1606
  "src/initPlugins.ts"() {
1584
1607
  "use strict";
@@ -1586,6 +1609,45 @@ var init_initPlugins = __esm({
1586
1609
  init_constants();
1587
1610
  init_createContext();
1588
1611
  init_helpers();
1612
+ mapProcessAssetsStage = (compiler, stage) => {
1613
+ const { Compilation } = compiler.webpack;
1614
+ switch (stage) {
1615
+ case "additional":
1616
+ return Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL;
1617
+ case "pre-process":
1618
+ return Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS;
1619
+ case "derived":
1620
+ return Compilation.PROCESS_ASSETS_STAGE_DERIVED;
1621
+ case "additions":
1622
+ return Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;
1623
+ case "none":
1624
+ return Compilation.PROCESS_ASSETS_STAGE_NONE;
1625
+ case "optimize":
1626
+ return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE;
1627
+ case "optimize-count":
1628
+ return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COUNT;
1629
+ case "optimize-compatibility":
1630
+ return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY;
1631
+ case "optimize-size":
1632
+ return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE;
1633
+ case "dev-tooling":
1634
+ return Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING;
1635
+ case "optimize-inline":
1636
+ return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE;
1637
+ case "summarize":
1638
+ return Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
1639
+ case "optimize-hash":
1640
+ return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH;
1641
+ case "optimize-transfer":
1642
+ return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER;
1643
+ case "analyse":
1644
+ return Compilation.PROCESS_ASSETS_STAGE_ANALYSE;
1645
+ case "report":
1646
+ return Compilation.PROCESS_ASSETS_STAGE_REPORT;
1647
+ default:
1648
+ throw new Error(`Invalid process assets stage: ${stage}`);
1649
+ }
1650
+ };
1589
1651
  }
1590
1652
  });
1591
1653
 
@@ -1602,33 +1664,33 @@ async function createContextByConfig(options, bundlerType) {
1602
1664
  const rootPath = cwd;
1603
1665
  const cachePath = (0, import_node_path8.join)(rootPath, "node_modules", ".cache");
1604
1666
  return {
1605
- version: "1.0.1-beta.3",
1667
+ version: "1.0.1-beta.4",
1606
1668
  rootPath,
1607
1669
  distPath: "",
1608
1670
  cachePath,
1609
1671
  bundlerType
1610
1672
  };
1611
1673
  }
1612
- async function getBrowserslist(path17) {
1674
+ async function getBrowserslist(path19) {
1613
1675
  const env = process.env.NODE_ENV;
1614
- const cacheKey = path17 + env;
1676
+ const cacheKey = path19 + env;
1615
1677
  if (browsersListCache.has(cacheKey)) {
1616
1678
  return browsersListCache.get(cacheKey);
1617
1679
  }
1618
- const result = import_browserslist.default.loadConfig({ path: path17, env });
1680
+ const result = import_browserslist.default.loadConfig({ path: path19, env });
1619
1681
  if (result) {
1620
1682
  browsersListCache.set(cacheKey, result);
1621
1683
  return result;
1622
1684
  }
1623
1685
  return null;
1624
1686
  }
1625
- async function getBrowserslistByEnvironment(path17, config) {
1687
+ async function getBrowserslistByEnvironment(path19, config) {
1626
1688
  const { target, overrideBrowserslist } = config.output;
1627
1689
  if (Array.isArray(overrideBrowserslist)) {
1628
1690
  return overrideBrowserslist;
1629
1691
  }
1630
1692
  if (target === "web" || target === "web-worker") {
1631
- const browserslistrc = await getBrowserslist(path17);
1693
+ const browserslistrc = await getBrowserslist(path19);
1632
1694
  if (browserslistrc) {
1633
1695
  return browserslistrc;
1634
1696
  }
@@ -2277,8 +2339,6 @@ var init_configChain = __esm({
2277
2339
  MANIFEST: "webpack-manifest",
2278
2340
  /** ForkTsCheckerWebpackPlugin */
2279
2341
  TS_CHECKER: "ts-checker",
2280
- /** InlineChunkHtmlPlugin */
2281
- INLINE_HTML: "inline-html",
2282
2342
  /** WebpackBundleAnalyzer */
2283
2343
  BUNDLE_ANALYZER: "bundle-analyze",
2284
2344
  /** ModuleFederationPlugin */
@@ -3478,8 +3538,8 @@ var init_getDevMiddlewares = __esm({
3478
3538
  }
3479
3539
  middlewares.push((req, res, next) => {
3480
3540
  res.setHeader("Access-Control-Allow-Origin", "*");
3481
- const path17 = req.url ? import_node_url3.default.parse(req.url).pathname : "";
3482
- if (path17?.includes("hot-update")) {
3541
+ const path19 = req.url ? import_node_url3.default.parse(req.url).pathname : "";
3542
+ if (path19?.includes("hot-update")) {
3483
3543
  res.setHeader("Access-Control-Allow-Credentials", "false");
3484
3544
  }
3485
3545
  const confHeaders = server.headers;
@@ -3506,7 +3566,7 @@ var init_getDevMiddlewares = __esm({
3506
3566
  compileMiddlewareAPI.onUpgrade.bind(compileMiddlewareAPI)
3507
3567
  );
3508
3568
  middlewares.push((req, res, next) => {
3509
- if (req.url?.endsWith(".hot-update.json")) {
3569
+ if (req.url?.endsWith(".hot-update.json") && req.method !== "OPTIONS") {
3510
3570
  res.statusCode = 404;
3511
3571
  res.end();
3512
3572
  } else {
@@ -5876,6 +5936,7 @@ var init_HtmlBasicPlugin = __esm({
5876
5936
  bodyTags: bodyTags.map(formatBasicTag)
5877
5937
  };
5878
5938
  const modified = this.modifyTagsFn ? await this.modifyTagsFn(tags, {
5939
+ compiler,
5879
5940
  compilation,
5880
5941
  assetPrefix: data.publicPath,
5881
5942
  filename: data.outputName,
@@ -5897,76 +5958,6 @@ var init_HtmlBasicPlugin = __esm({
5897
5958
  }
5898
5959
  });
5899
5960
 
5900
- // src/rspack/HtmlAppIconPlugin.ts
5901
- var HtmlAppIconPlugin_exports = {};
5902
- __export(HtmlAppIconPlugin_exports, {
5903
- HtmlAppIconPlugin: () => HtmlAppIconPlugin
5904
- });
5905
- var import_node_fs7, import_node_path24, HtmlAppIconPlugin;
5906
- var init_HtmlAppIconPlugin = __esm({
5907
- "src/rspack/HtmlAppIconPlugin.ts"() {
5908
- "use strict";
5909
- import_node_fs7 = __toESM(require("fs"));
5910
- import_node_path24 = require("path");
5911
- init_helpers();
5912
- init_pluginHelper();
5913
- HtmlAppIconPlugin = class {
5914
- constructor(options) {
5915
- __publicField(this, "name");
5916
- __publicField(this, "distDir");
5917
- __publicField(this, "iconPath");
5918
- this.name = "HtmlAppIconPlugin";
5919
- this.distDir = options.distDir;
5920
- this.iconPath = options.iconPath;
5921
- }
5922
- apply(compiler) {
5923
- if (!import_node_fs7.default.existsSync(this.iconPath)) {
5924
- throw new Error(
5925
- `[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
5926
- );
5927
- }
5928
- const iconRelativePath = import_node_path24.posix.join(this.distDir, (0, import_node_path24.basename)(this.iconPath));
5929
- compiler.hooks.compilation.tap(this.name, (compilation) => {
5930
- getHTMLPlugin().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
5931
- data.headTags.unshift({
5932
- tagName: "link",
5933
- voidTag: true,
5934
- attributes: {
5935
- rel: "apple-touch-icon",
5936
- sizes: "180*180",
5937
- href: ensureAssetPrefix(
5938
- iconRelativePath,
5939
- compilation.outputOptions.publicPath
5940
- )
5941
- },
5942
- meta: {}
5943
- });
5944
- return data;
5945
- });
5946
- });
5947
- compiler.hooks.thisCompilation.tap(
5948
- this.name,
5949
- (compilation) => {
5950
- compilation.hooks.processAssets.tap(
5951
- {
5952
- name: this.name,
5953
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
5954
- },
5955
- () => {
5956
- const source = import_node_fs7.default.readFileSync(this.iconPath);
5957
- compilation.emitAsset(
5958
- iconRelativePath,
5959
- new compiler.webpack.sources.RawSource(source, false)
5960
- );
5961
- }
5962
- );
5963
- }
5964
- );
5965
- }
5966
- };
5967
- }
5968
- });
5969
-
5970
5961
  // src/plugins/html.ts
5971
5962
  var html_exports = {};
5972
5963
  __export(html_exports, {
@@ -5999,7 +5990,7 @@ async function getTemplate(entryName, config, rootPath) {
5999
5990
  templateContent: getDefaultTemplateContent(config.html.mountId)
6000
5991
  };
6001
5992
  }
6002
- const absolutePath = (0, import_node_path25.isAbsolute)(templatePath) ? templatePath : import_node_path25.default.resolve(rootPath, templatePath);
5993
+ const absolutePath = (0, import_node_path24.isAbsolute)(templatePath) ? templatePath : import_node_path24.default.resolve(rootPath, templatePath);
6003
5994
  if (!existTemplatePath.has(absolutePath)) {
6004
5995
  if (!await isFileExists(absolutePath)) {
6005
5996
  throw new Error(
@@ -6010,7 +6001,7 @@ async function getTemplate(entryName, config, rootPath) {
6010
6001
  }
6011
6002
  existTemplatePath.add(absolutePath);
6012
6003
  }
6013
- const templateContent = await import_node_fs8.default.promises.readFile(absolutePath, "utf-8");
6004
+ const templateContent = await import_node_fs7.default.promises.readFile(absolutePath, "utf-8");
6014
6005
  return {
6015
6006
  templatePath: absolutePath,
6016
6007
  templateContent
@@ -6089,12 +6080,12 @@ function getChunks(entryName, entryValue) {
6089
6080
  }
6090
6081
  return chunks;
6091
6082
  }
6092
- var import_node_fs8, import_node_path25, import_picocolors12, getDefaultTemplateContent, existTemplatePath, getTagConfig, pluginHtml;
6083
+ var import_node_fs7, import_node_path24, import_picocolors12, getDefaultTemplateContent, existTemplatePath, getTagConfig, pluginHtml;
6093
6084
  var init_html = __esm({
6094
6085
  "src/plugins/html.ts"() {
6095
6086
  "use strict";
6096
- import_node_fs8 = __toESM(require("fs"));
6097
- import_node_path25 = __toESM(require("path"));
6087
+ import_node_fs7 = __toESM(require("fs"));
6088
+ import_node_path24 = __toESM(require("path"));
6098
6089
  import_picocolors12 = __toESM(require("../compiled/picocolors/index.js"));
6099
6090
  init_dist();
6100
6091
  init_helpers();
@@ -6193,17 +6184,11 @@ var init_html = __esm({
6193
6184
  const { HtmlBasicPlugin: HtmlBasicPlugin2 } = await Promise.resolve().then(() => (init_HtmlBasicPlugin(), HtmlBasicPlugin_exports));
6194
6185
  chain.plugin(CHAIN_ID2.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin2, [htmlInfoMap, environment, modifyTagsFn]);
6195
6186
  if (config.html) {
6196
- const { appIcon, crossorigin } = config.html;
6187
+ const { crossorigin } = config.html;
6197
6188
  if (crossorigin) {
6198
6189
  const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
6199
6190
  chain.output.crossOriginLoading(formattedCrossorigin);
6200
6191
  }
6201
- if (appIcon) {
6202
- const { HtmlAppIconPlugin: HtmlAppIconPlugin2 } = await Promise.resolve().then(() => (init_HtmlAppIconPlugin(), HtmlAppIconPlugin_exports));
6203
- const distDir = config.output.distPath.image;
6204
- const iconPath = import_node_path25.default.isAbsolute(appIcon) ? appIcon : import_node_path25.default.join(api.context.rootPath, appIcon);
6205
- chain.plugin(CHAIN_ID2.PLUGIN.APP_ICON).use(HtmlAppIconPlugin2, [{ iconPath, distDir }]);
6206
- }
6207
6192
  }
6208
6193
  }
6209
6194
  );
@@ -6230,6 +6215,88 @@ var init_html = __esm({
6230
6215
  }
6231
6216
  });
6232
6217
 
6218
+ // src/plugins/appIcon.ts
6219
+ var appIcon_exports = {};
6220
+ __export(appIcon_exports, {
6221
+ pluginAppIcon: () => pluginAppIcon
6222
+ });
6223
+ var import_node_fs8, import_node_path25, pluginAppIcon;
6224
+ var init_appIcon = __esm({
6225
+ "src/plugins/appIcon.ts"() {
6226
+ "use strict";
6227
+ import_node_fs8 = __toESM(require("fs"));
6228
+ import_node_path25 = __toESM(require("path"));
6229
+ init_helpers();
6230
+ pluginAppIcon = () => ({
6231
+ name: "rsbuild:app-icon",
6232
+ setup(api) {
6233
+ const cache = /* @__PURE__ */ new Map();
6234
+ const getIconPath = ({ config, name }) => {
6235
+ const { appIcon } = config.html;
6236
+ if (!appIcon) {
6237
+ return;
6238
+ }
6239
+ const cached = cache.get(name);
6240
+ if (cached) {
6241
+ cached;
6242
+ }
6243
+ const distDir = config.output.distPath.image;
6244
+ const absolutePath = import_node_path25.default.isAbsolute(appIcon) ? appIcon : import_node_path25.default.join(api.context.rootPath, appIcon);
6245
+ const relativePath = import_node_path25.default.posix.join(
6246
+ distDir,
6247
+ import_node_path25.default.basename(absolutePath)
6248
+ );
6249
+ const paths = {
6250
+ absolutePath,
6251
+ relativePath
6252
+ };
6253
+ cache.set(name, paths);
6254
+ return paths;
6255
+ };
6256
+ api.processAssets(
6257
+ { stage: "additional" },
6258
+ async ({ compiler, compilation, environment }) => {
6259
+ const iconPath = getIconPath(environment);
6260
+ if (!iconPath) {
6261
+ return;
6262
+ }
6263
+ if (!await isFileExists(iconPath.absolutePath)) {
6264
+ throw new Error(
6265
+ `[rsbuild:app-icon] Can not find the app icon, please check if the '${iconPath.relativePath}' file exists'.`
6266
+ );
6267
+ }
6268
+ const source = await import_node_fs8.default.promises.readFile(iconPath.absolutePath);
6269
+ compilation.emitAsset(
6270
+ iconPath.relativePath,
6271
+ new compiler.webpack.sources.RawSource(source, false)
6272
+ );
6273
+ }
6274
+ );
6275
+ api.modifyHTMLTags(
6276
+ ({ headTags, bodyTags }, { environment, compilation }) => {
6277
+ const iconPath = getIconPath(environment);
6278
+ if (!iconPath) {
6279
+ return { headTags, bodyTags };
6280
+ }
6281
+ headTags.unshift({
6282
+ tag: "link",
6283
+ attrs: {
6284
+ rel: "apple-touch-icon",
6285
+ sizes: "180*180",
6286
+ href: ensureAssetPrefix(
6287
+ iconPath.relativePath,
6288
+ compilation.outputOptions.publicPath
6289
+ )
6290
+ }
6291
+ });
6292
+ return { headTags, bodyTags };
6293
+ }
6294
+ );
6295
+ }
6296
+ });
6297
+ }
6298
+ });
6299
+
6233
6300
  // src/plugins/wasm.ts
6234
6301
  var wasm_exports = {};
6235
6302
  __export(wasm_exports, {
@@ -6304,15 +6371,15 @@ var init_nodeAddons = __esm({
6304
6371
  "use strict";
6305
6372
  import_node_path27 = __toESM(require("path"));
6306
6373
  getFilename2 = (resourcePath) => {
6307
- let basename2 = "";
6374
+ let basename = "";
6308
6375
  if (resourcePath) {
6309
6376
  const parsed = import_node_path27.default.parse(resourcePath);
6310
6377
  if (parsed.dir) {
6311
- basename2 = parsed.name;
6378
+ basename = parsed.name;
6312
6379
  }
6313
6380
  }
6314
- if (basename2) {
6315
- return `${basename2}.node`;
6381
+ if (basename) {
6382
+ return `${basename}.node`;
6316
6383
  }
6317
6384
  return null;
6318
6385
  };
@@ -7055,222 +7122,188 @@ var init_open = __esm({
7055
7122
  }
7056
7123
  });
7057
7124
 
7058
- // src/rspack/InlineChunkHtmlPlugin.ts
7059
- var InlineChunkHtmlPlugin_exports = {};
7060
- __export(InlineChunkHtmlPlugin_exports, {
7061
- InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
7062
- });
7063
- var import_node_path29, InlineChunkHtmlPlugin;
7064
- var init_InlineChunkHtmlPlugin = __esm({
7065
- "src/rspack/InlineChunkHtmlPlugin.ts"() {
7066
- "use strict";
7067
- import_node_path29 = require("path");
7068
- init_helpers();
7069
- init_pluginHelper();
7070
- InlineChunkHtmlPlugin = class {
7071
- constructor({
7072
- styleTests,
7073
- scriptTests,
7074
- distPath
7075
- }) {
7076
- __publicField(this, "name");
7077
- __publicField(this, "styleTests");
7078
- __publicField(this, "scriptTests");
7079
- __publicField(this, "distPath");
7080
- __publicField(this, "inlinedAssets");
7081
- this.name = "InlineChunkHtmlPlugin";
7082
- this.styleTests = styleTests;
7083
- this.scriptTests = scriptTests;
7084
- this.distPath = distPath;
7085
- this.inlinedAssets = /* @__PURE__ */ new Set();
7086
- }
7087
- /**
7088
- * If we inlined the chunk to HTML,we should update the value of sourceMappingURL,
7089
- * because the relative path of source code has been changed.
7090
- * @param source
7091
- */
7092
- updateSourceMappingURL({
7093
- source,
7094
- compilation,
7095
- publicPath,
7096
- type
7097
- }) {
7098
- const { devtool } = compilation.options;
7099
- if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
7100
- !devtool.includes("inline") && source.includes("# sourceMappingURL")) {
7101
- const prefix = addTrailingSlash(
7102
- (0, import_node_path29.join)(publicPath, this.distPath[type] || "")
7103
- );
7104
- return source.replace(
7105
- /# sourceMappingURL=/,
7106
- `# sourceMappingURL=${prefix}`
7107
- );
7108
- }
7109
- return source;
7110
- }
7111
- matchTests(name, source, tests) {
7112
- return tests.some((test) => {
7113
- if (isFunction(test)) {
7114
- const size = source.length;
7115
- return test({ name, size });
7116
- }
7117
- return test.exec(name);
7118
- });
7119
- }
7120
- getInlinedScriptTag(publicPath, tag, compilation) {
7121
- const { assets } = compilation;
7122
- if (!(tag?.attributes.src && typeof tag.attributes.src === "string")) {
7123
- return tag;
7124
- }
7125
- const { src, ...otherAttrs } = tag.attributes;
7126
- const scriptName = publicPath ? src.replace(publicPath, "") : src;
7127
- const asset = assets[scriptName];
7128
- if (asset == null) {
7129
- return tag;
7130
- }
7131
- const source = asset.source().toString();
7132
- const shouldInline = this.matchTests(scriptName, source, this.scriptTests);
7133
- if (!shouldInline) {
7134
- return tag;
7135
- }
7136
- const ret = {
7137
- tagName: "script",
7138
- innerHTML: this.updateSourceMappingURL({
7139
- source,
7140
- compilation,
7141
- publicPath,
7142
- type: "js"
7143
- }),
7144
- attributes: {
7145
- ...otherAttrs
7146
- },
7147
- closeTag: true
7148
- };
7149
- this.inlinedAssets.add(scriptName);
7150
- return ret;
7151
- }
7152
- getInlinedCSSTag(publicPath, tag, compilation) {
7153
- const { assets } = compilation;
7154
- if (!(tag.attributes.href && typeof tag.attributes.href === "string")) {
7155
- return tag;
7156
- }
7157
- const linkName = publicPath ? tag.attributes.href.replace(publicPath, "") : tag.attributes.href;
7158
- const asset = assets[linkName];
7159
- if (asset == null) {
7160
- return tag;
7161
- }
7162
- const source = asset.source().toString();
7163
- const shouldInline = this.matchTests(linkName, source, this.styleTests);
7164
- if (!shouldInline) {
7165
- return tag;
7166
- }
7167
- const ret = {
7168
- tagName: "style",
7169
- innerHTML: this.updateSourceMappingURL({
7170
- source,
7171
- compilation,
7172
- publicPath,
7173
- type: "css"
7174
- }),
7175
- closeTag: true
7176
- };
7177
- this.inlinedAssets.add(linkName);
7178
- return ret;
7179
- }
7180
- getInlinedTag(publicPath, tag, compilation) {
7181
- if (tag.tagName === "script") {
7182
- return this.getInlinedScriptTag(
7183
- publicPath,
7184
- tag,
7185
- compilation
7186
- );
7187
- }
7188
- if (tag.tagName === "link" && tag.attributes && tag.attributes.rel === "stylesheet") {
7189
- return this.getInlinedCSSTag(
7190
- publicPath,
7191
- tag,
7192
- compilation
7193
- );
7194
- }
7195
- return tag;
7196
- }
7197
- apply(compiler) {
7198
- compiler.hooks.compilation.tap(this.name, (compilation) => {
7199
- const publicPath = getPublicPathFromCompiler(compiler);
7200
- const tagFunction = (tag) => this.getInlinedTag(publicPath, tag, compilation);
7201
- const hooks = getHTMLPlugin().getHooks(compilation);
7202
- hooks.alterAssetTagGroups.tap(this.name, (assets) => {
7203
- assets.headTags = assets.headTags.map(tagFunction);
7204
- assets.bodyTags = assets.bodyTags.map(tagFunction);
7205
- return assets;
7206
- });
7207
- compilation.hooks.processAssets.tap(
7208
- {
7209
- name: "InlineChunkHtmlPlugin",
7210
- /**
7211
- * Remove marked inline assets in summarize stage,
7212
- * which should be later than the emitting of html-rspack-plugin
7213
- */
7214
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
7215
- },
7216
- () => {
7217
- const { devtool } = compiler.options;
7218
- for (const name of this.inlinedAssets) {
7219
- if (devtool === "hidden-source-map") {
7220
- compilation.deleteAsset(name);
7221
- } else {
7222
- delete compilation.assets[name];
7223
- }
7224
- }
7225
- this.inlinedAssets.clear();
7226
- }
7227
- );
7228
- });
7229
- }
7230
- };
7231
- }
7232
- });
7233
-
7234
7125
  // src/plugins/inlineChunk.ts
7235
7126
  var inlineChunk_exports = {};
7236
7127
  __export(inlineChunk_exports, {
7237
7128
  pluginInlineChunk: () => pluginInlineChunk
7238
7129
  });
7239
- var pluginInlineChunk;
7130
+ function updateSourceMappingURL({
7131
+ source,
7132
+ compilation,
7133
+ publicPath,
7134
+ type,
7135
+ config
7136
+ }) {
7137
+ const { devtool } = compilation.options;
7138
+ if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
7139
+ !devtool.includes("inline") && source.includes("# sourceMappingURL")) {
7140
+ const prefix = addTrailingSlash(
7141
+ import_node_path29.default.join(publicPath, config.output.distPath[type] || "")
7142
+ );
7143
+ return source.replace(
7144
+ /# sourceMappingURL=/,
7145
+ `# sourceMappingURL=${prefix}`
7146
+ );
7147
+ }
7148
+ return source;
7149
+ }
7150
+ function matchTests(name, source, tests) {
7151
+ return tests.some((test) => {
7152
+ if (isFunction(test)) {
7153
+ const size = source.length;
7154
+ return test({ name, size });
7155
+ }
7156
+ return test.exec(name);
7157
+ });
7158
+ }
7159
+ var import_node_path29, pluginInlineChunk;
7240
7160
  var init_inlineChunk = __esm({
7241
7161
  "src/plugins/inlineChunk.ts"() {
7242
7162
  "use strict";
7163
+ import_node_path29 = __toESM(require("path"));
7243
7164
  init_constants();
7244
7165
  init_helpers();
7245
7166
  pluginInlineChunk = () => ({
7246
7167
  name: "rsbuild:inline-chunk",
7247
7168
  setup(api) {
7248
- api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID2, isDev: isDev2, environment }) => {
7249
- const { htmlPaths, config } = environment;
7250
- if (Object.keys(htmlPaths).length === 0 || isDev2) {
7251
- return;
7169
+ const inlinedAssets = /* @__PURE__ */ new Set();
7170
+ const getInlinedScriptTag = (publicPath, tag, compilation, scriptTests, config) => {
7171
+ const { assets } = compilation;
7172
+ if (!(tag.attrs?.src && typeof tag.attrs.src === "string")) {
7173
+ return tag;
7252
7174
  }
7253
- const { InlineChunkHtmlPlugin: InlineChunkHtmlPlugin2 } = await Promise.resolve().then(() => (init_InlineChunkHtmlPlugin(), InlineChunkHtmlPlugin_exports));
7254
- const { inlineStyles, inlineScripts } = config.output;
7255
- const scriptTests = [];
7256
- const styleTests = [];
7257
- if (inlineScripts) {
7258
- scriptTests.push(inlineScripts === true ? JS_REGEX : inlineScripts);
7175
+ const { src, ...otherAttrs } = tag.attrs;
7176
+ const scriptName = publicPath ? src.replace(publicPath, "") : src;
7177
+ const asset = assets[scriptName];
7178
+ if (asset == null) {
7179
+ return tag;
7259
7180
  }
7260
- if (inlineStyles) {
7261
- styleTests.push(inlineStyles === true ? CSS_REGEX : inlineStyles);
7181
+ const source = asset.source().toString();
7182
+ const shouldInline = matchTests(scriptName, source, scriptTests);
7183
+ if (!shouldInline) {
7184
+ return tag;
7262
7185
  }
7263
- if (!scriptTests.length && !styleTests.length) {
7264
- return;
7186
+ const ret = {
7187
+ tag: "script",
7188
+ children: updateSourceMappingURL({
7189
+ source,
7190
+ compilation,
7191
+ publicPath,
7192
+ type: "js",
7193
+ config
7194
+ }),
7195
+ attrs: {
7196
+ ...otherAttrs
7197
+ }
7198
+ };
7199
+ inlinedAssets.add(scriptName);
7200
+ return ret;
7201
+ };
7202
+ const getInlinedCSSTag = (publicPath, tag, compilation, styleTests, config) => {
7203
+ const { assets } = compilation;
7204
+ if (!(tag.attrs?.href && typeof tag.attrs.href === "string")) {
7205
+ return tag;
7265
7206
  }
7266
- chain.plugin(CHAIN_ID2.PLUGIN.INLINE_HTML).before(CHAIN_ID2.PLUGIN.HTML_BASIC).use(InlineChunkHtmlPlugin2, [
7267
- {
7268
- styleTests,
7207
+ const linkName = publicPath ? tag.attrs.href.replace(publicPath, "") : tag.attrs.href;
7208
+ const asset = assets[linkName];
7209
+ if (asset == null) {
7210
+ return tag;
7211
+ }
7212
+ const source = asset.source().toString();
7213
+ const shouldInline = matchTests(linkName, source, styleTests);
7214
+ if (!shouldInline) {
7215
+ return tag;
7216
+ }
7217
+ const ret = {
7218
+ tag: "style",
7219
+ children: updateSourceMappingURL({
7220
+ source,
7221
+ compilation,
7222
+ publicPath,
7223
+ type: "css",
7224
+ config
7225
+ })
7226
+ };
7227
+ inlinedAssets.add(linkName);
7228
+ return ret;
7229
+ };
7230
+ const getInlinedTag = (publicPath, tag, compilation, scriptTests, styleTests, config) => {
7231
+ if (tag.tag === "script") {
7232
+ return getInlinedScriptTag(
7233
+ publicPath,
7234
+ tag,
7235
+ compilation,
7269
7236
  scriptTests,
7270
- distPath: pick(config.output.distPath, ["js", "css"])
7237
+ config
7238
+ );
7239
+ }
7240
+ if (tag.tag === "link" && tag.attrs && tag.attrs.rel === "stylesheet") {
7241
+ return getInlinedCSSTag(
7242
+ publicPath,
7243
+ tag,
7244
+ compilation,
7245
+ styleTests,
7246
+ config
7247
+ );
7248
+ }
7249
+ return tag;
7250
+ };
7251
+ api.processAssets(
7252
+ {
7253
+ /**
7254
+ * Remove marked inline assets in summarize stage,
7255
+ * which should be later than the emitting of html-rspack-plugin
7256
+ */
7257
+ stage: "summarize"
7258
+ },
7259
+ ({ compiler, compilation }) => {
7260
+ if (inlinedAssets.size === 0) {
7261
+ return;
7271
7262
  }
7272
- ]);
7273
- });
7263
+ const { devtool } = compiler.options;
7264
+ for (const name of inlinedAssets) {
7265
+ if (devtool === "hidden-source-map") {
7266
+ compilation.deleteAsset(name);
7267
+ } else {
7268
+ delete compilation.assets[name];
7269
+ }
7270
+ }
7271
+ inlinedAssets.clear();
7272
+ }
7273
+ );
7274
+ api.modifyHTMLTags(
7275
+ ({ headTags, bodyTags }, { compiler, compilation, environment }) => {
7276
+ const { htmlPaths, config } = environment;
7277
+ if (isDev() || Object.keys(htmlPaths).length === 0) {
7278
+ return { headTags, bodyTags };
7279
+ }
7280
+ const { inlineStyles, inlineScripts } = config.output;
7281
+ const scriptTests = [];
7282
+ const styleTests = [];
7283
+ if (inlineScripts) {
7284
+ scriptTests.push(inlineScripts === true ? JS_REGEX : inlineScripts);
7285
+ }
7286
+ if (inlineStyles) {
7287
+ styleTests.push(inlineStyles === true ? CSS_REGEX : inlineStyles);
7288
+ }
7289
+ if (!scriptTests.length && !styleTests.length) {
7290
+ return { headTags, bodyTags };
7291
+ }
7292
+ const publicPath = getPublicPathFromCompiler(compiler);
7293
+ const updateTag = (tag) => getInlinedTag(
7294
+ publicPath,
7295
+ tag,
7296
+ compilation,
7297
+ scriptTests,
7298
+ styleTests,
7299
+ environment.config
7300
+ );
7301
+ return {
7302
+ headTags: headTags.map(updateTag),
7303
+ bodyTags: bodyTags.map(updateTag)
7304
+ };
7305
+ }
7306
+ );
7274
7307
  }
7275
7308
  });
7276
7309
  }
@@ -7298,10 +7331,10 @@ var init_rsdoctor = __esm({
7298
7331
  const packageName = isRspack ? "@rsdoctor/rspack-plugin" : "@rsdoctor/webpack-plugin";
7299
7332
  let module2;
7300
7333
  try {
7301
- const path17 = require.resolve(packageName, {
7334
+ const path19 = require.resolve(packageName, {
7302
7335
  paths: [api.context.rootPath]
7303
7336
  });
7304
- module2 = await import(path17);
7337
+ module2 = await import(path19);
7305
7338
  } catch (err) {
7306
7339
  import_rslog.logger.warn(
7307
7340
  `\`process.env.RSDOCTOR\` enabled, please install ${import_picocolors13.default.bold(import_picocolors13.default.yellow(packageName))} package.`
@@ -8289,57 +8322,35 @@ var init_sri = __esm({
8289
8322
  }
8290
8323
  return replacedHtml;
8291
8324
  };
8292
- class SriReplaceIntegrityPlugin {
8293
- constructor(algorithm) {
8294
- __publicField(this, "algorithm");
8295
- this.algorithm = algorithm;
8296
- }
8297
- apply(compiler) {
8298
- compiler.hooks.compilation.tap(
8299
- "SriReplaceIntegrityPlugin",
8300
- (compilation) => {
8301
- compilation.hooks.processAssets.tapPromise(
8302
- {
8303
- name: "SriReplaceIntegrityPlugin",
8304
- // use to final stage to get the final asset content
8305
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
8306
- },
8307
- async (assets) => {
8308
- const integrityCache = /* @__PURE__ */ new Map();
8309
- for (const asset of Object.keys(assets)) {
8310
- if (!HTML_REGEX.test(asset)) {
8311
- continue;
8312
- }
8313
- const htmlContent = assets[asset].source();
8314
- if (!htmlContent.includes(placeholder)) {
8315
- continue;
8316
- }
8317
- assets[asset] = new compiler.webpack.sources.RawSource(
8318
- replaceIntegrity(
8319
- htmlContent,
8320
- assets,
8321
- this.algorithm,
8322
- integrityCache
8323
- )
8324
- );
8325
- }
8326
- }
8327
- );
8325
+ api.processAssets(
8326
+ {
8327
+ // use to final stage to get the final asset content
8328
+ stage: "report"
8329
+ },
8330
+ ({ assets, compiler, environment }) => {
8331
+ const { htmlPaths } = environment;
8332
+ if (Object.keys(htmlPaths).length === 0) {
8333
+ return;
8334
+ }
8335
+ const algorithm = getAlgorithm(environment);
8336
+ if (!algorithm) {
8337
+ return;
8338
+ }
8339
+ const integrityCache = /* @__PURE__ */ new Map();
8340
+ for (const asset of Object.keys(assets)) {
8341
+ if (!HTML_REGEX.test(asset)) {
8342
+ continue;
8328
8343
  }
8329
- );
8330
- }
8331
- }
8332
- api.modifyBundlerChain((chain, { environment }) => {
8333
- const { htmlPaths } = environment;
8334
- if (Object.keys(htmlPaths).length === 0) {
8335
- return;
8336
- }
8337
- const algorithm = getAlgorithm(environment);
8338
- if (!algorithm) {
8339
- return;
8344
+ const htmlContent = assets[asset].source();
8345
+ if (!htmlContent.includes(placeholder)) {
8346
+ continue;
8347
+ }
8348
+ assets[asset] = new compiler.webpack.sources.RawSource(
8349
+ replaceIntegrity(htmlContent, assets, algorithm, integrityCache)
8350
+ );
8351
+ }
8340
8352
  }
8341
- chain.plugin("rsbuild-sri-replace").use(SriReplaceIntegrityPlugin, [algorithm]);
8342
- });
8353
+ );
8343
8354
  }
8344
8355
  });
8345
8356
  }
@@ -8546,11 +8557,11 @@ var init_prodServer = __esm({
8546
8557
  }
8547
8558
  async applyStaticAssetMiddleware() {
8548
8559
  const {
8549
- output: { path: path17, assetPrefixes },
8560
+ output: { path: path19, assetPrefixes },
8550
8561
  serverConfig: { htmlFallback }
8551
8562
  } = this.options;
8552
8563
  const { default: sirv } = await import("../compiled/sirv/index.js");
8553
- const assetMiddleware = sirv(path17, {
8564
+ const assetMiddleware = sirv(path19, {
8554
8565
  etag: true,
8555
8566
  dev: true,
8556
8567
  ignores: ["favicon.ico"],
@@ -8601,6 +8612,7 @@ async function applyDefaultPlugins(pluginManager, context) {
8601
8612
  return result[0];
8602
8613
  })
8603
8614
  ),
8615
+ Promise.resolve().then(() => (init_appIcon(), appIcon_exports)).then(({ pluginAppIcon: pluginAppIcon2 }) => pluginAppIcon2()),
8604
8616
  Promise.resolve().then(() => (init_wasm(), wasm_exports)).then(({ pluginWasm: pluginWasm2 }) => pluginWasm2()),
8605
8617
  Promise.resolve().then(() => (init_moment(), moment_exports)).then(({ pluginMoment: pluginMoment2 }) => pluginMoment2()),
8606
8618
  Promise.resolve().then(() => (init_nodeAddons(), nodeAddons_exports)).then(
@@ -8816,7 +8828,7 @@ var init_init = __esm({
8816
8828
 
8817
8829
  // src/cli/commands.ts
8818
8830
  function runCli() {
8819
- import_commander.program.name("rsbuild").usage("<command> [options]").version("1.0.1-beta.3");
8831
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("1.0.1-beta.4");
8820
8832
  const devCommand = import_commander.program.command("dev");
8821
8833
  const buildCommand = import_commander.program.command("build");
8822
8834
  const previewCommand = import_commander.program.command("preview");
@@ -8930,7 +8942,7 @@ function prepareCli() {
8930
8942
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
8931
8943
  console.log();
8932
8944
  }
8933
- import_rslog.logger.greet(` ${`Rsbuild v${"1.0.1-beta.3"}`}
8945
+ import_rslog.logger.greet(` ${`Rsbuild v${"1.0.1-beta.4"}`}
8934
8946
  `);
8935
8947
  }
8936
8948
  var init_prepare = __esm({
@@ -9013,7 +9025,7 @@ init_logger();
9013
9025
  init_mergeConfig();
9014
9026
  init_helpers();
9015
9027
  init_constants();
9016
- var version = "1.0.1-beta.3";
9028
+ var version = "1.0.1-beta.4";
9017
9029
  // Annotate the CommonJS export names for ESM import in node:
9018
9030
  0 && (module.exports = {
9019
9031
  PLUGIN_CSS_NAME,