@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 +393 -381
- package/dist/index.js +412 -400
- package/dist/transformLoader.cjs +2 -1
- package/dist/transformRawLoader.cjs +2 -1
- package/dist-types/configChain.d.ts +0 -2
- package/dist-types/loader/transformLoader.d.ts +5 -3
- package/dist-types/plugins/appIcon.d.ts +2 -0
- package/dist-types/types/hooks.d.ts +7 -1
- package/dist-types/types/plugin.d.ts +35 -5
- package/package.json +2 -2
- package/dist-types/rspack/HtmlAppIconPlugin.d.ts +0 -13
- package/dist-types/rspack/InlineChunkHtmlPlugin.d.ts +0 -29
package/dist/index.js
CHANGED
|
@@ -46,12 +46,12 @@ var __publicField = (obj, key, value) => {
|
|
|
46
46
|
return value;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
49
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.56.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
50
50
|
import { fileURLToPath } from "url";
|
|
51
51
|
import path from "path";
|
|
52
52
|
var getFilename, getDirname, __dirname, __filename;
|
|
53
53
|
var init_esm = __esm({
|
|
54
|
-
"../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
54
|
+
"../../node_modules/.pnpm/@modern-js+module-tools@2.56.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js"() {
|
|
55
55
|
"use strict";
|
|
56
56
|
getFilename = () => fileURLToPath(import.meta.url);
|
|
57
57
|
getDirname = () => path.dirname(getFilename());
|
|
@@ -427,12 +427,12 @@ function formatStats(stats, options = {}) {
|
|
|
427
427
|
}
|
|
428
428
|
return {};
|
|
429
429
|
}
|
|
430
|
-
function isEmptyDir(
|
|
431
|
-
const files = fs.readdirSync(
|
|
430
|
+
function isEmptyDir(path20) {
|
|
431
|
+
const files = fs.readdirSync(path20);
|
|
432
432
|
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
433
433
|
}
|
|
434
|
-
async function pathExists(
|
|
435
|
-
return fs.promises.access(
|
|
434
|
+
async function pathExists(path20) {
|
|
435
|
+
return fs.promises.access(path20).then(() => true).catch(() => false);
|
|
436
436
|
}
|
|
437
437
|
async function isFileExists(file) {
|
|
438
438
|
return fs.promises.access(file, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
@@ -708,9 +708,9 @@ ${color2.yellow(tips.join("\n"))}`;
|
|
|
708
708
|
}
|
|
709
709
|
return false;
|
|
710
710
|
};
|
|
711
|
-
urlJoin = (base,
|
|
711
|
+
urlJoin = (base, path20) => {
|
|
712
712
|
const fullUrl = new URL(base);
|
|
713
|
-
fullUrl.pathname = posix.join(fullUrl.pathname,
|
|
713
|
+
fullUrl.pathname = posix.join(fullUrl.pathname, path20);
|
|
714
714
|
return fullUrl.toString();
|
|
715
715
|
};
|
|
716
716
|
canParse = (url2) => {
|
|
@@ -822,8 +822,8 @@ var init_mergeConfig = __esm({
|
|
|
822
822
|
}
|
|
823
823
|
return OVERRIDE_PATHS.includes(key);
|
|
824
824
|
};
|
|
825
|
-
merge = (x, y,
|
|
826
|
-
if (isOverridePath(
|
|
825
|
+
merge = (x, y, path20 = "") => {
|
|
826
|
+
if (isOverridePath(path20)) {
|
|
827
827
|
return y ?? x;
|
|
828
828
|
}
|
|
829
829
|
if (x === void 0) {
|
|
@@ -845,7 +845,7 @@ var init_mergeConfig = __esm({
|
|
|
845
845
|
const merged = {};
|
|
846
846
|
const keys = /* @__PURE__ */ new Set([...Object.keys(x), ...Object.keys(y)]);
|
|
847
847
|
for (const key of keys) {
|
|
848
|
-
const childPath =
|
|
848
|
+
const childPath = path20 ? `${path20}.${key}` : key;
|
|
849
849
|
merged[key] = merge(x[key], y[key], childPath);
|
|
850
850
|
}
|
|
851
851
|
return merged;
|
|
@@ -956,10 +956,10 @@ async function watchFiles(files) {
|
|
|
956
956
|
}
|
|
957
957
|
async function loadConfig({
|
|
958
958
|
cwd = process.cwd(),
|
|
959
|
-
path:
|
|
959
|
+
path: path20,
|
|
960
960
|
envMode
|
|
961
961
|
} = {}) {
|
|
962
|
-
const configFilePath = resolveConfigPath(cwd,
|
|
962
|
+
const configFilePath = resolveConfigPath(cwd, path20);
|
|
963
963
|
if (!configFilePath) {
|
|
964
964
|
return {
|
|
965
965
|
content: {},
|
|
@@ -1493,23 +1493,6 @@ function getHTMLPathByEntry(entryName, config) {
|
|
|
1493
1493
|
const filename = config.html.outputStructure === "flat" ? `${entryName}.html` : `${entryName}/index.html`;
|
|
1494
1494
|
return removeLeadingSlash(`${config.output.distPath.html}/${filename}`);
|
|
1495
1495
|
}
|
|
1496
|
-
function applyTransformPlugin(chain, transformer) {
|
|
1497
|
-
const name = "RsbuildTransformPlugin";
|
|
1498
|
-
if (chain.plugins.get(name)) {
|
|
1499
|
-
return;
|
|
1500
|
-
}
|
|
1501
|
-
class RsbuildTransformPlugin {
|
|
1502
|
-
apply(compiler) {
|
|
1503
|
-
compiler.__rsbuildTransformer = transformer;
|
|
1504
|
-
compiler.hooks.thisCompilation.tap(name, (compilation) => {
|
|
1505
|
-
compilation.hooks.childCompiler.tap(name, (childCompiler) => {
|
|
1506
|
-
childCompiler.__rsbuildTransformer = transformer;
|
|
1507
|
-
});
|
|
1508
|
-
});
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
chain.plugin(name).use(RsbuildTransformPlugin);
|
|
1512
|
-
}
|
|
1513
1496
|
function getPluginAPI({
|
|
1514
1497
|
context,
|
|
1515
1498
|
pluginManager
|
|
@@ -1556,6 +1539,40 @@ function getPluginAPI({
|
|
|
1556
1539
|
};
|
|
1557
1540
|
let transformId = 0;
|
|
1558
1541
|
const transformer = {};
|
|
1542
|
+
const processAssetsFns = [];
|
|
1543
|
+
hooks.modifyBundlerChain.tap((chain, { target, environment }) => {
|
|
1544
|
+
const pluginName = "RsbuildCorePlugin";
|
|
1545
|
+
class RsbuildCorePlugin {
|
|
1546
|
+
apply(compiler) {
|
|
1547
|
+
compiler.__rsbuildTransformer = transformer;
|
|
1548
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
1549
|
+
compilation.hooks.childCompiler.tap(pluginName, (childCompiler) => {
|
|
1550
|
+
childCompiler.__rsbuildTransformer = transformer;
|
|
1551
|
+
});
|
|
1552
|
+
});
|
|
1553
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
1554
|
+
for (const { descriptor, handler } of processAssetsFns) {
|
|
1555
|
+
if (descriptor.targets && !descriptor.targets.includes(target)) {
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
compilation.hooks.processAssets.tapPromise(
|
|
1559
|
+
{
|
|
1560
|
+
name: pluginName,
|
|
1561
|
+
stage: mapProcessAssetsStage(compiler, descriptor.stage)
|
|
1562
|
+
},
|
|
1563
|
+
async (assets) => handler({
|
|
1564
|
+
assets,
|
|
1565
|
+
compiler,
|
|
1566
|
+
compilation,
|
|
1567
|
+
environment
|
|
1568
|
+
})
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
chain.plugin(pluginName).use(RsbuildCorePlugin);
|
|
1575
|
+
});
|
|
1559
1576
|
const transform = (descriptor, handler) => {
|
|
1560
1577
|
const id = `rsbuild-transform-${transformId++}`;
|
|
1561
1578
|
transformer[id] = handler;
|
|
@@ -1575,10 +1592,15 @@ function getPluginAPI({
|
|
|
1575
1592
|
}
|
|
1576
1593
|
const loaderName = descriptor.raw ? "transformRawLoader.cjs" : "transformLoader.cjs";
|
|
1577
1594
|
const loaderPath = join5(LOADER_PATH, loaderName);
|
|
1578
|
-
rule.use(id).loader(loaderPath).options({
|
|
1579
|
-
|
|
1595
|
+
rule.use(id).loader(loaderPath).options({
|
|
1596
|
+
id,
|
|
1597
|
+
getEnvironment: () => environment
|
|
1598
|
+
});
|
|
1580
1599
|
});
|
|
1581
1600
|
};
|
|
1601
|
+
const processAssets = (descriptor, handler) => {
|
|
1602
|
+
processAssetsFns.push({ descriptor, handler });
|
|
1603
|
+
};
|
|
1582
1604
|
process.on("exit", () => {
|
|
1583
1605
|
hooks.onExit.call();
|
|
1584
1606
|
});
|
|
@@ -1587,6 +1609,7 @@ function getPluginAPI({
|
|
|
1587
1609
|
expose,
|
|
1588
1610
|
transform,
|
|
1589
1611
|
useExposed,
|
|
1612
|
+
processAssets,
|
|
1590
1613
|
getRsbuildConfig,
|
|
1591
1614
|
getNormalizedConfig,
|
|
1592
1615
|
isPluginExists: pluginManager.isPluginExists,
|
|
@@ -1611,6 +1634,7 @@ function getPluginAPI({
|
|
|
1611
1634
|
modifyEnvironmentConfig: hooks.modifyEnvironmentConfig.tap
|
|
1612
1635
|
};
|
|
1613
1636
|
}
|
|
1637
|
+
var mapProcessAssetsStage;
|
|
1614
1638
|
var init_initPlugins = __esm({
|
|
1615
1639
|
"src/initPlugins.ts"() {
|
|
1616
1640
|
"use strict";
|
|
@@ -1618,6 +1642,45 @@ var init_initPlugins = __esm({
|
|
|
1618
1642
|
init_constants();
|
|
1619
1643
|
init_createContext();
|
|
1620
1644
|
init_helpers();
|
|
1645
|
+
mapProcessAssetsStage = (compiler, stage) => {
|
|
1646
|
+
const { Compilation } = compiler.webpack;
|
|
1647
|
+
switch (stage) {
|
|
1648
|
+
case "additional":
|
|
1649
|
+
return Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL;
|
|
1650
|
+
case "pre-process":
|
|
1651
|
+
return Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS;
|
|
1652
|
+
case "derived":
|
|
1653
|
+
return Compilation.PROCESS_ASSETS_STAGE_DERIVED;
|
|
1654
|
+
case "additions":
|
|
1655
|
+
return Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;
|
|
1656
|
+
case "none":
|
|
1657
|
+
return Compilation.PROCESS_ASSETS_STAGE_NONE;
|
|
1658
|
+
case "optimize":
|
|
1659
|
+
return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE;
|
|
1660
|
+
case "optimize-count":
|
|
1661
|
+
return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COUNT;
|
|
1662
|
+
case "optimize-compatibility":
|
|
1663
|
+
return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY;
|
|
1664
|
+
case "optimize-size":
|
|
1665
|
+
return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE;
|
|
1666
|
+
case "dev-tooling":
|
|
1667
|
+
return Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING;
|
|
1668
|
+
case "optimize-inline":
|
|
1669
|
+
return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE;
|
|
1670
|
+
case "summarize":
|
|
1671
|
+
return Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
|
|
1672
|
+
case "optimize-hash":
|
|
1673
|
+
return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH;
|
|
1674
|
+
case "optimize-transfer":
|
|
1675
|
+
return Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER;
|
|
1676
|
+
case "analyse":
|
|
1677
|
+
return Compilation.PROCESS_ASSETS_STAGE_ANALYSE;
|
|
1678
|
+
case "report":
|
|
1679
|
+
return Compilation.PROCESS_ASSETS_STAGE_REPORT;
|
|
1680
|
+
default:
|
|
1681
|
+
throw new Error(`Invalid process assets stage: ${stage}`);
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1621
1684
|
}
|
|
1622
1685
|
});
|
|
1623
1686
|
|
|
@@ -1636,33 +1699,33 @@ async function createContextByConfig(options, bundlerType) {
|
|
|
1636
1699
|
const rootPath = cwd;
|
|
1637
1700
|
const cachePath = join6(rootPath, "node_modules", ".cache");
|
|
1638
1701
|
return {
|
|
1639
|
-
version: "1.0.1-beta.
|
|
1702
|
+
version: "1.0.1-beta.4",
|
|
1640
1703
|
rootPath,
|
|
1641
1704
|
distPath: "",
|
|
1642
1705
|
cachePath,
|
|
1643
1706
|
bundlerType
|
|
1644
1707
|
};
|
|
1645
1708
|
}
|
|
1646
|
-
async function getBrowserslist(
|
|
1709
|
+
async function getBrowserslist(path20) {
|
|
1647
1710
|
const env = process.env.NODE_ENV;
|
|
1648
|
-
const cacheKey =
|
|
1711
|
+
const cacheKey = path20 + env;
|
|
1649
1712
|
if (browsersListCache.has(cacheKey)) {
|
|
1650
1713
|
return browsersListCache.get(cacheKey);
|
|
1651
1714
|
}
|
|
1652
|
-
const result = browserslist.loadConfig({ path:
|
|
1715
|
+
const result = browserslist.loadConfig({ path: path20, env });
|
|
1653
1716
|
if (result) {
|
|
1654
1717
|
browsersListCache.set(cacheKey, result);
|
|
1655
1718
|
return result;
|
|
1656
1719
|
}
|
|
1657
1720
|
return null;
|
|
1658
1721
|
}
|
|
1659
|
-
async function getBrowserslistByEnvironment(
|
|
1722
|
+
async function getBrowserslistByEnvironment(path20, config) {
|
|
1660
1723
|
const { target, overrideBrowserslist } = config.output;
|
|
1661
1724
|
if (Array.isArray(overrideBrowserslist)) {
|
|
1662
1725
|
return overrideBrowserslist;
|
|
1663
1726
|
}
|
|
1664
1727
|
if (target === "web" || target === "web-worker") {
|
|
1665
|
-
const browserslistrc = await getBrowserslist(
|
|
1728
|
+
const browserslistrc = await getBrowserslist(path20);
|
|
1666
1729
|
if (browserslistrc) {
|
|
1667
1730
|
return browserslistrc;
|
|
1668
1731
|
}
|
|
@@ -2314,8 +2377,6 @@ var init_configChain = __esm({
|
|
|
2314
2377
|
MANIFEST: "webpack-manifest",
|
|
2315
2378
|
/** ForkTsCheckerWebpackPlugin */
|
|
2316
2379
|
TS_CHECKER: "ts-checker",
|
|
2317
|
-
/** InlineChunkHtmlPlugin */
|
|
2318
|
-
INLINE_HTML: "inline-html",
|
|
2319
2380
|
/** WebpackBundleAnalyzer */
|
|
2320
2381
|
BUNDLE_ANALYZER: "bundle-analyze",
|
|
2321
2382
|
/** ModuleFederationPlugin */
|
|
@@ -3527,8 +3588,8 @@ var init_getDevMiddlewares = __esm({
|
|
|
3527
3588
|
}
|
|
3528
3589
|
middlewares.push((req, res, next) => {
|
|
3529
3590
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
3530
|
-
const
|
|
3531
|
-
if (
|
|
3591
|
+
const path20 = req.url ? url.parse(req.url).pathname : "";
|
|
3592
|
+
if (path20?.includes("hot-update")) {
|
|
3532
3593
|
res.setHeader("Access-Control-Allow-Credentials", "false");
|
|
3533
3594
|
}
|
|
3534
3595
|
const confHeaders = server.headers;
|
|
@@ -3555,7 +3616,7 @@ var init_getDevMiddlewares = __esm({
|
|
|
3555
3616
|
compileMiddlewareAPI.onUpgrade.bind(compileMiddlewareAPI)
|
|
3556
3617
|
);
|
|
3557
3618
|
middlewares.push((req, res, next) => {
|
|
3558
|
-
if (req.url?.endsWith(".hot-update.json")) {
|
|
3619
|
+
if (req.url?.endsWith(".hot-update.json") && req.method !== "OPTIONS") {
|
|
3559
3620
|
res.statusCode = 404;
|
|
3560
3621
|
res.end();
|
|
3561
3622
|
} else {
|
|
@@ -5945,6 +6006,7 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
5945
6006
|
bodyTags: bodyTags.map(formatBasicTag)
|
|
5946
6007
|
};
|
|
5947
6008
|
const modified = this.modifyTagsFn ? await this.modifyTagsFn(tags, {
|
|
6009
|
+
compiler,
|
|
5948
6010
|
compilation,
|
|
5949
6011
|
assetPrefix: data.publicPath,
|
|
5950
6012
|
filename: data.outputName,
|
|
@@ -5966,84 +6028,13 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
5966
6028
|
}
|
|
5967
6029
|
});
|
|
5968
6030
|
|
|
5969
|
-
// src/rspack/HtmlAppIconPlugin.ts
|
|
5970
|
-
var HtmlAppIconPlugin_exports = {};
|
|
5971
|
-
__export(HtmlAppIconPlugin_exports, {
|
|
5972
|
-
HtmlAppIconPlugin: () => HtmlAppIconPlugin
|
|
5973
|
-
});
|
|
5974
|
-
import fs7 from "fs";
|
|
5975
|
-
import { basename, posix as posix4 } from "path";
|
|
5976
|
-
var HtmlAppIconPlugin;
|
|
5977
|
-
var init_HtmlAppIconPlugin = __esm({
|
|
5978
|
-
"src/rspack/HtmlAppIconPlugin.ts"() {
|
|
5979
|
-
"use strict";
|
|
5980
|
-
init_esm();
|
|
5981
|
-
init_helpers();
|
|
5982
|
-
init_pluginHelper();
|
|
5983
|
-
HtmlAppIconPlugin = class {
|
|
5984
|
-
constructor(options) {
|
|
5985
|
-
__publicField(this, "name");
|
|
5986
|
-
__publicField(this, "distDir");
|
|
5987
|
-
__publicField(this, "iconPath");
|
|
5988
|
-
this.name = "HtmlAppIconPlugin";
|
|
5989
|
-
this.distDir = options.distDir;
|
|
5990
|
-
this.iconPath = options.iconPath;
|
|
5991
|
-
}
|
|
5992
|
-
apply(compiler) {
|
|
5993
|
-
if (!fs7.existsSync(this.iconPath)) {
|
|
5994
|
-
throw new Error(
|
|
5995
|
-
`[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
|
|
5996
|
-
);
|
|
5997
|
-
}
|
|
5998
|
-
const iconRelativePath = posix4.join(this.distDir, basename(this.iconPath));
|
|
5999
|
-
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
6000
|
-
getHTMLPlugin().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
|
|
6001
|
-
data.headTags.unshift({
|
|
6002
|
-
tagName: "link",
|
|
6003
|
-
voidTag: true,
|
|
6004
|
-
attributes: {
|
|
6005
|
-
rel: "apple-touch-icon",
|
|
6006
|
-
sizes: "180*180",
|
|
6007
|
-
href: ensureAssetPrefix(
|
|
6008
|
-
iconRelativePath,
|
|
6009
|
-
compilation.outputOptions.publicPath
|
|
6010
|
-
)
|
|
6011
|
-
},
|
|
6012
|
-
meta: {}
|
|
6013
|
-
});
|
|
6014
|
-
return data;
|
|
6015
|
-
});
|
|
6016
|
-
});
|
|
6017
|
-
compiler.hooks.thisCompilation.tap(
|
|
6018
|
-
this.name,
|
|
6019
|
-
(compilation) => {
|
|
6020
|
-
compilation.hooks.processAssets.tap(
|
|
6021
|
-
{
|
|
6022
|
-
name: this.name,
|
|
6023
|
-
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
|
|
6024
|
-
},
|
|
6025
|
-
() => {
|
|
6026
|
-
const source = fs7.readFileSync(this.iconPath);
|
|
6027
|
-
compilation.emitAsset(
|
|
6028
|
-
iconRelativePath,
|
|
6029
|
-
new compiler.webpack.sources.RawSource(source, false)
|
|
6030
|
-
);
|
|
6031
|
-
}
|
|
6032
|
-
);
|
|
6033
|
-
}
|
|
6034
|
-
);
|
|
6035
|
-
}
|
|
6036
|
-
};
|
|
6037
|
-
}
|
|
6038
|
-
});
|
|
6039
|
-
|
|
6040
6031
|
// src/plugins/html.ts
|
|
6041
6032
|
var html_exports = {};
|
|
6042
6033
|
__export(html_exports, {
|
|
6043
6034
|
getTemplate: () => getTemplate,
|
|
6044
6035
|
pluginHtml: () => pluginHtml
|
|
6045
6036
|
});
|
|
6046
|
-
import
|
|
6037
|
+
import fs7 from "fs";
|
|
6047
6038
|
import path12, { isAbsolute as isAbsolute7 } from "path";
|
|
6048
6039
|
import color12 from "../compiled/picocolors/index.js";
|
|
6049
6040
|
function getTitle(entryName, config) {
|
|
@@ -6083,7 +6074,7 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
6083
6074
|
}
|
|
6084
6075
|
existTemplatePath.add(absolutePath);
|
|
6085
6076
|
}
|
|
6086
|
-
const templateContent = await
|
|
6077
|
+
const templateContent = await fs7.promises.readFile(absolutePath, "utf-8");
|
|
6087
6078
|
return {
|
|
6088
6079
|
templatePath: absolutePath,
|
|
6089
6080
|
templateContent
|
|
@@ -6264,17 +6255,11 @@ var init_html = __esm({
|
|
|
6264
6255
|
const { HtmlBasicPlugin: HtmlBasicPlugin2 } = await Promise.resolve().then(() => (init_HtmlBasicPlugin(), HtmlBasicPlugin_exports));
|
|
6265
6256
|
chain.plugin(CHAIN_ID2.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin2, [htmlInfoMap, environment, modifyTagsFn]);
|
|
6266
6257
|
if (config.html) {
|
|
6267
|
-
const {
|
|
6258
|
+
const { crossorigin } = config.html;
|
|
6268
6259
|
if (crossorigin) {
|
|
6269
6260
|
const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
6270
6261
|
chain.output.crossOriginLoading(formattedCrossorigin);
|
|
6271
6262
|
}
|
|
6272
|
-
if (appIcon) {
|
|
6273
|
-
const { HtmlAppIconPlugin: HtmlAppIconPlugin2 } = await Promise.resolve().then(() => (init_HtmlAppIconPlugin(), HtmlAppIconPlugin_exports));
|
|
6274
|
-
const distDir = config.output.distPath.image;
|
|
6275
|
-
const iconPath = path12.isAbsolute(appIcon) ? appIcon : path12.join(api.context.rootPath, appIcon);
|
|
6276
|
-
chain.plugin(CHAIN_ID2.PLUGIN.APP_ICON).use(HtmlAppIconPlugin2, [{ iconPath, distDir }]);
|
|
6277
|
-
}
|
|
6278
6263
|
}
|
|
6279
6264
|
}
|
|
6280
6265
|
);
|
|
@@ -6301,12 +6286,95 @@ var init_html = __esm({
|
|
|
6301
6286
|
}
|
|
6302
6287
|
});
|
|
6303
6288
|
|
|
6289
|
+
// src/plugins/appIcon.ts
|
|
6290
|
+
var appIcon_exports = {};
|
|
6291
|
+
__export(appIcon_exports, {
|
|
6292
|
+
pluginAppIcon: () => pluginAppIcon
|
|
6293
|
+
});
|
|
6294
|
+
import fs8 from "fs";
|
|
6295
|
+
import path13 from "path";
|
|
6296
|
+
var pluginAppIcon;
|
|
6297
|
+
var init_appIcon = __esm({
|
|
6298
|
+
"src/plugins/appIcon.ts"() {
|
|
6299
|
+
"use strict";
|
|
6300
|
+
init_esm();
|
|
6301
|
+
init_helpers();
|
|
6302
|
+
pluginAppIcon = () => ({
|
|
6303
|
+
name: "rsbuild:app-icon",
|
|
6304
|
+
setup(api) {
|
|
6305
|
+
const cache = /* @__PURE__ */ new Map();
|
|
6306
|
+
const getIconPath = ({ config, name }) => {
|
|
6307
|
+
const { appIcon } = config.html;
|
|
6308
|
+
if (!appIcon) {
|
|
6309
|
+
return;
|
|
6310
|
+
}
|
|
6311
|
+
const cached = cache.get(name);
|
|
6312
|
+
if (cached) {
|
|
6313
|
+
cached;
|
|
6314
|
+
}
|
|
6315
|
+
const distDir = config.output.distPath.image;
|
|
6316
|
+
const absolutePath = path13.isAbsolute(appIcon) ? appIcon : path13.join(api.context.rootPath, appIcon);
|
|
6317
|
+
const relativePath = path13.posix.join(
|
|
6318
|
+
distDir,
|
|
6319
|
+
path13.basename(absolutePath)
|
|
6320
|
+
);
|
|
6321
|
+
const paths = {
|
|
6322
|
+
absolutePath,
|
|
6323
|
+
relativePath
|
|
6324
|
+
};
|
|
6325
|
+
cache.set(name, paths);
|
|
6326
|
+
return paths;
|
|
6327
|
+
};
|
|
6328
|
+
api.processAssets(
|
|
6329
|
+
{ stage: "additional" },
|
|
6330
|
+
async ({ compiler, compilation, environment }) => {
|
|
6331
|
+
const iconPath = getIconPath(environment);
|
|
6332
|
+
if (!iconPath) {
|
|
6333
|
+
return;
|
|
6334
|
+
}
|
|
6335
|
+
if (!await isFileExists(iconPath.absolutePath)) {
|
|
6336
|
+
throw new Error(
|
|
6337
|
+
`[rsbuild:app-icon] Can not find the app icon, please check if the '${iconPath.relativePath}' file exists'.`
|
|
6338
|
+
);
|
|
6339
|
+
}
|
|
6340
|
+
const source = await fs8.promises.readFile(iconPath.absolutePath);
|
|
6341
|
+
compilation.emitAsset(
|
|
6342
|
+
iconPath.relativePath,
|
|
6343
|
+
new compiler.webpack.sources.RawSource(source, false)
|
|
6344
|
+
);
|
|
6345
|
+
}
|
|
6346
|
+
);
|
|
6347
|
+
api.modifyHTMLTags(
|
|
6348
|
+
({ headTags, bodyTags }, { environment, compilation }) => {
|
|
6349
|
+
const iconPath = getIconPath(environment);
|
|
6350
|
+
if (!iconPath) {
|
|
6351
|
+
return { headTags, bodyTags };
|
|
6352
|
+
}
|
|
6353
|
+
headTags.unshift({
|
|
6354
|
+
tag: "link",
|
|
6355
|
+
attrs: {
|
|
6356
|
+
rel: "apple-touch-icon",
|
|
6357
|
+
sizes: "180*180",
|
|
6358
|
+
href: ensureAssetPrefix(
|
|
6359
|
+
iconPath.relativePath,
|
|
6360
|
+
compilation.outputOptions.publicPath
|
|
6361
|
+
)
|
|
6362
|
+
}
|
|
6363
|
+
});
|
|
6364
|
+
return { headTags, bodyTags };
|
|
6365
|
+
}
|
|
6366
|
+
);
|
|
6367
|
+
}
|
|
6368
|
+
});
|
|
6369
|
+
}
|
|
6370
|
+
});
|
|
6371
|
+
|
|
6304
6372
|
// src/plugins/wasm.ts
|
|
6305
6373
|
var wasm_exports = {};
|
|
6306
6374
|
__export(wasm_exports, {
|
|
6307
6375
|
pluginWasm: () => pluginWasm
|
|
6308
6376
|
});
|
|
6309
|
-
import { posix as
|
|
6377
|
+
import { posix as posix4 } from "path";
|
|
6310
6378
|
var pluginWasm;
|
|
6311
6379
|
var init_wasm = __esm({
|
|
6312
6380
|
"src/plugins/wasm.ts"() {
|
|
@@ -6322,7 +6390,7 @@ var init_wasm = __esm({
|
|
|
6322
6390
|
...chain.get("experiments"),
|
|
6323
6391
|
asyncWebAssembly: true
|
|
6324
6392
|
});
|
|
6325
|
-
const wasmFilename =
|
|
6393
|
+
const wasmFilename = posix4.join(distPath, "[hash].module.wasm");
|
|
6326
6394
|
chain.output.merge({
|
|
6327
6395
|
webassemblyModuleFilename: wasmFilename
|
|
6328
6396
|
});
|
|
@@ -6371,22 +6439,22 @@ var nodeAddons_exports = {};
|
|
|
6371
6439
|
__export(nodeAddons_exports, {
|
|
6372
6440
|
pluginNodeAddons: () => pluginNodeAddons
|
|
6373
6441
|
});
|
|
6374
|
-
import
|
|
6442
|
+
import path14 from "path";
|
|
6375
6443
|
var getFilename3, pluginNodeAddons;
|
|
6376
6444
|
var init_nodeAddons = __esm({
|
|
6377
6445
|
"src/plugins/nodeAddons.ts"() {
|
|
6378
6446
|
"use strict";
|
|
6379
6447
|
init_esm();
|
|
6380
6448
|
getFilename3 = (resourcePath) => {
|
|
6381
|
-
let
|
|
6449
|
+
let basename = "";
|
|
6382
6450
|
if (resourcePath) {
|
|
6383
|
-
const parsed =
|
|
6451
|
+
const parsed = path14.parse(resourcePath);
|
|
6384
6452
|
if (parsed.dir) {
|
|
6385
|
-
|
|
6453
|
+
basename = parsed.name;
|
|
6386
6454
|
}
|
|
6387
6455
|
}
|
|
6388
|
-
if (
|
|
6389
|
-
return `${
|
|
6456
|
+
if (basename) {
|
|
6457
|
+
return `${basename}.node`;
|
|
6390
6458
|
}
|
|
6391
6459
|
return null;
|
|
6392
6460
|
};
|
|
@@ -6590,7 +6658,7 @@ __export(swc_exports, {
|
|
|
6590
6658
|
pluginSwc: () => pluginSwc
|
|
6591
6659
|
});
|
|
6592
6660
|
import fs9 from "fs";
|
|
6593
|
-
import
|
|
6661
|
+
import path15 from "path";
|
|
6594
6662
|
function applyScriptCondition({
|
|
6595
6663
|
rule,
|
|
6596
6664
|
chain,
|
|
@@ -6640,7 +6708,7 @@ function getDefaultSwcConfig(browserslist3, cacheRoot) {
|
|
|
6640
6708
|
async function applyCoreJs(swcConfig, polyfillMode) {
|
|
6641
6709
|
const coreJsPath = __require.resolve("core-js/package.json");
|
|
6642
6710
|
const version2 = getCoreJsVersion(coreJsPath);
|
|
6643
|
-
const coreJsDir =
|
|
6711
|
+
const coreJsDir = path15.dirname(coreJsPath);
|
|
6644
6712
|
swcConfig.env.coreJs = version2;
|
|
6645
6713
|
if (polyfillMode === "usage") {
|
|
6646
6714
|
swcConfig.env.shippedProposals = true;
|
|
@@ -6689,7 +6757,7 @@ var init_swc = __esm({
|
|
|
6689
6757
|
order: "pre",
|
|
6690
6758
|
handler: async (chain, { CHAIN_ID: CHAIN_ID2, target, environment }) => {
|
|
6691
6759
|
const { config, browserslist: browserslist3 } = environment;
|
|
6692
|
-
const cacheRoot =
|
|
6760
|
+
const cacheRoot = path15.join(api.context.cachePath, ".swc");
|
|
6693
6761
|
const rule = chain.module.rule(CHAIN_ID2.RULE.JS).test(SCRIPT_REGEX).type("javascript/auto");
|
|
6694
6762
|
const dataUriRule = chain.module.rule(CHAIN_ID2.RULE.JS_DATA_URI).mimetype({
|
|
6695
6763
|
or: ["text/javascript", "application/javascript"]
|
|
@@ -6711,7 +6779,7 @@ var init_swc = __esm({
|
|
|
6711
6779
|
if (swcConfig.jsc?.externalHelpers) {
|
|
6712
6780
|
chain.resolve.alias.set(
|
|
6713
6781
|
"@swc/helpers",
|
|
6714
|
-
|
|
6782
|
+
path15.dirname(__require.resolve("@swc/helpers/package.json"))
|
|
6715
6783
|
);
|
|
6716
6784
|
}
|
|
6717
6785
|
if (isWebTarget(target)) {
|
|
@@ -7136,188 +7204,41 @@ var init_open = __esm({
|
|
|
7136
7204
|
}
|
|
7137
7205
|
});
|
|
7138
7206
|
|
|
7139
|
-
// src/rspack/InlineChunkHtmlPlugin.ts
|
|
7140
|
-
var InlineChunkHtmlPlugin_exports = {};
|
|
7141
|
-
__export(InlineChunkHtmlPlugin_exports, {
|
|
7142
|
-
InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
|
|
7143
|
-
});
|
|
7144
|
-
import { join as join11 } from "path";
|
|
7145
|
-
var InlineChunkHtmlPlugin;
|
|
7146
|
-
var init_InlineChunkHtmlPlugin = __esm({
|
|
7147
|
-
"src/rspack/InlineChunkHtmlPlugin.ts"() {
|
|
7148
|
-
"use strict";
|
|
7149
|
-
init_esm();
|
|
7150
|
-
init_helpers();
|
|
7151
|
-
init_pluginHelper();
|
|
7152
|
-
InlineChunkHtmlPlugin = class {
|
|
7153
|
-
constructor({
|
|
7154
|
-
styleTests,
|
|
7155
|
-
scriptTests,
|
|
7156
|
-
distPath
|
|
7157
|
-
}) {
|
|
7158
|
-
__publicField(this, "name");
|
|
7159
|
-
__publicField(this, "styleTests");
|
|
7160
|
-
__publicField(this, "scriptTests");
|
|
7161
|
-
__publicField(this, "distPath");
|
|
7162
|
-
__publicField(this, "inlinedAssets");
|
|
7163
|
-
this.name = "InlineChunkHtmlPlugin";
|
|
7164
|
-
this.styleTests = styleTests;
|
|
7165
|
-
this.scriptTests = scriptTests;
|
|
7166
|
-
this.distPath = distPath;
|
|
7167
|
-
this.inlinedAssets = /* @__PURE__ */ new Set();
|
|
7168
|
-
}
|
|
7169
|
-
/**
|
|
7170
|
-
* If we inlined the chunk to HTML,we should update the value of sourceMappingURL,
|
|
7171
|
-
* because the relative path of source code has been changed.
|
|
7172
|
-
* @param source
|
|
7173
|
-
*/
|
|
7174
|
-
updateSourceMappingURL({
|
|
7175
|
-
source,
|
|
7176
|
-
compilation,
|
|
7177
|
-
publicPath,
|
|
7178
|
-
type
|
|
7179
|
-
}) {
|
|
7180
|
-
const { devtool } = compilation.options;
|
|
7181
|
-
if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
|
|
7182
|
-
!devtool.includes("inline") && source.includes("# sourceMappingURL")) {
|
|
7183
|
-
const prefix = addTrailingSlash(
|
|
7184
|
-
join11(publicPath, this.distPath[type] || "")
|
|
7185
|
-
);
|
|
7186
|
-
return source.replace(
|
|
7187
|
-
/# sourceMappingURL=/,
|
|
7188
|
-
`# sourceMappingURL=${prefix}`
|
|
7189
|
-
);
|
|
7190
|
-
}
|
|
7191
|
-
return source;
|
|
7192
|
-
}
|
|
7193
|
-
matchTests(name, source, tests) {
|
|
7194
|
-
return tests.some((test) => {
|
|
7195
|
-
if (isFunction(test)) {
|
|
7196
|
-
const size = source.length;
|
|
7197
|
-
return test({ name, size });
|
|
7198
|
-
}
|
|
7199
|
-
return test.exec(name);
|
|
7200
|
-
});
|
|
7201
|
-
}
|
|
7202
|
-
getInlinedScriptTag(publicPath, tag, compilation) {
|
|
7203
|
-
const { assets } = compilation;
|
|
7204
|
-
if (!(tag?.attributes.src && typeof tag.attributes.src === "string")) {
|
|
7205
|
-
return tag;
|
|
7206
|
-
}
|
|
7207
|
-
const { src, ...otherAttrs } = tag.attributes;
|
|
7208
|
-
const scriptName = publicPath ? src.replace(publicPath, "") : src;
|
|
7209
|
-
const asset = assets[scriptName];
|
|
7210
|
-
if (asset == null) {
|
|
7211
|
-
return tag;
|
|
7212
|
-
}
|
|
7213
|
-
const source = asset.source().toString();
|
|
7214
|
-
const shouldInline = this.matchTests(scriptName, source, this.scriptTests);
|
|
7215
|
-
if (!shouldInline) {
|
|
7216
|
-
return tag;
|
|
7217
|
-
}
|
|
7218
|
-
const ret = {
|
|
7219
|
-
tagName: "script",
|
|
7220
|
-
innerHTML: this.updateSourceMappingURL({
|
|
7221
|
-
source,
|
|
7222
|
-
compilation,
|
|
7223
|
-
publicPath,
|
|
7224
|
-
type: "js"
|
|
7225
|
-
}),
|
|
7226
|
-
attributes: {
|
|
7227
|
-
...otherAttrs
|
|
7228
|
-
},
|
|
7229
|
-
closeTag: true
|
|
7230
|
-
};
|
|
7231
|
-
this.inlinedAssets.add(scriptName);
|
|
7232
|
-
return ret;
|
|
7233
|
-
}
|
|
7234
|
-
getInlinedCSSTag(publicPath, tag, compilation) {
|
|
7235
|
-
const { assets } = compilation;
|
|
7236
|
-
if (!(tag.attributes.href && typeof tag.attributes.href === "string")) {
|
|
7237
|
-
return tag;
|
|
7238
|
-
}
|
|
7239
|
-
const linkName = publicPath ? tag.attributes.href.replace(publicPath, "") : tag.attributes.href;
|
|
7240
|
-
const asset = assets[linkName];
|
|
7241
|
-
if (asset == null) {
|
|
7242
|
-
return tag;
|
|
7243
|
-
}
|
|
7244
|
-
const source = asset.source().toString();
|
|
7245
|
-
const shouldInline = this.matchTests(linkName, source, this.styleTests);
|
|
7246
|
-
if (!shouldInline) {
|
|
7247
|
-
return tag;
|
|
7248
|
-
}
|
|
7249
|
-
const ret = {
|
|
7250
|
-
tagName: "style",
|
|
7251
|
-
innerHTML: this.updateSourceMappingURL({
|
|
7252
|
-
source,
|
|
7253
|
-
compilation,
|
|
7254
|
-
publicPath,
|
|
7255
|
-
type: "css"
|
|
7256
|
-
}),
|
|
7257
|
-
closeTag: true
|
|
7258
|
-
};
|
|
7259
|
-
this.inlinedAssets.add(linkName);
|
|
7260
|
-
return ret;
|
|
7261
|
-
}
|
|
7262
|
-
getInlinedTag(publicPath, tag, compilation) {
|
|
7263
|
-
if (tag.tagName === "script") {
|
|
7264
|
-
return this.getInlinedScriptTag(
|
|
7265
|
-
publicPath,
|
|
7266
|
-
tag,
|
|
7267
|
-
compilation
|
|
7268
|
-
);
|
|
7269
|
-
}
|
|
7270
|
-
if (tag.tagName === "link" && tag.attributes && tag.attributes.rel === "stylesheet") {
|
|
7271
|
-
return this.getInlinedCSSTag(
|
|
7272
|
-
publicPath,
|
|
7273
|
-
tag,
|
|
7274
|
-
compilation
|
|
7275
|
-
);
|
|
7276
|
-
}
|
|
7277
|
-
return tag;
|
|
7278
|
-
}
|
|
7279
|
-
apply(compiler) {
|
|
7280
|
-
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
7281
|
-
const publicPath = getPublicPathFromCompiler(compiler);
|
|
7282
|
-
const tagFunction = (tag) => this.getInlinedTag(publicPath, tag, compilation);
|
|
7283
|
-
const hooks = getHTMLPlugin().getHooks(compilation);
|
|
7284
|
-
hooks.alterAssetTagGroups.tap(this.name, (assets) => {
|
|
7285
|
-
assets.headTags = assets.headTags.map(tagFunction);
|
|
7286
|
-
assets.bodyTags = assets.bodyTags.map(tagFunction);
|
|
7287
|
-
return assets;
|
|
7288
|
-
});
|
|
7289
|
-
compilation.hooks.processAssets.tap(
|
|
7290
|
-
{
|
|
7291
|
-
name: "InlineChunkHtmlPlugin",
|
|
7292
|
-
/**
|
|
7293
|
-
* Remove marked inline assets in summarize stage,
|
|
7294
|
-
* which should be later than the emitting of html-rspack-plugin
|
|
7295
|
-
*/
|
|
7296
|
-
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
7297
|
-
},
|
|
7298
|
-
() => {
|
|
7299
|
-
const { devtool } = compiler.options;
|
|
7300
|
-
for (const name of this.inlinedAssets) {
|
|
7301
|
-
if (devtool === "hidden-source-map") {
|
|
7302
|
-
compilation.deleteAsset(name);
|
|
7303
|
-
} else {
|
|
7304
|
-
delete compilation.assets[name];
|
|
7305
|
-
}
|
|
7306
|
-
}
|
|
7307
|
-
this.inlinedAssets.clear();
|
|
7308
|
-
}
|
|
7309
|
-
);
|
|
7310
|
-
});
|
|
7311
|
-
}
|
|
7312
|
-
};
|
|
7313
|
-
}
|
|
7314
|
-
});
|
|
7315
|
-
|
|
7316
7207
|
// src/plugins/inlineChunk.ts
|
|
7317
7208
|
var inlineChunk_exports = {};
|
|
7318
7209
|
__export(inlineChunk_exports, {
|
|
7319
7210
|
pluginInlineChunk: () => pluginInlineChunk
|
|
7320
7211
|
});
|
|
7212
|
+
import path16 from "path";
|
|
7213
|
+
function updateSourceMappingURL({
|
|
7214
|
+
source,
|
|
7215
|
+
compilation,
|
|
7216
|
+
publicPath,
|
|
7217
|
+
type,
|
|
7218
|
+
config
|
|
7219
|
+
}) {
|
|
7220
|
+
const { devtool } = compilation.options;
|
|
7221
|
+
if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
|
|
7222
|
+
!devtool.includes("inline") && source.includes("# sourceMappingURL")) {
|
|
7223
|
+
const prefix = addTrailingSlash(
|
|
7224
|
+
path16.join(publicPath, config.output.distPath[type] || "")
|
|
7225
|
+
);
|
|
7226
|
+
return source.replace(
|
|
7227
|
+
/# sourceMappingURL=/,
|
|
7228
|
+
`# sourceMappingURL=${prefix}`
|
|
7229
|
+
);
|
|
7230
|
+
}
|
|
7231
|
+
return source;
|
|
7232
|
+
}
|
|
7233
|
+
function matchTests(name, source, tests) {
|
|
7234
|
+
return tests.some((test) => {
|
|
7235
|
+
if (isFunction(test)) {
|
|
7236
|
+
const size = source.length;
|
|
7237
|
+
return test({ name, size });
|
|
7238
|
+
}
|
|
7239
|
+
return test.exec(name);
|
|
7240
|
+
});
|
|
7241
|
+
}
|
|
7321
7242
|
var pluginInlineChunk;
|
|
7322
7243
|
var init_inlineChunk = __esm({
|
|
7323
7244
|
"src/plugins/inlineChunk.ts"() {
|
|
@@ -7328,32 +7249,144 @@ var init_inlineChunk = __esm({
|
|
|
7328
7249
|
pluginInlineChunk = () => ({
|
|
7329
7250
|
name: "rsbuild:inline-chunk",
|
|
7330
7251
|
setup(api) {
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7252
|
+
const inlinedAssets = /* @__PURE__ */ new Set();
|
|
7253
|
+
const getInlinedScriptTag = (publicPath, tag, compilation, scriptTests, config) => {
|
|
7254
|
+
const { assets } = compilation;
|
|
7255
|
+
if (!(tag.attrs?.src && typeof tag.attrs.src === "string")) {
|
|
7256
|
+
return tag;
|
|
7335
7257
|
}
|
|
7336
|
-
const {
|
|
7337
|
-
const
|
|
7338
|
-
const
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
scriptTests.push(inlineScripts === true ? JS_REGEX : inlineScripts);
|
|
7258
|
+
const { src, ...otherAttrs } = tag.attrs;
|
|
7259
|
+
const scriptName = publicPath ? src.replace(publicPath, "") : src;
|
|
7260
|
+
const asset = assets[scriptName];
|
|
7261
|
+
if (asset == null) {
|
|
7262
|
+
return tag;
|
|
7342
7263
|
}
|
|
7343
|
-
|
|
7344
|
-
|
|
7264
|
+
const source = asset.source().toString();
|
|
7265
|
+
const shouldInline = matchTests(scriptName, source, scriptTests);
|
|
7266
|
+
if (!shouldInline) {
|
|
7267
|
+
return tag;
|
|
7345
7268
|
}
|
|
7346
|
-
|
|
7347
|
-
|
|
7269
|
+
const ret = {
|
|
7270
|
+
tag: "script",
|
|
7271
|
+
children: updateSourceMappingURL({
|
|
7272
|
+
source,
|
|
7273
|
+
compilation,
|
|
7274
|
+
publicPath,
|
|
7275
|
+
type: "js",
|
|
7276
|
+
config
|
|
7277
|
+
}),
|
|
7278
|
+
attrs: {
|
|
7279
|
+
...otherAttrs
|
|
7280
|
+
}
|
|
7281
|
+
};
|
|
7282
|
+
inlinedAssets.add(scriptName);
|
|
7283
|
+
return ret;
|
|
7284
|
+
};
|
|
7285
|
+
const getInlinedCSSTag = (publicPath, tag, compilation, styleTests, config) => {
|
|
7286
|
+
const { assets } = compilation;
|
|
7287
|
+
if (!(tag.attrs?.href && typeof tag.attrs.href === "string")) {
|
|
7288
|
+
return tag;
|
|
7348
7289
|
}
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7290
|
+
const linkName = publicPath ? tag.attrs.href.replace(publicPath, "") : tag.attrs.href;
|
|
7291
|
+
const asset = assets[linkName];
|
|
7292
|
+
if (asset == null) {
|
|
7293
|
+
return tag;
|
|
7294
|
+
}
|
|
7295
|
+
const source = asset.source().toString();
|
|
7296
|
+
const shouldInline = matchTests(linkName, source, styleTests);
|
|
7297
|
+
if (!shouldInline) {
|
|
7298
|
+
return tag;
|
|
7299
|
+
}
|
|
7300
|
+
const ret = {
|
|
7301
|
+
tag: "style",
|
|
7302
|
+
children: updateSourceMappingURL({
|
|
7303
|
+
source,
|
|
7304
|
+
compilation,
|
|
7305
|
+
publicPath,
|
|
7306
|
+
type: "css",
|
|
7307
|
+
config
|
|
7308
|
+
})
|
|
7309
|
+
};
|
|
7310
|
+
inlinedAssets.add(linkName);
|
|
7311
|
+
return ret;
|
|
7312
|
+
};
|
|
7313
|
+
const getInlinedTag = (publicPath, tag, compilation, scriptTests, styleTests, config) => {
|
|
7314
|
+
if (tag.tag === "script") {
|
|
7315
|
+
return getInlinedScriptTag(
|
|
7316
|
+
publicPath,
|
|
7317
|
+
tag,
|
|
7318
|
+
compilation,
|
|
7352
7319
|
scriptTests,
|
|
7353
|
-
|
|
7320
|
+
config
|
|
7321
|
+
);
|
|
7322
|
+
}
|
|
7323
|
+
if (tag.tag === "link" && tag.attrs && tag.attrs.rel === "stylesheet") {
|
|
7324
|
+
return getInlinedCSSTag(
|
|
7325
|
+
publicPath,
|
|
7326
|
+
tag,
|
|
7327
|
+
compilation,
|
|
7328
|
+
styleTests,
|
|
7329
|
+
config
|
|
7330
|
+
);
|
|
7331
|
+
}
|
|
7332
|
+
return tag;
|
|
7333
|
+
};
|
|
7334
|
+
api.processAssets(
|
|
7335
|
+
{
|
|
7336
|
+
/**
|
|
7337
|
+
* Remove marked inline assets in summarize stage,
|
|
7338
|
+
* which should be later than the emitting of html-rspack-plugin
|
|
7339
|
+
*/
|
|
7340
|
+
stage: "summarize"
|
|
7341
|
+
},
|
|
7342
|
+
({ compiler, compilation }) => {
|
|
7343
|
+
if (inlinedAssets.size === 0) {
|
|
7344
|
+
return;
|
|
7354
7345
|
}
|
|
7355
|
-
|
|
7356
|
-
|
|
7346
|
+
const { devtool } = compiler.options;
|
|
7347
|
+
for (const name of inlinedAssets) {
|
|
7348
|
+
if (devtool === "hidden-source-map") {
|
|
7349
|
+
compilation.deleteAsset(name);
|
|
7350
|
+
} else {
|
|
7351
|
+
delete compilation.assets[name];
|
|
7352
|
+
}
|
|
7353
|
+
}
|
|
7354
|
+
inlinedAssets.clear();
|
|
7355
|
+
}
|
|
7356
|
+
);
|
|
7357
|
+
api.modifyHTMLTags(
|
|
7358
|
+
({ headTags, bodyTags }, { compiler, compilation, environment }) => {
|
|
7359
|
+
const { htmlPaths, config } = environment;
|
|
7360
|
+
if (isDev() || Object.keys(htmlPaths).length === 0) {
|
|
7361
|
+
return { headTags, bodyTags };
|
|
7362
|
+
}
|
|
7363
|
+
const { inlineStyles, inlineScripts } = config.output;
|
|
7364
|
+
const scriptTests = [];
|
|
7365
|
+
const styleTests = [];
|
|
7366
|
+
if (inlineScripts) {
|
|
7367
|
+
scriptTests.push(inlineScripts === true ? JS_REGEX : inlineScripts);
|
|
7368
|
+
}
|
|
7369
|
+
if (inlineStyles) {
|
|
7370
|
+
styleTests.push(inlineStyles === true ? CSS_REGEX : inlineStyles);
|
|
7371
|
+
}
|
|
7372
|
+
if (!scriptTests.length && !styleTests.length) {
|
|
7373
|
+
return { headTags, bodyTags };
|
|
7374
|
+
}
|
|
7375
|
+
const publicPath = getPublicPathFromCompiler(compiler);
|
|
7376
|
+
const updateTag = (tag) => getInlinedTag(
|
|
7377
|
+
publicPath,
|
|
7378
|
+
tag,
|
|
7379
|
+
compilation,
|
|
7380
|
+
scriptTests,
|
|
7381
|
+
styleTests,
|
|
7382
|
+
environment.config
|
|
7383
|
+
);
|
|
7384
|
+
return {
|
|
7385
|
+
headTags: headTags.map(updateTag),
|
|
7386
|
+
bodyTags: bodyTags.map(updateTag)
|
|
7387
|
+
};
|
|
7388
|
+
}
|
|
7389
|
+
);
|
|
7357
7390
|
}
|
|
7358
7391
|
});
|
|
7359
7392
|
}
|
|
@@ -7382,10 +7415,10 @@ var init_rsdoctor = __esm({
|
|
|
7382
7415
|
const packageName = isRspack ? "@rsdoctor/rspack-plugin" : "@rsdoctor/webpack-plugin";
|
|
7383
7416
|
let module;
|
|
7384
7417
|
try {
|
|
7385
|
-
const
|
|
7418
|
+
const path20 = __require.resolve(packageName, {
|
|
7386
7419
|
paths: [api.context.rootPath]
|
|
7387
7420
|
});
|
|
7388
|
-
module = await import(
|
|
7421
|
+
module = await import(path20);
|
|
7389
7422
|
} catch (err) {
|
|
7390
7423
|
logger.warn(
|
|
7391
7424
|
`\`process.env.RSDOCTOR\` enabled, please install ${color13.bold(color13.yellow(packageName))} package.`
|
|
@@ -7463,14 +7496,14 @@ var init_extractChunks = __esm({
|
|
|
7463
7496
|
});
|
|
7464
7497
|
|
|
7465
7498
|
// src/rspack/preload/helpers/determineAsValue.ts
|
|
7466
|
-
import
|
|
7499
|
+
import path17 from "path";
|
|
7467
7500
|
import { URL as URL2 } from "url";
|
|
7468
7501
|
function determineAsValue({
|
|
7469
7502
|
href,
|
|
7470
7503
|
file
|
|
7471
7504
|
}) {
|
|
7472
7505
|
const url2 = new URL2(file || href, "https://example.com");
|
|
7473
|
-
const extension =
|
|
7506
|
+
const extension = path17.extname(url2.pathname).slice(1);
|
|
7474
7507
|
if (["css"].includes(extension)) {
|
|
7475
7508
|
return "style";
|
|
7476
7509
|
}
|
|
@@ -7871,7 +7904,7 @@ __export(server_exports, {
|
|
|
7871
7904
|
pluginServer: () => pluginServer
|
|
7872
7905
|
});
|
|
7873
7906
|
import fs10 from "fs";
|
|
7874
|
-
import { isAbsolute as isAbsolute8, join as
|
|
7907
|
+
import { isAbsolute as isAbsolute8, join as join11 } from "path";
|
|
7875
7908
|
var pluginServer;
|
|
7876
7909
|
var init_server = __esm({
|
|
7877
7910
|
"src/plugins/server.ts"() {
|
|
@@ -7889,7 +7922,7 @@ var init_server = __esm({
|
|
|
7889
7922
|
if (!copyOnBuild || !name) {
|
|
7890
7923
|
continue;
|
|
7891
7924
|
}
|
|
7892
|
-
const normalizedPath = isAbsolute8(name) ? name :
|
|
7925
|
+
const normalizedPath = isAbsolute8(name) ? name : join11(api.context.rootPath, name);
|
|
7893
7926
|
if (!fs10.existsSync(normalizedPath)) {
|
|
7894
7927
|
continue;
|
|
7895
7928
|
}
|
|
@@ -8163,7 +8196,7 @@ __export(rspackProfile_exports, {
|
|
|
8163
8196
|
});
|
|
8164
8197
|
import fs11 from "fs";
|
|
8165
8198
|
import inspector from "inspector";
|
|
8166
|
-
import
|
|
8199
|
+
import path18 from "path";
|
|
8167
8200
|
import rspack9 from "@rspack/core";
|
|
8168
8201
|
var stopProfiler, pluginRspackProfile;
|
|
8169
8202
|
var init_rspackProfile = __esm({
|
|
@@ -8200,8 +8233,8 @@ var init_rspackProfile = __esm({
|
|
|
8200
8233
|
const enableCPUProfile = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("CPU");
|
|
8201
8234
|
const enableLogging = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("LOGGING");
|
|
8202
8235
|
const onStart = () => {
|
|
8203
|
-
const profileDir =
|
|
8204
|
-
const traceFilePath =
|
|
8236
|
+
const profileDir = path18.join(api.context.distPath, profileDirName);
|
|
8237
|
+
const traceFilePath = path18.join(profileDir, "trace.json");
|
|
8205
8238
|
if (!fs11.existsSync(profileDir)) {
|
|
8206
8239
|
fs11.mkdirSync(profileDir, { recursive: true });
|
|
8207
8240
|
}
|
|
@@ -8222,7 +8255,7 @@ var init_rspackProfile = __esm({
|
|
|
8222
8255
|
api.onBeforeBuild(onStart);
|
|
8223
8256
|
api.onBeforeStartDevServer(onStart);
|
|
8224
8257
|
api.onAfterBuild(async ({ stats }) => {
|
|
8225
|
-
const loggingFilePath =
|
|
8258
|
+
const loggingFilePath = path18.join(
|
|
8226
8259
|
api.context.distPath,
|
|
8227
8260
|
profileDirName,
|
|
8228
8261
|
"logging.json"
|
|
@@ -8240,8 +8273,8 @@ var init_rspackProfile = __esm({
|
|
|
8240
8273
|
if (enableProfileTrace) {
|
|
8241
8274
|
rspack9.experiments.globalTrace.cleanup();
|
|
8242
8275
|
}
|
|
8243
|
-
const profileDir =
|
|
8244
|
-
const cpuProfilePath =
|
|
8276
|
+
const profileDir = path18.join(api.context.distPath, profileDirName);
|
|
8277
|
+
const cpuProfilePath = path18.join(profileDir, "jscpuprofile.json");
|
|
8245
8278
|
stopProfiler(cpuProfilePath, profileSession);
|
|
8246
8279
|
logger.info(`Saved Rspack profile file to ${profileDir}`);
|
|
8247
8280
|
});
|
|
@@ -8387,57 +8420,35 @@ var init_sri = __esm({
|
|
|
8387
8420
|
}
|
|
8388
8421
|
return replacedHtml;
|
|
8389
8422
|
};
|
|
8390
|
-
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
}
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
if (!HTML_REGEX.test(asset)) {
|
|
8409
|
-
continue;
|
|
8410
|
-
}
|
|
8411
|
-
const htmlContent = assets[asset].source();
|
|
8412
|
-
if (!htmlContent.includes(placeholder)) {
|
|
8413
|
-
continue;
|
|
8414
|
-
}
|
|
8415
|
-
assets[asset] = new compiler.webpack.sources.RawSource(
|
|
8416
|
-
replaceIntegrity(
|
|
8417
|
-
htmlContent,
|
|
8418
|
-
assets,
|
|
8419
|
-
this.algorithm,
|
|
8420
|
-
integrityCache
|
|
8421
|
-
)
|
|
8422
|
-
);
|
|
8423
|
-
}
|
|
8424
|
-
}
|
|
8425
|
-
);
|
|
8423
|
+
api.processAssets(
|
|
8424
|
+
{
|
|
8425
|
+
// use to final stage to get the final asset content
|
|
8426
|
+
stage: "report"
|
|
8427
|
+
},
|
|
8428
|
+
({ assets, compiler, environment }) => {
|
|
8429
|
+
const { htmlPaths } = environment;
|
|
8430
|
+
if (Object.keys(htmlPaths).length === 0) {
|
|
8431
|
+
return;
|
|
8432
|
+
}
|
|
8433
|
+
const algorithm = getAlgorithm(environment);
|
|
8434
|
+
if (!algorithm) {
|
|
8435
|
+
return;
|
|
8436
|
+
}
|
|
8437
|
+
const integrityCache = /* @__PURE__ */ new Map();
|
|
8438
|
+
for (const asset of Object.keys(assets)) {
|
|
8439
|
+
if (!HTML_REGEX.test(asset)) {
|
|
8440
|
+
continue;
|
|
8426
8441
|
}
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
const algorithm = getAlgorithm(environment);
|
|
8436
|
-
if (!algorithm) {
|
|
8437
|
-
return;
|
|
8442
|
+
const htmlContent = assets[asset].source();
|
|
8443
|
+
if (!htmlContent.includes(placeholder)) {
|
|
8444
|
+
continue;
|
|
8445
|
+
}
|
|
8446
|
+
assets[asset] = new compiler.webpack.sources.RawSource(
|
|
8447
|
+
replaceIntegrity(htmlContent, assets, algorithm, integrityCache)
|
|
8448
|
+
);
|
|
8449
|
+
}
|
|
8438
8450
|
}
|
|
8439
|
-
|
|
8440
|
-
});
|
|
8451
|
+
);
|
|
8441
8452
|
}
|
|
8442
8453
|
});
|
|
8443
8454
|
}
|
|
@@ -8646,11 +8657,11 @@ var init_prodServer = __esm({
|
|
|
8646
8657
|
}
|
|
8647
8658
|
async applyStaticAssetMiddleware() {
|
|
8648
8659
|
const {
|
|
8649
|
-
output: { path:
|
|
8660
|
+
output: { path: path20, assetPrefixes },
|
|
8650
8661
|
serverConfig: { htmlFallback }
|
|
8651
8662
|
} = this.options;
|
|
8652
8663
|
const { default: sirv } = await import("../compiled/sirv/index.js");
|
|
8653
|
-
const assetMiddleware = sirv(
|
|
8664
|
+
const assetMiddleware = sirv(path20, {
|
|
8654
8665
|
etag: true,
|
|
8655
8666
|
dev: true,
|
|
8656
8667
|
ignores: ["favicon.ico"],
|
|
@@ -8701,6 +8712,7 @@ async function applyDefaultPlugins(pluginManager, context) {
|
|
|
8701
8712
|
return result[0];
|
|
8702
8713
|
})
|
|
8703
8714
|
),
|
|
8715
|
+
Promise.resolve().then(() => (init_appIcon(), appIcon_exports)).then(({ pluginAppIcon: pluginAppIcon2 }) => pluginAppIcon2()),
|
|
8704
8716
|
Promise.resolve().then(() => (init_wasm(), wasm_exports)).then(({ pluginWasm: pluginWasm2 }) => pluginWasm2()),
|
|
8705
8717
|
Promise.resolve().then(() => (init_moment(), moment_exports)).then(({ pluginMoment: pluginMoment2 }) => pluginMoment2()),
|
|
8706
8718
|
Promise.resolve().then(() => (init_nodeAddons(), nodeAddons_exports)).then(
|
|
@@ -8836,7 +8848,7 @@ var init_createRsbuild = __esm({
|
|
|
8836
8848
|
});
|
|
8837
8849
|
|
|
8838
8850
|
// src/cli/init.ts
|
|
8839
|
-
import
|
|
8851
|
+
import path19 from "path";
|
|
8840
8852
|
async function init({
|
|
8841
8853
|
cliOptions,
|
|
8842
8854
|
isRestart
|
|
@@ -8909,7 +8921,7 @@ var init_init = __esm({
|
|
|
8909
8921
|
commonOpts = {};
|
|
8910
8922
|
getEnvDir = (cwd, envDir) => {
|
|
8911
8923
|
if (envDir) {
|
|
8912
|
-
return
|
|
8924
|
+
return path19.isAbsolute(envDir) ? envDir : path19.resolve(cwd, envDir);
|
|
8913
8925
|
}
|
|
8914
8926
|
return cwd;
|
|
8915
8927
|
};
|
|
@@ -8921,7 +8933,7 @@ import { existsSync } from "fs";
|
|
|
8921
8933
|
import { program } from "../compiled/commander/index.js";
|
|
8922
8934
|
import color14 from "../compiled/picocolors/index.js";
|
|
8923
8935
|
function runCli() {
|
|
8924
|
-
program.name("rsbuild").usage("<command> [options]").version("1.0.1-beta.
|
|
8936
|
+
program.name("rsbuild").usage("<command> [options]").version("1.0.1-beta.4");
|
|
8925
8937
|
const devCommand = program.command("dev");
|
|
8926
8938
|
const buildCommand = program.command("build");
|
|
8927
8939
|
const previewCommand = program.command("preview");
|
|
@@ -9033,7 +9045,7 @@ function prepareCli() {
|
|
|
9033
9045
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
|
|
9034
9046
|
console.log();
|
|
9035
9047
|
}
|
|
9036
|
-
logger.greet(` ${`Rsbuild v${"1.0.1-beta.
|
|
9048
|
+
logger.greet(` ${`Rsbuild v${"1.0.1-beta.4"}`}
|
|
9037
9049
|
`);
|
|
9038
9050
|
}
|
|
9039
9051
|
var init_prepare = __esm({
|
|
@@ -9103,7 +9115,7 @@ init_mergeConfig();
|
|
|
9103
9115
|
init_helpers();
|
|
9104
9116
|
init_constants();
|
|
9105
9117
|
import { rspack as rspack10 } from "@rspack/core";
|
|
9106
|
-
var version = "1.0.1-beta.
|
|
9118
|
+
var version = "1.0.1-beta.4";
|
|
9107
9119
|
export {
|
|
9108
9120
|
PLUGIN_CSS_NAME,
|
|
9109
9121
|
PLUGIN_SWC_NAME,
|