@rsbuild/core 0.1.4 → 0.1.6

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 (52) hide show
  1. package/dist/cli/commands.d.ts +1 -1
  2. package/dist/cli/commands.js +10 -3
  3. package/dist/cli/config.d.ts +1 -1
  4. package/dist/cli/config.js +13 -9
  5. package/dist/cli/prepare.js +1 -1
  6. package/dist/createRsbuild.d.ts +8 -8
  7. package/dist/loadEnv.d.ts +8 -2
  8. package/dist/loadEnv.js +22 -10
  9. package/dist/plugins/html.d.ts +2 -2
  10. package/dist/plugins/html.js +6 -6
  11. package/dist/plugins/index.js +2 -1
  12. package/dist/plugins/inlineChunk.js +1 -1
  13. package/dist/plugins/networkPerformance.js +13 -3
  14. package/dist/plugins/preloadOrPrefetch.js +13 -3
  15. package/dist/plugins/server.d.ts +2 -0
  16. package/dist/plugins/server.js +56 -0
  17. package/dist/rspack-plugins/HtmlAppIconPlugin.d.ts +16 -0
  18. package/dist/rspack-plugins/HtmlAppIconPlugin.js +97 -0
  19. package/dist/rspack-plugins/HtmlCrossOriginPlugin.d.ts +15 -0
  20. package/dist/rspack-plugins/HtmlCrossOriginPlugin.js +59 -0
  21. package/dist/rspack-plugins/HtmlNetworkPerformancePlugin.d.ts +12 -0
  22. package/dist/rspack-plugins/HtmlNetworkPerformancePlugin.js +72 -0
  23. package/dist/rspack-plugins/HtmlNoncePlugin.d.ts +14 -0
  24. package/dist/rspack-plugins/HtmlNoncePlugin.js +52 -0
  25. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/determineAsValue.d.ts +25 -0
  26. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/determineAsValue.js +99 -0
  27. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/doesChunkBelongToHtml.d.ts +31 -0
  28. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/doesChunkBelongToHtml.js +75 -0
  29. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/extractChunks.d.ts +28 -0
  30. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/extractChunks.js +83 -0
  31. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/index.d.ts +4 -0
  32. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/index.js +28 -0
  33. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/type.d.ts +13 -0
  34. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/type.js +16 -0
  35. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/index.d.ts +30 -0
  36. package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/index.js +167 -0
  37. package/dist/rspack-plugins/HtmlTagsPlugin.d.ts +30 -0
  38. package/dist/rspack-plugins/HtmlTagsPlugin.js +173 -0
  39. package/dist/rspack-plugins/InlineChunkHtmlPlugin.d.ts +57 -0
  40. package/dist/rspack-plugins/InlineChunkHtmlPlugin.js +182 -0
  41. package/dist/rspack-provider/core/createContext.js +7 -3
  42. package/dist/rspack-provider/core/initHooks.d.ts +7 -6
  43. package/dist/rspack-provider/core/initHooks.js +4 -2
  44. package/dist/rspack-provider/core/initPlugins.d.ts +2 -2
  45. package/dist/rspack-provider/core/initPlugins.js +5 -7
  46. package/dist/rspack-provider/index.d.ts +2 -1
  47. package/dist/rspack-provider/index.js +8 -2
  48. package/dist/rspack-provider/provider.d.ts +3 -4
  49. package/dist/rspack-provider/shared.js +21 -2
  50. package/dist/server/devServer.js +10 -0
  51. package/dist/types.d.ts +2 -4
  52. package/package.json +5 -6
@@ -21,5 +21,5 @@ export declare function init({
21
21
  }: {
22
22
  cliOptions?: CommonOptions;
23
23
  isRestart?: boolean;
24
- }): Promise<import("@rsbuild/shared").RsbuildInstance<any> | undefined>;
24
+ }): Promise<import("@rsbuild/shared").RsbuildInstance | undefined>;
25
25
  export declare function runCli(): void;
