@rsbuild/core 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands.js +6 -3
- package/dist/cli/config.d.ts +7 -1
- package/dist/cli/config.js +6 -3
- package/dist/cli/prepare.js +1 -1
- package/dist/createRsbuild.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/loadEnv.d.ts +2 -2
- package/dist/loadEnv.js +2 -2
- package/dist/plugins/asset.js +2 -2
- package/dist/plugins/basic.d.ts +5 -0
- package/dist/plugins/basic.js +68 -0
- package/dist/plugins/html.d.ts +1 -2
- package/dist/plugins/html.js +8 -8
- package/dist/plugins/index.js +2 -3
- package/dist/plugins/inlineChunk.js +25 -28
- package/dist/plugins/networkPerformance.js +3 -11
- package/dist/plugins/nodeAddons.js +1 -1
- package/dist/plugins/preloadOrPrefetch.js +4 -10
- package/dist/plugins/wasm.js +1 -1
- package/dist/provider/core/createCompiler.js +15 -7
- package/dist/provider/core/createContext.d.ts +3 -3
- package/dist/provider/core/createContext.js +13 -27
- package/dist/provider/core/initConfigs.d.ts +2 -2
- package/dist/provider/core/initConfigs.js +4 -3
- package/dist/provider/core/initPlugins.js +15 -12
- package/dist/provider/core/inspectConfig.d.ts +2 -20
- package/dist/provider/core/inspectConfig.js +6 -6
- package/dist/provider/css-modules-typescript-pre-loader/index.js +1 -1
- package/dist/provider/css-modules-typescript-pre-loader/{postcss-icss-extract-plugin.js → postcssIcssExtractPlugin.js} +5 -5
- package/dist/provider/index.d.ts +1 -2
- package/dist/provider/index.js +4 -7
- package/dist/provider/plugins/css.js +3 -7
- package/dist/provider/plugins/less.js +1 -1
- package/dist/provider/plugins/output.js +2 -2
- package/dist/provider/plugins/resolve.js +0 -5
- package/dist/provider/plugins/server.d.ts +2 -0
- package/dist/provider/plugins/server.js +70 -0
- package/dist/provider/plugins/swc.js +1 -1
- package/dist/provider/provider.js +15 -1
- package/dist/provider/shared.d.ts +1 -2
- package/dist/provider/shared.js +2 -15
- package/dist/rspack/HtmlAppIconPlugin.d.ts +0 -3
- package/dist/rspack/HtmlAppIconPlugin.js +2 -2
- package/dist/rspack/HtmlBasicPlugin.d.ts +0 -3
- package/dist/rspack/HtmlBasicPlugin.js +24 -10
- package/dist/rspack/HtmlCrossOriginPlugin.d.ts +0 -3
- package/dist/rspack/HtmlCrossOriginPlugin.js +12 -2
- package/dist/rspack/HtmlNetworkPerformancePlugin.d.ts +1 -3
- package/dist/rspack/HtmlNetworkPerformancePlugin.js +13 -3
- package/dist/rspack/HtmlNoncePlugin.d.ts +0 -3
- package/dist/rspack/HtmlNoncePlugin.js +12 -2
- package/dist/rspack/HtmlTagsPlugin.d.ts +1 -7
- package/dist/rspack/HtmlTagsPlugin.js +12 -1
- package/dist/rspack/InlineChunkHtmlPlugin.d.ts +2 -3
- package/dist/rspack/InlineChunkHtmlPlugin.js +17 -3
- package/dist/rspack/RemoveCssSourcemapPlugin.d.ts +1 -3
- package/dist/rspack/RemoveCssSourcemapPlugin.js +1 -2
- package/dist/rspack/{HtmlPreloadOrPrefetchPlugin/index.d.ts → preload/HtmlPreloadOrPrefetchPlugin.d.ts} +3 -4
- package/dist/rspack/{HtmlPreloadOrPrefetchPlugin/index.js → preload/HtmlPreloadOrPrefetchPlugin.js} +17 -7
- package/dist/server/{dev-middleware → compiler-dev-middleware}/index.d.ts +2 -2
- package/dist/server/{dev-middleware → compiler-dev-middleware}/index.js +3 -3
- package/dist/server/{dev-middleware → compiler-dev-middleware}/socketServer.d.ts +2 -2
- package/dist/server/devMiddlewares.d.ts +7 -0
- package/dist/server/devMiddlewares.js +156 -0
- package/dist/server/devServer.d.ts +10 -23
- package/dist/server/devServer.js +77 -162
- package/dist/server/httpServer.d.ts +8 -0
- package/dist/server/httpServer.js +48 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +2 -0
- package/dist/server/prodServer.d.ts +0 -5
- package/dist/server/prodServer.js +11 -25
- package/package.json +4 -4
- package/dist/plugins/devtool.d.ts +0 -2
- package/dist/plugins/devtool.js +0 -46
- package/dist/plugins/server.d.ts +0 -2
- package/dist/plugins/server.js +0 -56
- package/dist/provider/plugins/basic.d.ts +0 -5
- package/dist/provider/plugins/basic.js +0 -34
- /package/dist/provider/css-modules-typescript-pre-loader/{postcss-icss-extract-plugin.d.ts → postcssIcssExtractPlugin.d.ts} +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/determineAsValue.d.ts +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/determineAsValue.js +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/doesChunkBelongToHtml.d.ts +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/doesChunkBelongToHtml.js +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/extractChunks.d.ts +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/extractChunks.js +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/index.d.ts +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/index.js +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/type.d.ts +0 -0
- /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/type.js +0 -0
- /package/dist/server/{dev-middleware → compiler-dev-middleware}/socketServer.js +0 -0
package/dist/cli/commands.js
CHANGED
|
@@ -47,8 +47,11 @@ async function init({
|
|
|
47
47
|
}
|
|
48
48
|
try {
|
|
49
49
|
const root = process.cwd();
|
|
50
|
-
const { publicVars } = await (0, import_loadEnv.loadEnv)({
|
|
51
|
-
const config = await (0, import_config.loadConfig)(
|
|
50
|
+
const { publicVars } = await (0, import_loadEnv.loadEnv)({ cwd: root });
|
|
51
|
+
const config = await (0, import_config.loadConfig)({
|
|
52
|
+
cwd: root,
|
|
53
|
+
path: commonOpts.config
|
|
54
|
+
});
|
|
52
55
|
const { createRsbuild } = await Promise.resolve().then(() => __toESM(require("../createRsbuild")));
|
|
53
56
|
config.source || (config.source = {});
|
|
54
57
|
config.source.define = {
|
|
@@ -81,7 +84,7 @@ async function init({
|
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
function runCli() {
|
|
84
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.
|
|
87
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.2.0");
|
|
85
88
|
import_commander.program.command("dev").option("--open", "open the page in browser on startup").option(
|
|
86
89
|
"--port <port>",
|
|
87
90
|
"specify a port number for Rsbuild Server to listen"
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -17,4 +17,10 @@ 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(
|
|
20
|
+
export declare function loadConfig({
|
|
21
|
+
cwd,
|
|
22
|
+
path
|
|
23
|
+
}: {
|
|
24
|
+
cwd: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
}): Promise<RsbuildConfig>;
|
package/dist/cli/config.js
CHANGED
|
@@ -86,8 +86,11 @@ async function watchConfig(root, configFile) {
|
|
|
86
86
|
watcher.on("change", callback);
|
|
87
87
|
watcher.on("unlink", callback);
|
|
88
88
|
}
|
|
89
|
-
async function loadConfig(
|
|
90
|
-
|
|
89
|
+
async function loadConfig({
|
|
90
|
+
cwd,
|
|
91
|
+
path
|
|
92
|
+
}) {
|
|
93
|
+
const configFile = resolveConfigPath(cwd, path);
|
|
91
94
|
if (!configFile) {
|
|
92
95
|
return {};
|
|
93
96
|
}
|
|
@@ -101,7 +104,7 @@ async function loadConfig(root, customConfig) {
|
|
|
101
104
|
});
|
|
102
105
|
const command = process.argv[2];
|
|
103
106
|
if (command === "dev") {
|
|
104
|
-
watchConfig(
|
|
107
|
+
watchConfig(cwd, configFile);
|
|
105
108
|
}
|
|
106
109
|
const configExport = loadConfig2(configFile);
|
|
107
110
|
if (typeof configExport === "function") {
|
package/dist/cli/prepare.js
CHANGED
|
@@ -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.
|
|
37
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.2.0"}`}
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/createRsbuild.js
CHANGED
|
@@ -44,7 +44,6 @@ async function createRsbuild(options) {
|
|
|
44
44
|
const provider = options.provider ? options.provider({ rsbuildConfig }) : await getRspackProvider(rsbuildConfig);
|
|
45
45
|
const rsbuildOptions = {
|
|
46
46
|
cwd: process.cwd(),
|
|
47
|
-
target: ["web"],
|
|
48
47
|
...options
|
|
49
48
|
};
|
|
50
49
|
const pluginStore = (0, import_shared.createPluginStore)();
|
|
@@ -56,6 +55,7 @@ async function createRsbuild(options) {
|
|
|
56
55
|
initConfigs,
|
|
57
56
|
inspectConfig,
|
|
58
57
|
createCompiler,
|
|
58
|
+
createDevServer,
|
|
59
59
|
startDevServer,
|
|
60
60
|
applyDefaultPlugins
|
|
61
61
|
} = await provider({
|
|
@@ -88,6 +88,7 @@ async function createRsbuild(options) {
|
|
|
88
88
|
createCompiler,
|
|
89
89
|
initConfigs,
|
|
90
90
|
inspectConfig,
|
|
91
|
+
createDevServer,
|
|
91
92
|
startDevServer,
|
|
92
93
|
context: publicContext
|
|
93
94
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the public API of @rsbuild/core.
|
|
4
4
|
*/
|
|
5
5
|
export { createRsbuild } from './createRsbuild';
|
|
6
|
-
export { defineConfig } from './cli/config';
|
|
6
|
+
export { loadConfig, defineConfig } from './cli/config';
|
|
7
7
|
export { logger, mergeRsbuildConfig } from '@rsbuild/shared';
|
|
8
8
|
export type { Rspack } from './provider';
|
|
9
9
|
export type { RsbuildConfig, NormalizedConfig, RsbuildPlugin, RsbuildPluginAPI } from './types';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var src_exports = {};
|
|
|
20
20
|
__export(src_exports, {
|
|
21
21
|
createRsbuild: () => import_createRsbuild.createRsbuild,
|
|
22
22
|
defineConfig: () => import_config.defineConfig,
|
|
23
|
+
loadConfig: () => import_config.loadConfig,
|
|
23
24
|
logger: () => import_shared.logger,
|
|
24
25
|
mergeRsbuildConfig: () => import_shared.mergeRsbuildConfig
|
|
25
26
|
});
|
|
@@ -31,6 +32,7 @@ var import_shared = require("@rsbuild/shared");
|
|
|
31
32
|
0 && (module.exports = {
|
|
32
33
|
createRsbuild,
|
|
33
34
|
defineConfig,
|
|
35
|
+
loadConfig,
|
|
34
36
|
logger,
|
|
35
37
|
mergeRsbuildConfig
|
|
36
38
|
});
|
package/dist/loadEnv.d.ts
CHANGED
package/dist/loadEnv.js
CHANGED
|
@@ -40,12 +40,12 @@ const getEnvFiles = () => {
|
|
|
40
40
|
return [".env", ".env.local", `.env.${NODE_ENV}`, `.env.${NODE_ENV}.local`];
|
|
41
41
|
};
|
|
42
42
|
async function loadEnv({
|
|
43
|
-
|
|
43
|
+
cwd = process.cwd(),
|
|
44
44
|
prefixes = ["PUBLIC_"]
|
|
45
45
|
} = {}) {
|
|
46
46
|
const { parse } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv")));
|
|
47
47
|
const { expand } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv-expand")));
|
|
48
|
-
const envPaths = getEnvFiles().map((filename) => (0, import_path.join)(
|
|
48
|
+
const envPaths = getEnvFiles().map((filename) => (0, import_path.join)(cwd, filename)).filter(import_shared.isFileSync);
|
|
49
49
|
const parsed = {};
|
|
50
50
|
envPaths.forEach((envPath) => {
|
|
51
51
|
Object.assign(parsed, parse(import_fs.default.readFileSync(envPath)));
|
package/dist/plugins/asset.js
CHANGED
|
@@ -48,8 +48,8 @@ const pluginAsset = () => ({
|
|
|
48
48
|
const config = api.getNormalizedConfig();
|
|
49
49
|
const createAssetRule = (assetType, exts) => {
|
|
50
50
|
const regExp = getRegExpForExts(exts);
|
|
51
|
-
const distDir = (0, import_shared.getDistPath)(config
|
|
52
|
-
const filename = (0, import_shared.getFilename)(config
|
|
51
|
+
const distDir = (0, import_shared.getDistPath)(config, assetType);
|
|
52
|
+
const filename = (0, import_shared.getFilename)(config, assetType, isProd);
|
|
53
53
|
const maxSize = config.output.dataUriLimit[assetType];
|
|
54
54
|
const rule = chain.module.rule(assetType).test(regExp);
|
|
55
55
|
(0, import_shared.chainStaticAssetRule)({
|
|
@@ -0,0 +1,68 @@
|
|
|
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 basic_exports = {};
|
|
30
|
+
__export(basic_exports, {
|
|
31
|
+
pluginBasic: () => pluginBasic
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(basic_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_shared = require("@rsbuild/shared");
|
|
36
|
+
const pluginBasic = () => ({
|
|
37
|
+
name: "rsbuild:basic",
|
|
38
|
+
setup(api) {
|
|
39
|
+
api.modifyBundlerChain((chain, { env, isProd, target }) => {
|
|
40
|
+
const config = api.getNormalizedConfig();
|
|
41
|
+
chain.name(import_shared.TARGET_ID_MAP[target]);
|
|
42
|
+
chain.devtool((0, import_shared.getJsSourceMap)(config));
|
|
43
|
+
chain.context(api.context.rootPath);
|
|
44
|
+
chain.mode(isProd ? "production" : "development");
|
|
45
|
+
chain.merge({
|
|
46
|
+
infrastructureLogging: {
|
|
47
|
+
// Using `error` level to avoid `cache.PackFileCacheStrategy` logs
|
|
48
|
+
level: "error"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
chain.performance.hints(false);
|
|
52
|
+
chain.module.parser.merge({
|
|
53
|
+
javascript: {
|
|
54
|
+
exportsPresence: "error"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (env === "development") {
|
|
58
|
+
chain.output.devtoolModuleFilenameTemplate(
|
|
59
|
+
(info) => import_path.default.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
pluginBasic
|
|
68
|
+
});
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HtmlConfig, RsbuildPluginAPI, NormalizedConfig
|
|
1
|
+
import type { HtmlConfig, RsbuildPluginAPI, NormalizedConfig } 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;
|
|
@@ -11,7 +11,6 @@ export declare function getFavicon(entryName: string, config: {
|
|
|
11
11
|
}): string;
|
|
12
12
|
export declare function getMetaTags(entryName: string, config: {
|
|
13
13
|
html: HtmlConfig;
|
|
14
|
-
output: NormalizedOutputConfig;
|
|
15
14
|
}, templateContent?: string): import("@rsbuild/shared").MetaOptions;
|
|
16
15
|
export declare const applyInjectTags: (api: RsbuildPluginAPI) => void;
|
|
17
16
|
export declare const pluginHtml: () => RsbuildPlugin;
|
package/dist/plugins/html.js
CHANGED
|
@@ -142,7 +142,7 @@ function getChunks(entryName, entryValue) {
|
|
|
142
142
|
return [...dependOn, entryName];
|
|
143
143
|
}
|
|
144
144
|
const applyInjectTags = (api) => {
|
|
145
|
-
api.modifyBundlerChain(async (chain, {
|
|
145
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
146
146
|
const config = api.getNormalizedConfig();
|
|
147
147
|
const tags = (0, import_shared.castArray)(config.html.tags).filter(Boolean);
|
|
148
148
|
const tagsByEntries = config.html.tagsByEntries || {};
|
|
@@ -157,7 +157,6 @@ const applyInjectTags = (api) => {
|
|
|
157
157
|
}
|
|
158
158
|
const { HtmlTagsPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlTagsPlugin")));
|
|
159
159
|
const sharedOptions = {
|
|
160
|
-
HtmlPlugin,
|
|
161
160
|
append: true,
|
|
162
161
|
hash: false,
|
|
163
162
|
publicPath: true,
|
|
@@ -215,11 +214,12 @@ const pluginHtml = () => ({
|
|
|
215
214
|
minify,
|
|
216
215
|
filename,
|
|
217
216
|
template: templatePath,
|
|
217
|
+
entryName,
|
|
218
218
|
templateParameters,
|
|
219
219
|
scriptLoading: config.html.scriptLoading
|
|
220
220
|
};
|
|
221
221
|
const htmlInfo = {};
|
|
222
|
-
htmlInfoMap[
|
|
222
|
+
htmlInfoMap[entryName] = htmlInfo;
|
|
223
223
|
if (templateContent) {
|
|
224
224
|
htmlInfo.templateContent = templateContent;
|
|
225
225
|
}
|
|
@@ -247,12 +247,12 @@ const pluginHtml = () => ({
|
|
|
247
247
|
})
|
|
248
248
|
);
|
|
249
249
|
const { HtmlBasicPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlBasicPlugin")));
|
|
250
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin, [{
|
|
250
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin, [{ info: htmlInfoMap }]);
|
|
251
251
|
if (config.security) {
|
|
252
252
|
const { nonce } = config.security;
|
|
253
253
|
if (nonce) {
|
|
254
254
|
const { HtmlNoncePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlNoncePlugin")));
|
|
255
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_NONCE).use(HtmlNoncePlugin, [{ nonce
|
|
255
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_NONCE).use(HtmlNoncePlugin, [{ nonce }]);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
if (config.html) {
|
|
@@ -261,15 +261,15 @@ const pluginHtml = () => ({
|
|
|
261
261
|
const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlCrossOriginPlugin")));
|
|
262
262
|
const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
263
263
|
chain.plugin(CHAIN_ID.PLUGIN.HTML_CROSS_ORIGIN).use(HtmlCrossOriginPlugin, [
|
|
264
|
-
{ crossOrigin: formattedCrossorigin
|
|
264
|
+
{ crossOrigin: formattedCrossorigin }
|
|
265
265
|
]);
|
|
266
266
|
chain.output.crossOriginLoading(formattedCrossorigin);
|
|
267
267
|
}
|
|
268
268
|
if (appIcon) {
|
|
269
269
|
const { HtmlAppIconPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlAppIconPlugin")));
|
|
270
|
-
const distDir = (0, import_shared.getDistPath)(config
|
|
270
|
+
const distDir = (0, import_shared.getDistPath)(config, "image");
|
|
271
271
|
const iconPath = import_path.default.isAbsolute(appIcon) ? appIcon : import_path.default.join(api.context.rootPath, appIcon);
|
|
272
|
-
chain.plugin(CHAIN_ID.PLUGIN.APP_ICON).use(HtmlAppIconPlugin, [{ iconPath, distDir
|
|
272
|
+
chain.plugin(CHAIN_ID.PLUGIN.APP_ICON).use(HtmlAppIconPlugin, [{ iconPath, distDir }]);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
}
|
package/dist/plugins/index.js
CHANGED
|
@@ -32,11 +32,11 @@ __export(plugins_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(plugins_exports);
|
|
34
34
|
const plugins = {
|
|
35
|
+
basic: () => Promise.resolve().then(() => __toESM(require("./basic"))).then((m) => m.pluginBasic()),
|
|
35
36
|
html: () => Promise.resolve().then(() => __toESM(require("./html"))).then((m) => m.pluginHtml()),
|
|
36
37
|
cleanOutput: () => Promise.resolve().then(() => __toESM(require("./cleanOutput"))).then((m) => m.pluginCleanOutput()),
|
|
37
38
|
startUrl: () => Promise.resolve().then(() => __toESM(require("./startUrl"))).then((m) => m.pluginStartUrl()),
|
|
38
39
|
fileSize: () => Promise.resolve().then(() => __toESM(require("./fileSize"))).then((m) => m.pluginFileSize()),
|
|
39
|
-
devtool: () => Promise.resolve().then(() => __toESM(require("./devtool"))).then((m) => m.pluginDevtool()),
|
|
40
40
|
target: () => Promise.resolve().then(() => __toESM(require("./target"))).then((m) => m.pluginTarget()),
|
|
41
41
|
entry: () => Promise.resolve().then(() => __toESM(require("./entry"))).then((m) => m.pluginEntry()),
|
|
42
42
|
cache: () => Promise.resolve().then(() => __toESM(require("./cache"))).then((m) => m.pluginCache()),
|
|
@@ -53,8 +53,7 @@ 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())
|
|
57
|
-
server: () => Promise.resolve().then(() => __toESM(require("./server"))).then((m) => m.pluginServer())
|
|
56
|
+
define: () => Promise.resolve().then(() => __toESM(require("./define"))).then((m) => m.pluginDefine())
|
|
58
57
|
};
|
|
59
58
|
// Annotate the CommonJS export names for ESM import in node:
|
|
60
59
|
0 && (module.exports = {
|
|
@@ -35,35 +35,32 @@ var import_shared = require("@rsbuild/shared");
|
|
|
35
35
|
const pluginInlineChunk = () => ({
|
|
36
36
|
name: "rsbuild:inline-chunk",
|
|
37
37
|
setup(api) {
|
|
38
|
-
api.modifyBundlerChain(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/InlineChunkHtmlPlugin")));
|
|
45
|
-
const { inlineStyles, inlineScripts } = config.output;
|
|
46
|
-
const scriptTests = [];
|
|
47
|
-
const styleTests = [];
|
|
48
|
-
if (inlineScripts) {
|
|
49
|
-
scriptTests.push(inlineScripts === true ? import_shared.JS_REGEX : inlineScripts);
|
|
50
|
-
}
|
|
51
|
-
if (inlineStyles) {
|
|
52
|
-
styleTests.push(inlineStyles === true ? import_shared.CSS_REGEX : inlineStyles);
|
|
53
|
-
}
|
|
54
|
-
if (!scriptTests.length && !styleTests.length) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
|
|
58
|
-
HtmlPlugin,
|
|
59
|
-
{
|
|
60
|
-
styleTests,
|
|
61
|
-
scriptTests,
|
|
62
|
-
distPath: (0, import_shared.pick)(config.output.distPath, ["js", "css"])
|
|
63
|
-
}
|
|
64
|
-
]);
|
|
38
|
+
api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd }) => {
|
|
39
|
+
const config = api.getNormalizedConfig();
|
|
40
|
+
if ((0, import_shared.isHtmlDisabled)(config, target) || !isProd) {
|
|
41
|
+
return;
|
|
65
42
|
}
|
|
66
|
-
|
|
43
|
+
const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/InlineChunkHtmlPlugin")));
|
|
44
|
+
const { inlineStyles, inlineScripts } = config.output;
|
|
45
|
+
const scriptTests = [];
|
|
46
|
+
const styleTests = [];
|
|
47
|
+
if (inlineScripts) {
|
|
48
|
+
scriptTests.push(inlineScripts === true ? import_shared.JS_REGEX : inlineScripts);
|
|
49
|
+
}
|
|
50
|
+
if (inlineStyles) {
|
|
51
|
+
styleTests.push(inlineStyles === true ? import_shared.CSS_REGEX : inlineStyles);
|
|
52
|
+
}
|
|
53
|
+
if (!scriptTests.length && !styleTests.length) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
|
|
57
|
+
{
|
|
58
|
+
styleTests,
|
|
59
|
+
scriptTests,
|
|
60
|
+
distPath: (0, import_shared.pick)(config.output.distPath, ["js", "css"])
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
67
64
|
}
|
|
68
65
|
});
|
|
69
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -35,7 +35,7 @@ const pluginNetworkPerformance = () => ({
|
|
|
35
35
|
name: `plugin-network-performance`,
|
|
36
36
|
setup(api) {
|
|
37
37
|
api.modifyBundlerChain(
|
|
38
|
-
async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker
|
|
38
|
+
async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker }) => {
|
|
39
39
|
const config = api.getNormalizedConfig();
|
|
40
40
|
const {
|
|
41
41
|
performance: { dnsPrefetch, preconnect }
|
|
@@ -45,18 +45,10 @@ const pluginNetworkPerformance = () => ({
|
|
|
45
45
|
}
|
|
46
46
|
const { HtmlNetworkPerformancePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlNetworkPerformancePlugin")));
|
|
47
47
|
if (dnsPrefetch) {
|
|
48
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(HtmlNetworkPerformancePlugin, [
|
|
49
|
-
dnsPrefetch,
|
|
50
|
-
"dnsPrefetch",
|
|
51
|
-
HtmlPlugin
|
|
52
|
-
]);
|
|
48
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(HtmlNetworkPerformancePlugin, [dnsPrefetch, "dnsPrefetch"]);
|
|
53
49
|
}
|
|
54
50
|
if (preconnect) {
|
|
55
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(HtmlNetworkPerformancePlugin, [
|
|
56
|
-
preconnect,
|
|
57
|
-
"preconnect",
|
|
58
|
-
HtmlPlugin
|
|
59
|
-
]);
|
|
51
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(HtmlNetworkPerformancePlugin, [preconnect, "preconnect"]);
|
|
60
52
|
}
|
|
61
53
|
}
|
|
62
54
|
);
|
|
@@ -54,7 +54,7 @@ const pluginNodeAddons = () => ({
|
|
|
54
54
|
};
|
|
55
55
|
const { name: pkgName } = require(pkgJSON);
|
|
56
56
|
const config = api.getNormalizedConfig();
|
|
57
|
-
const serverPath = (0, import_shared.getDistPath)(config
|
|
57
|
+
const serverPath = (0, import_shared.getDistPath)(config, "server");
|
|
58
58
|
return `${serverPath}/${getFilename(resourcePath, pkgName)}`;
|
|
59
59
|
};
|
|
60
60
|
chain.module.rule(CHAIN_ID.RULE.NODE).test(/\.node$/).use(CHAIN_ID.USE.NODE).loader((0, import_shared.getSharedPkgCompiledPath)("node-loader")).options({
|
|
@@ -35,7 +35,7 @@ const pluginPreloadOrPrefetch = () => ({
|
|
|
35
35
|
name: `plugin-preload-or-prefetch`,
|
|
36
36
|
setup(api) {
|
|
37
37
|
api.modifyBundlerChain(
|
|
38
|
-
async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker
|
|
38
|
+
async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker }) => {
|
|
39
39
|
const config = api.getNormalizedConfig();
|
|
40
40
|
const {
|
|
41
41
|
performance: { preload, prefetch }
|
|
@@ -44,22 +44,16 @@ const pluginPreloadOrPrefetch = () => ({
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const HTMLCount = chain.entryPoints.values().length;
|
|
47
|
-
const {
|
|
47
|
+
const { HtmlPreloadOrPrefetchPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/preload/HtmlPreloadOrPrefetchPlugin")));
|
|
48
48
|
if (prefetch) {
|
|
49
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(
|
|
49
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HtmlPreloadOrPrefetchPlugin, [
|
|
50
50
|
prefetch,
|
|
51
51
|
"prefetch",
|
|
52
|
-
HtmlPlugin,
|
|
53
52
|
HTMLCount
|
|
54
53
|
]);
|
|
55
54
|
}
|
|
56
55
|
if (preload) {
|
|
57
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(
|
|
58
|
-
preload,
|
|
59
|
-
"preload",
|
|
60
|
-
HtmlPlugin,
|
|
61
|
-
HTMLCount
|
|
62
|
-
]);
|
|
56
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HtmlPreloadOrPrefetchPlugin, [preload, "preload", HTMLCount]);
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
59
|
);
|
package/dist/plugins/wasm.js
CHANGED
|
@@ -28,7 +28,7 @@ const pluginWasm = () => ({
|
|
|
28
28
|
setup(api) {
|
|
29
29
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
30
30
|
const config = api.getNormalizedConfig();
|
|
31
|
-
const distPath = (0, import_shared.getDistPath)(config
|
|
31
|
+
const distPath = (0, import_shared.getDistPath)(config, "wasm");
|
|
32
32
|
chain.experiments({
|
|
33
33
|
...chain.get("experiments"),
|
|
34
34
|
asyncWebAssembly: true
|
|
@@ -53,16 +53,23 @@ async function createCompiler({
|
|
|
53
53
|
}
|
|
54
54
|
const compiler = rspackConfigs.length === 1 ? rspack(rspackConfigs[0]) : rspack(rspackConfigs);
|
|
55
55
|
let isFirstCompile = true;
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
let isVersionLogged = false;
|
|
57
|
+
let isCompiling = false;
|
|
58
|
+
const logRspackVersion = () => {
|
|
59
|
+
if (!isVersionLogged) {
|
|
58
60
|
import_shared.logger.start(`Use Rspack v${rspack.rspackVersion}`);
|
|
61
|
+
isVersionLogged = true;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
|
|
65
|
+
logRspackVersion();
|
|
66
|
+
if (!isCompiling) {
|
|
67
|
+
import_shared.logger.start("Compiling...");
|
|
59
68
|
}
|
|
60
|
-
|
|
69
|
+
isCompiling = true;
|
|
61
70
|
});
|
|
62
71
|
if ((0, import_shared.isProd)()) {
|
|
63
|
-
compiler.hooks.run.tap("rsbuild:run",
|
|
64
|
-
import_shared.logger.start(`Use Rspack v${rspack.rspackVersion}`);
|
|
65
|
-
});
|
|
72
|
+
compiler.hooks.run.tap("rsbuild:run", logRspackVersion);
|
|
66
73
|
}
|
|
67
74
|
compiler.hooks.done.tap("rsbuild:done", async (stats) => {
|
|
68
75
|
const obj = stats.toJson({
|
|
@@ -72,7 +79,7 @@ async function createCompiler({
|
|
|
72
79
|
const printTime = (c, index) => {
|
|
73
80
|
if (c.time) {
|
|
74
81
|
const time = (0, import_shared.prettyTime)(c.time / 1e3);
|
|
75
|
-
const target =
|
|
82
|
+
const target = context.targets[index];
|
|
76
83
|
const name = import_shared.TARGET_ID_MAP[target || "web"];
|
|
77
84
|
import_shared.logger.ready(`${name} compiled in ${time}`);
|
|
78
85
|
}
|
|
@@ -98,6 +105,7 @@ async function createCompiler({
|
|
|
98
105
|
isFirstCompile
|
|
99
106
|
});
|
|
100
107
|
}
|
|
108
|
+
isCompiling = false;
|
|
101
109
|
isFirstCompile = false;
|
|
102
110
|
});
|
|
103
111
|
await context.hooks.onAfterCreateCompilerHook.call({ compiler });
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { RsbuildConfig, type Context as BaseContext, type BundlerType, type
|
|
1
|
+
import { RsbuildConfig, type Context as BaseContext, type BundlerType, type NormalizedConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
2
2
|
import type { Context } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* Create context by config.
|
|
5
5
|
*/
|
|
6
|
-
export declare function createContextByConfig(options: Required<CreateRsbuildOptions>, bundlerType: BundlerType,
|
|
6
|
+
export declare function createContextByConfig(options: Required<CreateRsbuildOptions>, bundlerType: BundlerType, config?: RsbuildConfig): BaseContext;
|
|
7
7
|
export declare function updateContextByNormalizedConfig(context: BaseContext, config: NormalizedConfig): void;
|
|
8
8
|
export declare function createPublicContext(context: BaseContext): Readonly<BaseContext>;
|
|
9
9
|
/**
|
|
10
10
|
* Generate the actual context used in the build,
|
|
11
11
|
* which can have a lot of overhead and take some side effects.
|
|
12
12
|
*/
|
|
13
|
-
export declare function createContext(options: Required<CreateRsbuildOptions>, userRsbuildConfig: RsbuildConfig): Promise<Context>;
|
|
13
|
+
export declare function createContext(options: Required<CreateRsbuildOptions>, userRsbuildConfig: RsbuildConfig, bundlerType: BundlerType): Promise<Context>;
|
|
@@ -47,29 +47,19 @@ function getDefaultEntry(root) {
|
|
|
47
47
|
}
|
|
48
48
|
return {};
|
|
49
49
|
}
|
|
50
|
-
function getAbsoluteDistPath(cwd,
|
|
51
|
-
const root = (0, import_shared.getDistPath)(
|
|
50
|
+
function getAbsoluteDistPath(cwd, config) {
|
|
51
|
+
const root = (0, import_shared.getDistPath)(config, "root");
|
|
52
52
|
return (0, import_path.isAbsolute)(root) ? root : (0, import_path.join)(cwd, root);
|
|
53
53
|
}
|
|
54
|
-
function createContextByConfig(options, bundlerType,
|
|
55
|
-
const { cwd
|
|
54
|
+
function createContextByConfig(options, bundlerType, config = {}) {
|
|
55
|
+
const { cwd } = options;
|
|
56
56
|
const rootPath = cwd;
|
|
57
|
-
const distPath = getAbsoluteDistPath(cwd,
|
|
57
|
+
const distPath = getAbsoluteDistPath(cwd, config);
|
|
58
58
|
const cachePath = (0, import_path.join)(rootPath, "node_modules", ".cache");
|
|
59
|
-
if (sourceConfig.entries) {
|
|
60
|
-
import_shared.logger.warn(
|
|
61
|
-
"[Rsbuild] `source.entries` option has been renamed to `source.entry`, please update the Rsbuild config."
|
|
62
|
-
);
|
|
63
|
-
import_shared.logger.warn(
|
|
64
|
-
"[Rsbuild] `source.entries` option will be removed in Rsbuild v0.2.0."
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
59
|
const context = {
|
|
68
|
-
entry:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
version: "0.1.9",
|
|
72
|
-
target,
|
|
60
|
+
entry: config.source?.entry || getDefaultEntry(rootPath),
|
|
61
|
+
targets: config.output?.targets || [],
|
|
62
|
+
version: "0.2.0",
|
|
73
63
|
rootPath,
|
|
74
64
|
distPath,
|
|
75
65
|
cachePath,
|
|
@@ -78,7 +68,8 @@ function createContextByConfig(options, bundlerType, sourceConfig = {}, outputCo
|
|
|
78
68
|
return context;
|
|
79
69
|
}
|
|
80
70
|
function updateContextByNormalizedConfig(context, config) {
|
|
81
|
-
context.
|
|
71
|
+
context.targets = config.output.targets;
|
|
72
|
+
context.distPath = getAbsoluteDistPath(context.rootPath, config);
|
|
82
73
|
if (config.source.entry) {
|
|
83
74
|
context.entry = config.source.entry;
|
|
84
75
|
}
|
|
@@ -86,7 +77,7 @@ function updateContextByNormalizedConfig(context, config) {
|
|
|
86
77
|
function createPublicContext(context) {
|
|
87
78
|
const exposedKeys = [
|
|
88
79
|
"entry",
|
|
89
|
-
"
|
|
80
|
+
"targets",
|
|
90
81
|
"version",
|
|
91
82
|
"rootPath",
|
|
92
83
|
"distPath",
|
|
@@ -111,14 +102,9 @@ function createPublicContext(context) {
|
|
|
111
102
|
}
|
|
112
103
|
});
|
|
113
104
|
}
|
|
114
|
-
async function createContext(options, userRsbuildConfig) {
|
|
105
|
+
async function createContext(options, userRsbuildConfig, bundlerType) {
|
|
115
106
|
const rsbuildConfig = (0, import_config.withDefaultConfig)(userRsbuildConfig);
|
|
116
|
-
const context = createContextByConfig(
|
|
117
|
-
options,
|
|
118
|
-
"rspack",
|
|
119
|
-
rsbuildConfig.source,
|
|
120
|
-
rsbuildConfig.output
|
|
121
|
-
);
|
|
107
|
+
const context = createContextByConfig(options, bundlerType, rsbuildConfig);
|
|
122
108
|
const tsconfigPath = (0, import_path.join)(context.rootPath, import_shared.TS_CONFIG_FILE);
|
|
123
109
|
return {
|
|
124
110
|
...context,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PluginStore, type RspackConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
2
|
-
import type { Context } from '../../types';
|
|
2
|
+
import type { Context, NormalizedConfig } from '../../types';
|
|
3
3
|
export type InitConfigsOptions = {
|
|
4
4
|
context: Context;
|
|
5
5
|
pluginStore: PluginStore;
|
|
@@ -8,7 +8,7 @@ export type InitConfigsOptions = {
|
|
|
8
8
|
export declare function initRsbuildConfig({
|
|
9
9
|
context,
|
|
10
10
|
pluginStore
|
|
11
|
-
}: Pick<InitConfigsOptions, 'context' | 'pluginStore'>): Promise<
|
|
11
|
+
}: Pick<InitConfigsOptions, 'context' | 'pluginStore'>): Promise<NormalizedConfig>;
|
|
12
12
|
export declare function initConfigs({
|
|
13
13
|
context,
|
|
14
14
|
pluginStore,
|