@rsbuild/core 0.0.15 → 0.0.16

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.
@@ -35,11 +35,11 @@ const pluginDefine = () => ({
35
35
  "process.env.NODE_ENV": process.env.NODE_ENV,
36
36
  "process.env.ASSET_PREFIX": (0, import_shared.removeTailSlash)(assetPrefix)
37
37
  };
38
- const globalVars = (0, import_shared.mergeChainedOptions)(
39
- builtinVars,
40
- config.source.globalVars,
41
- { env, target }
42
- );
38
+ const globalVars = (0, import_shared.mergeChainedOptions)({
39
+ defaults: builtinVars,
40
+ options: config.source.globalVars,
41
+ utils: { env, target }
42
+ });
43
43
  const serializedVars = (0, import_lodash.mapValues)(
44
44
  globalVars,
45
45
  (value) => {
@@ -1,7 +1,8 @@
1
- import type { HtmlConfig, DefaultRsbuildPlugin, SharedRsbuildPluginAPI, NormalizedOutputConfig } from '@rsbuild/shared';
1
+ import type { MetaAttrs, HtmlConfig, MetaOptions, DefaultRsbuildPlugin, SharedRsbuildPluginAPI, NormalizedOutputConfig } from '@rsbuild/shared';
2
+ export declare const generateMetaTags: (metaOptions?: MetaOptions) => MetaAttrs[];
2
3
  export declare function getMetaTags(entryName: string, config: {
3
4
  html: HtmlConfig;
4
5
  output: NormalizedOutputConfig;
5
- }): Promise<import("html-webpack-plugin").HtmlTagObject[]>;
6
+ }): Promise<MetaAttrs[]>;
6
7
  export declare const applyInjectTags: (api: SharedRsbuildPluginAPI) => void;
7
8
  export declare const pluginHtml: () => DefaultRsbuildPlugin;
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var html_exports = {};
30
30
  __export(html_exports, {
31
31
  applyInjectTags: () => applyInjectTags,
32
+ generateMetaTags: () => generateMetaTags,
32
33
  getMetaTags: () => getMetaTags,
33
34
  pluginHtml: () => pluginHtml
34
35
  });
@@ -37,15 +38,26 @@ var import_path = __toESM(require("path"));
37
38
  var import_shared = require("@rsbuild/shared");
38
39
  var import_fs_extra = require("@rsbuild/shared/fs-extra");
39
40
  var import_lodash = __toESM(require("lodash"));
40
- var import_generateMetaTags = require("../utils/generateMetaTags");
41
- async function getMetaTags(entryName, config) {
42
- const { meta, metaByEntries } = config.html;
43
- const metaOptions = {};
44
- if (config.output.charset === "utf8") {
45
- metaOptions.charset = { charset: "utf-8" };
41
+ const generateMetaTags = (metaOptions) => {
42
+ if (!metaOptions) {
43
+ return [];
46
44
  }
47
- Object.assign(metaOptions, meta, metaByEntries == null ? void 0 : metaByEntries[entryName]);
48
- return (0, import_generateMetaTags.generateMetaTags)(metaOptions);
45
+ return Object.keys(metaOptions).map((metaName) => {
46
+ const metaTagContent = metaOptions[metaName];
47
+ return typeof metaTagContent === "string" ? {
48
+ name: metaName,
49
+ content: metaTagContent
50
+ } : metaTagContent;
51
+ }).filter(Boolean);
52
+ };
53
+ async function getMetaTags(entryName, config) {
54
+ const merged = (0, import_shared.mergeChainedOptions)({
55
+ defaults: {},
56
+ options: config.html.meta,
57
+ utils: { entryName },
58
+ useObjectParam: true
59
+ });
60
+ return generateMetaTags(merged);
49
61
  }
50
62
  async function getTemplateParameters(entryName, config, assetPrefix) {
51
63
  const { mountId, templateParameters, templateParametersByEntries } = config.html;
@@ -66,7 +78,10 @@ async function getTemplateParameters(entryName, config, assetPrefix) {
66
78
  },
67
79
  ...baseParameters
68
80
  };
69
- return (0, import_shared.mergeChainedOptions)(defaultOptions, templateParams);
81
+ return (0, import_shared.mergeChainedOptions)({
82
+ defaults: defaultOptions,
83
+ options: templateParams
84
+ });
70
85
  };
71
86
  }
72
87
  async function getChunks(entryName, entryValue) {
@@ -126,11 +141,11 @@ const pluginHtml = () => ({
126
141
  const htmlPaths = api.getHTMLPaths();
127
142
  const faviconUrls = [];
128
143
  const metaPluginOptions = {
129
- meta: [],
144
+ meta: {},
130
145
  HtmlPlugin
131
146
  };
132
147
  const titlePluginOptions = {
133
- titles: [],
148
+ titles: {},
134
149
  HtmlPlugin
135
150
  };
136
151
  await Promise.all(
@@ -149,16 +164,10 @@ const pluginHtml = () => ({
149
164
  assetPrefix
150
165
  );
151
166
  if (metaTags.length) {
152
- metaPluginOptions.meta.push({
153
- tags: metaTags,
154
- filename
155
- });
167
+ metaPluginOptions.meta[filename] = metaTags;
156
168
  }
157
169
  if (title) {
158
- titlePluginOptions.titles.push({
159
- title,
160
- filename
161
- });
170
+ titlePluginOptions.titles[filename] = title;
162
171
  }
163
172
  const pluginOptions = {
164
173
  chunks,
@@ -179,14 +188,14 @@ const pluginHtml = () => ({
179
188
  pluginOptions.favicon = favicon;
180
189
  }
181
190
  }
182
- const finalOptions = (0, import_shared.mergeChainedOptions)(
183
- pluginOptions,
184
- config.tools.htmlPlugin,
185
- {
191
+ const finalOptions = (0, import_shared.mergeChainedOptions)({
192
+ defaults: pluginOptions,
193
+ options: config.tools.htmlPlugin,
194
+ utils: {
186
195
  entryName,
187
196
  entryValue
188
197
  }
189
- );
198
+ });
190
199
  routesInfo.push({
191
200
  urlPath: index === 0 ? "/" : `/${entryName}`,
192
201
  entryName,
@@ -196,10 +205,10 @@ const pluginHtml = () => ({
196
205
  chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [finalOptions]);
197
206
  })
198
207
  );
199
- if (metaPluginOptions.meta.length) {
208
+ if (Object.keys(metaPluginOptions.meta).length) {
200
209
  chain.plugin(CHAIN_ID.PLUGIN.HTML_META).use(import_shared.HtmlMetaPlugin, [metaPluginOptions]);
201
210
  }
202
- if (titlePluginOptions.titles.length) {
211
+ if (Object.keys(titlePluginOptions.titles).length) {
203
212
  chain.plugin(CHAIN_ID.PLUGIN.HTML_TITLE).use(import_shared.HtmlTitlePlugin, [titlePluginOptions]);
204
213
  }
205
214
  if (config.security) {
@@ -249,6 +258,7 @@ const pluginHtml = () => ({
249
258
  // Annotate the CommonJS export names for ESM import in node:
250
259
  0 && (module.exports = {
251
260
  applyInjectTags,
261
+ generateMetaTags,
252
262
  getMetaTags,
253
263
  pluginHtml
254
264
  });
@@ -41,12 +41,12 @@ async function modifyRspackConfig(context, rspackConfig, utils) {
41
41
  utils
42
42
  );
43
43
  if ((_a = context.config.tools) == null ? void 0 : _a.rspack) {
44
- modifiedConfig = (0, import_shared.mergeChainedOptions)(
45
- modifiedConfig,
46
- context.config.tools.rspack,
44
+ modifiedConfig = (0, import_shared.mergeChainedOptions)({
45
+ defaults: modifiedConfig,
46
+ options: context.config.tools.rspack,
47
47
  utils,
48
- utils.mergeConfig
49
- );
48
+ mergeFn: utils.mergeConfig
49
+ });
50
50
  }
51
51
  (0, import_shared.debug)("modify Rspack config done");
52
52
  return modifiedConfig;
@@ -65,14 +65,14 @@ async function applyBaseCSSRule({
65
65
  localIdentName
66
66
  });
67
67
  if (!isServer && !isWebWorker) {
68
- const styleLoaderOptions = (0, import_shared.mergeChainedOptions)(
69
- {
68
+ const styleLoaderOptions = (0, import_shared.mergeChainedOptions)({
69
+ defaults: {
70
70
  // todo: hmr does not work while esModule is true
71
71
  // @ts-expect-error
72
72
  esModule: false
73
73
  },
74
- config.tools.styleLoader
75
- );
74
+ options: config.tools.styleLoader
75
+ });
76
76
  rule.use(CHAIN_ID.USE.STYLE).loader(require.resolve("style-loader")).options(styleLoaderOptions).end();
77
77
  if (enableCSSModuleTS && cssLoaderOptions.modules) {
78
78
  rule.use(CHAIN_ID.USE.CSS_MODULES_TS).loader(
@@ -1,12 +0,0 @@
1
- /**
2
- * Copyright JS Foundation and other contributors.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file at
6
- * https://github.com/jantimon/html-webpack-plugin/blob/main/LICENSE
7
- *
8
- * Modified from https://github.com/jantimon/html-webpack-plugin/blob/2f5de7ab9e8bca60e9e200f2e4b4cfab90db28d4/index.js#L800
9
- */
10
- import type { MetaOptions } from '@rsbuild/shared';
11
- import type { HtmlTagObject } from 'html-webpack-plugin';
12
- export declare const generateMetaTags: (metaOptions?: MetaOptions) => HtmlTagObject[];
@@ -1,50 +1 @@
1
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 generateMetaTags_exports = {};
20
- __export(generateMetaTags_exports, {
21
- generateMetaTags: () => generateMetaTags
22
- });
23
- module.exports = __toCommonJS(generateMetaTags_exports);
24
- const generateMetaTags = (metaOptions) => {
25
- if (!metaOptions) {
26
- return [];
27
- }
28
- const metaTagAttributeObjects = Object.keys(metaOptions).map((metaName) => {
29
- const metaTagContent = metaOptions[metaName];
30
- return typeof metaTagContent === "string" ? {
31
- name: metaName,
32
- content: metaTagContent
33
- } : metaTagContent;
34
- }).filter((attribute) => attribute !== false);
35
- return metaTagAttributeObjects.map((metaTagAttributes) => {
36
- if (metaTagAttributes === false) {
37
- throw new Error("Invalid meta tag");
38
- }
39
- return {
40
- tagName: "meta",
41
- voidTag: true,
42
- attributes: metaTagAttributes,
43
- meta: {}
44
- };
45
- });
46
- };
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- generateMetaTags
50
- });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Unleash the power of Rspack with the out-of-the-box build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -74,7 +74,7 @@
74
74
  "pkg-up": "^3.1.0",
75
75
  "postcss": "8.4.31",
76
76
  "semver": "^7.5.4",
77
- "@rsbuild/shared": "0.0.15"
77
+ "@rsbuild/shared": "0.0.16"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@types/lodash": "^4.14.200",