@@ -46,9 +46,15 @@ async function init({
46
46
  commonOpts = cliOptions;
47
47
  }
48
48
  try {
49
- await (0, import_loadEnv.loadEnv)();
50
- const config = await (0, import_config.loadConfig)(commonOpts.config);
49
+ const root = process.cwd();
50
+ const { publicVars } = await (0, import_loadEnv.loadEnv)({ dir: root });
51
+ const config = await (0, import_config.loadConfig)(root, commonOpts.config);
51
52
  const { createRsbuild } = await Promise.resolve().then(() => __toESM(require("../createRsbuild")));
53
+ config.source || (config.source = {});
54
+ config.source.define = {
55
+ ...publicVars,
56
+ ...config.source.define
57
+ };
52
58
  if (commonOpts.open && !config.dev?.startUrl) {
53
59
  config.dev || (config.dev = {});
54
60
  config.dev.startUrl = true;
@@ -62,6 +68,7 @@ async function init({
62
68
  config.server.port = commonOpts.port;
63
69
  }
64
70
  return await createRsbuild({
71
+ cwd: root,
65
72
  rsbuildConfig: config,
66
73
  provider: config.provider
67
74
  });
@@ -74,7 +81,7 @@ async function init({
74
81
  }
75
82
  }
76
83
  function runCli() {
77
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.1.4");
84
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.1.6");
78
85
  import_commander.program.command("dev").option("--open", "open the page in browser on startup").option(
79
86
  "--port <port>",
80
87
  "specify a port number for Rsbuild Server to listen"
@@ -17,4 +17,4 @@ export type RsbuildConfigExport = RsbuildConfig | RsbuildConfigFn;
17
17
  */
18
18
  export declare function defineConfig(config: RsbuildConfig): RsbuildConfig;
19
19
  export declare function defineConfig(config: RsbuildConfigFn): RsbuildConfigFn;
20
- export declare function loadConfig(customConfig?: string): Promise<RsbuildConfig>;
20
+ export declare function loadConfig(root: string, customConfig?: string): Promise<RsbuildConfig>;
@@ -35,12 +35,12 @@ module.exports = __toCommonJS(config_exports);
35
35
  var import_fs = __toESM(require("fs"));
36
36
  var import_path = require("path");
37
37
  var import_shared = require("@rsbuild/shared");
38
+ var import_loadEnv = require("../loadEnv");
38
39
  var import_restart = require("../server/restart");
39
40
  function defineConfig(config) {
40
41
  return config;
41
42
  }
42
- const resolveConfigPath = (customConfig) => {
43
- const root = process.cwd();
43
+ const resolveConfigPath = (root, customConfig) => {
44
44
  if (customConfig) {
45
45
  const customConfigPath = (0, import_path.isAbsolute)(customConfig) ? customConfig : (0, import_path.join)(root, customConfig);
46
46
  if (import_fs.default.existsSync(customConfigPath)) {
@@ -65,25 +65,29 @@ const resolveConfigPath = (customConfig) => {
65
65
  }
66
66
  return null;
67
67
  };
68
- async function watchConfig(configFile) {
68
+ async function watchConfig(root, configFile) {
69
69
  const chokidar = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/chokidar")));
70
- const watcher = chokidar.watch(configFile, {
70
+ const envFiles = (0, import_loadEnv.getEnvFiles)().map((filename) => (0, import_path.join)(root, filename));
71
+ const watcher = chokidar.watch([configFile, ...envFiles], {
72
+ // do not trigger add for initial files
73
+ ignoreInitial: true,
71
74
  // If watching fails due to read permissions, the errors will be suppressed silently.
72
75
  ignorePermissionErrors: true
73
76
  });
74
77
  const callback = (0, import_shared.debounce)(
75
- async () => {
78
+ async (filePath) => {
76
79
  watcher.close();
77
- await (0, import_restart.restartDevServer)({ filePath: configFile });
80
+ await (0, import_restart.restartDevServer)({ filePath });
78
81
  },
79
82
  // set 300ms debounce to avoid restart frequently
80
83
  300
81
84
  );
85
+ watcher.on("add", callback);
82
86
  watcher.on("change", callback);
83
87
  watcher.on("unlink", callback);
84
88
  }
85
- async function loadConfig(customConfig) {
86
- const configFile = resolveConfigPath(customConfig);
89
+ async function loadConfig(root, customConfig) {
90
+ const configFile = resolveConfigPath(root, customConfig);
87
91
  if (!configFile) {
88
92
  return {};
89
93
  }
@@ -97,7 +101,7 @@ async function loadConfig(customConfig) {
97
101
  });
98
102
  const command = process.argv[2];
99
103
  if (command === "dev") {
100
- watchConfig(configFile);
104
+ watchConfig(root, configFile);
101
105
  }
102
106
  const configExport = loadConfig2(configFile);
103
107
  if (typeof configExport === "function") {
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.1.4"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.1.6"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,10 +1,10 @@
1
1
  import { type RsbuildInstance, type RsbuildProvider, type CreateRsbuildOptions } from '@rsbuild/shared';
2
2
  import type { RsbuildConfig } from './types';
3
- export declare function createRsbuild<P extends ({
4
- rsbuildConfig
5
- }: {
6
- rsbuildConfig: T;
7
- }) => RsbuildProvider, T extends RsbuildConfig>(options: CreateRsbuildOptions & {
8
- rsbuildConfig: T;
9
- provider?: P;
10
- }): Promise<RsbuildInstance<ReturnType<P>>>;
3
+ export declare function createRsbuild(options: CreateRsbuildOptions & {
4
+ rsbuildConfig: RsbuildConfig;
5
+ provider?: ({
6
+ rsbuildConfig
7
+ }: {
8
+ rsbuildConfig: RsbuildConfig;
9
+ }) => RsbuildProvider;
10
+ }): Promise<RsbuildInstance>;
package/dist/loadEnv.d.ts CHANGED
@@ -1,5 +1,11 @@
1
+ export declare const getEnvFiles: () => string[];
1
2
  export declare function loadEnv({
2
- dir
3
+ dir,
4
+ prefixes
3
5
  }?: {
4
6
  dir?: string;
5
- }): Promise<Record<string, string>>;
7
+ prefixes?: string[];
8
+ }): Promise<{
9
+ parsed: Record<string, string>;
10
+ publicVars: Record<string, string>;
11
+ }>;
package/dist/loadEnv.js CHANGED
@@ -28,31 +28,43 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var loadEnv_exports = {};
30
30
  __export(loadEnv_exports, {
31
+ getEnvFiles: () => getEnvFiles,
31
32
  loadEnv: () => loadEnv
32
33
  });
33
34
  module.exports = __toCommonJS(loadEnv_exports);
34
35
  var import_fs = __toESM(require("fs"));
35
36
  var import_path = require("path");
36
37
  var import_shared = require("@rsbuild/shared");
37
- async function loadEnv({ dir = process.cwd() } = {}) {
38
+ const getEnvFiles = () => {
39
+ const { NODE_ENV } = process.env;
40
+ return [".env", ".env.local", `.env.${NODE_ENV}`, `.env.${NODE_ENV}.local`];
41
+ };
42
+ async function loadEnv({
43
+ dir = process.cwd(),
44
+ prefixes = ["PUBLIC_"]
45
+ } = {}) {
38
46
  const { parse } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv")));
39
47
  const { expand } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv-expand")));
40
- const { NODE_ENV } = process.env;
41
- const files = [
42
- ".env",
43
- ".env.local",
44
- `.env.${NODE_ENV}`,
45
- `.env.${NODE_ENV}.local`
46
- ];
47
- const envPaths = files.map((filename) => (0, import_path.join)(dir, filename)).filter(import_shared.isFileSync);
48
+ const envPaths = getEnvFiles().map((filename) => (0, import_path.join)(dir, filename)).filter(import_shared.isFileSync);
48
49
  const parsed = {};
49
50
  envPaths.forEach((envPath) => {
50
51
  Object.assign(parsed, parse(import_fs.default.readFileSync(envPath)));
51
52
  });
52
53
  expand({ parsed });
53
- return parsed;
54
+ const publicVars = {};
55
+ Object.keys(process.env).forEach((key) => {
56
+ const val = process.env[key];
57
+ if (val && prefixes.some((prefix) => key.startsWith(prefix))) {
58
+ publicVars[`process.env.${key}`] = JSON.stringify(val);
59
+ }
60
+ });
61
+ return {
62
+ parsed,
63
+ publicVars
64
+ };
54
65
  }
55
66
  // Annotate the CommonJS export names for ESM import in node:
56
67
  0 && (module.exports = {
68
+ getEnvFiles,
57
69
  loadEnv
58
70
  });
@@ -1,4 +1,4 @@
1
- import type { HtmlConfig, NormalizedConfig, SharedRsbuildPluginAPI, NormalizedOutputConfig } from '@rsbuild/shared';
1
+ import type { HtmlConfig, RsbuildPluginAPI, NormalizedConfig, NormalizedOutputConfig } from '@rsbuild/shared';
2
2
  import type { RsbuildPlugin } from '../types';
3
3
  export declare function getTitle(entryName: string, config: NormalizedConfig): string;
4
4
  export declare function getInject(entryName: string, config: NormalizedConfig): import("@rsbuild/shared").ScriptInject;
@@ -13,5 +13,5 @@ export declare function getMetaTags(entryName: string, config: {
13
13
  html: HtmlConfig;
14
14
  output: NormalizedOutputConfig;
15
15
  }, templateContent?: string): import("@rsbuild/shared").MetaOptions;
16
- export declare const applyInjectTags: (api: SharedRsbuildPluginAPI) => void;
16
+ export declare const applyInjectTags: (api: RsbuildPluginAPI) => void;
17
17
  export declare const pluginHtml: () => RsbuildPlugin;
@@ -39,7 +39,6 @@ __export(html_exports, {
39
39
  module.exports = __toCommonJS(html_exports);
40
40
  var import_path = __toESM(require("path"));
41
41
  var import_shared = require("@rsbuild/shared");
42
- var import_HtmlBasicPlugin = require("../rspack-plugins/HtmlBasicPlugin");
43
42
  function getTitle(entryName, config) {
44
43
  return (0, import_shared.mergeChainedOptions)({
45
44
  defaults: "",
@@ -156,7 +155,7 @@ const applyInjectTags = (api) => {
156
155
  if (!tags.length && !shouldByEntries) {
157
156
  return;
158
157
  }
159
- const { HtmlTagsPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
158
+ const { HtmlTagsPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlTagsPlugin")));
160
159
  const sharedOptions = {
161
160
  HtmlPlugin,
162
161
  append: true,
@@ -247,18 +246,19 @@ const pluginHtml = () => ({
247
246
  chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [finalOptions]);
248
247
  })
249
248
  );
250
- chain.plugin(CHAIN_ID.PLUGIN.HTML_BASIC).use(import_HtmlBasicPlugin.HtmlBasicPlugin, [{ HtmlPlugin, info: htmlInfoMap }]);
249
+ const { HtmlBasicPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlBasicPlugin")));
250
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin, [{ HtmlPlugin, info: htmlInfoMap }]);
251
251
  if (config.security) {
252
252
  const { nonce } = config.security;
253
253
  if (nonce) {
254
- const { HtmlNoncePlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
254
+ const { HtmlNoncePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlNoncePlugin")));
255
255
  chain.plugin(CHAIN_ID.PLUGIN.HTML_NONCE).use(HtmlNoncePlugin, [{ nonce, HtmlPlugin }]);
256
256
  }
257
257
  }
258
258
  if (config.html) {
259
259
  const { appIcon, crossorigin } = config.html;
260
260
  if (crossorigin) {
261
- const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
261
+ const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlCrossOriginPlugin")));
262
262
  const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
263
263
  chain.plugin(CHAIN_ID.PLUGIN.HTML_CROSS_ORIGIN).use(HtmlCrossOriginPlugin, [
264
264
  { crossOrigin: formattedCrossorigin, HtmlPlugin }
@@ -266,7 +266,7 @@ const pluginHtml = () => ({
266
266
  chain.output.crossOriginLoading(formattedCrossorigin);
267
267
  }
268
268
  if (appIcon) {
269
- const { HtmlAppIconPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
269
+ const { HtmlAppIconPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlAppIconPlugin")));
270
270
  const distDir = (0, import_shared.getDistPath)(config.output, "image");
271
271
  const iconPath = import_path.default.isAbsolute(appIcon) ? appIcon : import_path.default.join(api.context.rootPath, appIcon);
272
272
  chain.plugin(CHAIN_ID.PLUGIN.APP_ICON).use(HtmlAppIconPlugin, [{ iconPath, distDir, HtmlPlugin }]);
@@ -53,7 +53,8 @@ const plugins = {
53
53
  networkPerformance: () => Promise.resolve().then(() => __toESM(require("./networkPerformance"))).then((m) => m.pluginNetworkPerformance()),
54
54
  preloadOrPrefetch: () => Promise.resolve().then(() => __toESM(require("./preloadOrPrefetch"))).then((m) => m.pluginPreloadOrPrefetch()),
55
55
  performance: () => Promise.resolve().then(() => __toESM(require("./performance"))).then((m) => m.pluginPerformance()),
56
- define: () => Promise.resolve().then(() => __toESM(require("./define"))).then((m) => m.pluginDefine())
56
+ define: () => Promise.resolve().then(() => __toESM(require("./define"))).then((m) => m.pluginDefine()),
57
+ server: () => Promise.resolve().then(() => __toESM(require("./server"))).then((m) => m.pluginServer())
57
58
  };
58
59
  // Annotate the CommonJS export names for ESM import in node:
59
60
  0 && (module.exports = {
@@ -41,7 +41,7 @@ const pluginInlineChunk = () => ({
41
41
  if ((0, import_shared.isHtmlDisabled)(config, target) || !isProd) {
42
42
  return;
43
43
  }
44
- const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
44
+ const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/InlineChunkHtmlPlugin")));
45
45
  const { inlineStyles, inlineScripts } = config.output;
46
46
  const scriptTests = [];
47
47
  const styleTests = [];
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,13 +17,20 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var networkPerformance_exports = {};
20
30
  __export(networkPerformance_exports, {
21
31
  pluginNetworkPerformance: () => pluginNetworkPerformance
22
32
  });
23
33
  module.exports = __toCommonJS(networkPerformance_exports);
24
- var import_shared = require("@rsbuild/shared");
25
34
  const pluginNetworkPerformance = () => ({
26
35
  name: `plugin-network-performance`,
27
36
  setup(api) {
@@ -34,15 +43,16 @@ const pluginNetworkPerformance = () => ({
34
43
  if (isServer || isWebWorker || isServiceWorker) {
35
44
  return;
36
45
  }
46
+ const { HtmlNetworkPerformancePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlNetworkPerformancePlugin")));
37
47
  if (dnsPrefetch) {
38
- chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(import_shared.HtmlNetworkPerformancePlugin, [
48
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(HtmlNetworkPerformancePlugin, [
39
49
  dnsPrefetch,
40
50
  "dnsPrefetch",
41
51
  HtmlPlugin
42
52
  ]);
43
53
  }
44
54
  if (preconnect) {
45
- chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(import_shared.HtmlNetworkPerformancePlugin, [
55
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(HtmlNetworkPerformancePlugin, [
46
56
  preconnect,
47
57
  "preconnect",
48
58
  HtmlPlugin
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,13 +17,20 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var preloadOrPrefetch_exports = {};
20
30
  __export(preloadOrPrefetch_exports, {
21
31
  pluginPreloadOrPrefetch: () => pluginPreloadOrPrefetch
22
32
  });
23
33
  module.exports = __toCommonJS(preloadOrPrefetch_exports);
24
- var import_shared = require("@rsbuild/shared");
25
34
  const pluginPreloadOrPrefetch = () => ({
26
35
  name: `plugin-preload-or-prefetch`,
27
36
  setup(api) {
@@ -35,8 +44,9 @@ const pluginPreloadOrPrefetch = () => ({
35
44
  return;
36
45
  }
37
46
  const HTMLCount = chain.entryPoints.values().length;
47
+ const { HTMLPreloadOrPrefetchPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlPreloadOrPrefetchPlugin")));
38
48
  if (prefetch) {
39
- chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(import_shared.HTMLPreloadOrPrefetchPlugin, [
49
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HTMLPreloadOrPrefetchPlugin, [
40
50
  prefetch,
41
51
  "prefetch",
42
52
  HtmlPlugin,
@@ -44,7 +54,7 @@ const pluginPreloadOrPrefetch = () => ({
44
54
  ]);
45
55
  }
46
56
  if (preload) {
47
- chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(import_shared.HTMLPreloadOrPrefetchPlugin, [
57
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HTMLPreloadOrPrefetchPlugin, [
48
58
  preload,
49
59
  "preload",
50
60
  HtmlPlugin,
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '../types';
2
+ export declare const pluginServer: () => RsbuildPlugin;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var server_exports = {};
20
+ __export(server_exports, {
21
+ pluginServer: () => pluginServer
22
+ });
23
+ module.exports = __toCommonJS(server_exports);
24
+ var import_shared = require("@rsbuild/shared");
25
+ const pluginServer = () => ({
26
+ name: "rsbuild:server",
27
+ setup(api) {
28
+ api.modifyRsbuildConfig((rsbuildConfig, { mergeRsbuildConfig }) => {
29
+ if ((0, import_shared.isProd)() && rsbuildConfig.server?.publicDir) {
30
+ const { name, copyOnBuild } = rsbuildConfig.server?.publicDir;
31
+ if (!copyOnBuild || !name) {
32
+ return;
33
+ }
34
+ const { copy } = rsbuildConfig.output || {};
35
+ const publicPattern = [
36
+ {
37
+ from: name,
38
+ to: "",
39
+ noErrorOnMissing: true
40
+ }
41
+ ];
42
+ return mergeRsbuildConfig(rsbuildConfig, {
43
+ output: {
44
+ copy: Array.isArray(copy) ? publicPattern : {
45
+ patterns: publicPattern
46
+ }
47
+ }
48
+ });
49
+ }
50
+ });
51
+ }
52
+ });
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ pluginServer
56
+ });
@@ -0,0 +1,16 @@
1
+ import type HtmlWebpackPlugin from 'html-webpack-plugin';
2
+ import type { Compiler } from '@rspack/core';
3
+ type AppIconOptions = {
4
+ distDir: string;
5
+ iconPath: string;
6
+ HtmlPlugin: typeof HtmlWebpackPlugin;
7
+ };
8
+ export declare class HtmlAppIconPlugin {
9
+ readonly name: string;
10
+ readonly distDir: string;
11
+ readonly iconPath: string;
12
+ readonly HtmlPlugin: typeof HtmlWebpackPlugin;
13
+ constructor(options: AppIconOptions);
14
+ apply(compiler: Compiler): void;
15
+ }
16
+ export {};
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var HtmlAppIconPlugin_exports = {};
30
+ __export(HtmlAppIconPlugin_exports, {
31
+ HtmlAppIconPlugin: () => HtmlAppIconPlugin
32
+ });
33
+ module.exports = __toCommonJS(HtmlAppIconPlugin_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_path = __toESM(require("path"));
36
+ var import_webpack_sources = __toESM(require("@rsbuild/shared/webpack-sources"));
37
+ var import_shared = require("@rsbuild/shared");
38
+ class HtmlAppIconPlugin {
39
+ constructor(options) {
40
+ this.name = "HtmlAppIconPlugin";
41
+ this.distDir = options.distDir;
42
+ this.iconPath = options.iconPath;
43
+ this.HtmlPlugin = options.HtmlPlugin;
44
+ }
45
+ apply(compiler) {
46
+ if (!import_fs.default.existsSync(this.iconPath)) {
47
+ throw new Error(
48
+ `[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
49
+ );
50
+ }
51
+ const iconRelativePath = import_path.default.join(
52
+ this.distDir,
53
+ import_path.default.basename(this.iconPath)
54
+ );
55
+ compiler.hooks.compilation.tap(this.name, (compilation) => {
56
+ this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tap(
57
+ this.name,
58
+ (data) => {
59
+ const { publicPath } = compiler.options.output;
60
+ data.headTags.unshift({
61
+ tagName: "link",
62
+ voidTag: true,
63
+ attributes: {
64
+ rel: "apple-touch-icon",
65
+ sizes: "180*180",
66
+ href: `${publicPath}${iconRelativePath}`
67
+ },
68
+ meta: {}
69
+ });
70
+ return data;
71
+ }
72
+ );
73
+ });
74
+ compiler.hooks.thisCompilation.tap(
75
+ this.name,
76
+ (compilation) => {
77
+ compilation.hooks.processAssets.tap(
78
+ {
79
+ name: this.name,
80
+ stage: import_shared.COMPILATION_PROCESS_STAGE.PROCESS_ASSETS_STAGE_PRE_PROCESS
81
+ },
82
+ (assets) => {
83
+ const source = import_fs.default.readFileSync(this.iconPath);
84
+ assets[iconRelativePath] = new import_webpack_sources.default.RawSource(
85
+ source,
86
+ false
87
+ );
88
+ }
89
+ );
90
+ }
91
+ );
92
+ }
93
+ }
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ HtmlAppIconPlugin
97
+ });
@@ -0,0 +1,15 @@
1
+ import type HtmlWebpackPlugin from 'html-webpack-plugin';
2
+ import type { CrossOrigin } from '@rsbuild/shared';
3
+ import type { Compiler, RspackPluginInstance } from '@rspack/core';
4
+ type CrossOriginOptions = {
5
+ crossOrigin: CrossOrigin;
6
+ HtmlPlugin: typeof HtmlWebpackPlugin;
7
+ };
8
+ export declare class HtmlCrossOriginPlugin implements RspackPluginInstance {
9
+ readonly name: string;
10
+ readonly crossOrigin: CrossOrigin;
11
+ readonly HtmlPlugin: typeof HtmlWebpackPlugin;
12
+ constructor(options: CrossOriginOptions);
13
+ apply(compiler: Compiler): void;
14
+ }
15
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var HtmlCrossOriginPlugin_exports = {};
20
+ __export(HtmlCrossOriginPlugin_exports, {
21
+ HtmlCrossOriginPlugin: () => HtmlCrossOriginPlugin
22
+ });
23
+ module.exports = __toCommonJS(HtmlCrossOriginPlugin_exports);
24
+ class HtmlCrossOriginPlugin {
25
+ constructor(options) {
26
+ const { crossOrigin } = options;
27
+ this.name = "HtmlCrossOriginPlugin";
28
+ this.crossOrigin = crossOrigin;
29
+ this.HtmlPlugin = options.HtmlPlugin;
30
+ }
31
+ apply(compiler) {
32
+ if (!this.crossOrigin || // align with crossOriginLoading logic
33
+ // https://github.com/web-infra-dev/rspack/blob/bc8e67b5419adda15c2b389517c9b37d02c8240f/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs#L39
34
+ compiler.options.output.publicPath === "/" && this.crossOrigin !== "use-credentials") {
35
+ return;
36
+ }
37
+ compiler.hooks.compilation.tap(this.name, (compilation) => {
38
+ this.HtmlPlugin.getHooks(compilation).alterAssetTags.tap(
39
+ this.name,
40
+ (alterAssetTags) => {
41
+ const {
42
+ assetTags: { scripts, styles }
43
+ } = alterAssetTags;
44
+ scripts.forEach(
45
+ (script) => script.attributes.crossorigin = this.crossOrigin
46
+ );
47
+ styles.forEach(
48
+ (style) => style.attributes.crossorigin = this.crossOrigin
49
+ );
50
+ return alterAssetTags;
51
+ }
52
+ );
53
+ });
54
+ }
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ HtmlCrossOriginPlugin
59
+ });