@rsbuild/core 0.0.14 → 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.
- package/dist/plugins/define.js +5 -5
- package/dist/plugins/html.d.ts +3 -2
- package/dist/plugins/html.js +44 -22
- package/dist/rspack-provider/core/rspackConfig.js +5 -5
- package/dist/rspack-provider/plugins/css.js +4 -4
- package/dist/utils/generateMetaTags.d.ts +0 -12
- package/dist/utils/generateMetaTags.js +0 -49
- package/package.json +2 -2
package/dist/plugins/define.js
CHANGED
|
@@ -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) => {
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -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<
|
|
6
|
+
}): Promise<MetaAttrs[]>;
|
|
6
7
|
export declare const applyInjectTags: (api: SharedRsbuildPluginAPI) => void;
|
|
7
8
|
export declare const pluginHtml: () => DefaultRsbuildPlugin;
|
package/dist/plugins/html.js
CHANGED
|
@@ -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,22 +38,31 @@ 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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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.
|
|
48
|
-
|
|
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;
|
|
52
|
-
const title = (0, import_shared.getTitle)(entryName, config);
|
|
53
64
|
const templateParams = (templateParametersByEntries == null ? void 0 : templateParametersByEntries[entryName]) || templateParameters;
|
|
54
65
|
const baseParameters = {
|
|
55
|
-
title,
|
|
56
66
|
mountId,
|
|
57
67
|
entryName,
|
|
58
68
|
assetPrefix
|
|
@@ -68,7 +78,10 @@ async function getTemplateParameters(entryName, config, assetPrefix) {
|
|
|
68
78
|
},
|
|
69
79
|
...baseParameters
|
|
70
80
|
};
|
|
71
|
-
return (0, import_shared.mergeChainedOptions)(
|
|
81
|
+
return (0, import_shared.mergeChainedOptions)({
|
|
82
|
+
defaults: defaultOptions,
|
|
83
|
+
options: templateParams
|
|
84
|
+
});
|
|
72
85
|
};
|
|
73
86
|
}
|
|
74
87
|
async function getChunks(entryName, entryValue) {
|
|
@@ -128,7 +141,11 @@ const pluginHtml = () => ({
|
|
|
128
141
|
const htmlPaths = api.getHTMLPaths();
|
|
129
142
|
const faviconUrls = [];
|
|
130
143
|
const metaPluginOptions = {
|
|
131
|
-
meta:
|
|
144
|
+
meta: {},
|
|
145
|
+
HtmlPlugin
|
|
146
|
+
};
|
|
147
|
+
const titlePluginOptions = {
|
|
148
|
+
titles: {},
|
|
132
149
|
HtmlPlugin
|
|
133
150
|
};
|
|
134
151
|
await Promise.all(
|
|
@@ -140,16 +157,17 @@ const pluginHtml = () => ({
|
|
|
140
157
|
const filename = htmlPaths[entryName];
|
|
141
158
|
const template = (0, import_shared.getTemplatePath)(entryName, config);
|
|
142
159
|
const metaTags = await getMetaTags(entryName, config);
|
|
160
|
+
const title = await (0, import_shared.getTitle)(entryName, config);
|
|
143
161
|
const templateParameters = await getTemplateParameters(
|
|
144
162
|
entryName,
|
|
145
163
|
config,
|
|
146
164
|
assetPrefix
|
|
147
165
|
);
|
|
148
166
|
if (metaTags.length) {
|
|
149
|
-
metaPluginOptions.meta
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
metaPluginOptions.meta[filename] = metaTags;
|
|
168
|
+
}
|
|
169
|
+
if (title) {
|
|
170
|
+
titlePluginOptions.titles[filename] = title;
|
|
153
171
|
}
|
|
154
172
|
const pluginOptions = {
|
|
155
173
|
chunks,
|
|
@@ -170,14 +188,14 @@ const pluginHtml = () => ({
|
|
|
170
188
|
pluginOptions.favicon = favicon;
|
|
171
189
|
}
|
|
172
190
|
}
|
|
173
|
-
const finalOptions = (0, import_shared.mergeChainedOptions)(
|
|
174
|
-
pluginOptions,
|
|
175
|
-
config.tools.htmlPlugin,
|
|
176
|
-
{
|
|
191
|
+
const finalOptions = (0, import_shared.mergeChainedOptions)({
|
|
192
|
+
defaults: pluginOptions,
|
|
193
|
+
options: config.tools.htmlPlugin,
|
|
194
|
+
utils: {
|
|
177
195
|
entryName,
|
|
178
196
|
entryValue
|
|
179
197
|
}
|
|
180
|
-
);
|
|
198
|
+
});
|
|
181
199
|
routesInfo.push({
|
|
182
200
|
urlPath: index === 0 ? "/" : `/${entryName}`,
|
|
183
201
|
entryName,
|
|
@@ -187,9 +205,12 @@ const pluginHtml = () => ({
|
|
|
187
205
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [finalOptions]);
|
|
188
206
|
})
|
|
189
207
|
);
|
|
190
|
-
if (metaPluginOptions.meta.length) {
|
|
208
|
+
if (Object.keys(metaPluginOptions.meta).length) {
|
|
191
209
|
chain.plugin(CHAIN_ID.PLUGIN.HTML_META).use(import_shared.HtmlMetaPlugin, [metaPluginOptions]);
|
|
192
210
|
}
|
|
211
|
+
if (Object.keys(titlePluginOptions.titles).length) {
|
|
212
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_TITLE).use(import_shared.HtmlTitlePlugin, [titlePluginOptions]);
|
|
213
|
+
}
|
|
193
214
|
if (config.security) {
|
|
194
215
|
const { nonce } = config.security;
|
|
195
216
|
if (nonce) {
|
|
@@ -237,6 +258,7 @@ const pluginHtml = () => ({
|
|
|
237
258
|
// Annotate the CommonJS export names for ESM import in node:
|
|
238
259
|
0 && (module.exports = {
|
|
239
260
|
applyInjectTags,
|
|
261
|
+
generateMetaTags,
|
|
240
262
|
getMetaTags,
|
|
241
263
|
pluginHtml
|
|
242
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.
|
|
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.
|
|
77
|
+
"@rsbuild/shared": "0.0.16"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/lodash": "^4.14.200",
|