diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e4b52358f..2fa8c353f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -417,9 +417,15 @@ importers:
'@rsbuild/plugin-sass':
specifier: ^1.2.2
version: 1.2.2(@rsbuild/core@1.3.0-beta.2)
+ '@rsbuild/plugin-toml':
+ specifier: ^1.1.0
+ version: 1.1.0(@rsbuild/core@1.3.0-beta.2)
'@rsbuild/plugin-typed-css-modules':
specifier: ^1.0.2
version: 1.0.2(@rsbuild/core@1.3.0-beta.2)
+ '@rsbuild/plugin-yaml':
+ specifier: ^1.0.2
+ version: 1.0.2(@rsbuild/core@1.3.0-beta.2)
'@rslib/core':
specifier: workspace:*
version: link:../packages/core
@@ -1007,8 +1013,8 @@ importers:
specifier: 1.0.3
version: 1.0.3(@rsbuild/core@1.3.0-beta.2)
rspress:
- specifier: ^2.0.0-alpha.5
- version: 2.0.0-alpha.5(webpack@5.98.0)
+ specifier: ^2.0.0-alpha.6
+ version: 2.0.0-alpha.6(webpack@5.98.0)
rspress-plugin-font-open-sans:
specifier: 1.0.0
version: 1.0.0
@@ -2154,6 +2160,14 @@ packages:
peerDependencies:
'@rsbuild/core': 1.x
+ '@rsbuild/plugin-toml@1.1.0':
+ resolution: {integrity: sha512-kzmgwXthLO1Co3KY0cGZ/3+jRY0u00Wh59+C5whTekpR0Ww3IXB6f/l/mKel6sk5s+3r8GRwhSbi0erv2AN+bg==}
+ peerDependencies:
+ '@rsbuild/core': 1.x
+ peerDependenciesMeta:
+ '@rsbuild/core':
+ optional: true
+
'@rsbuild/plugin-type-check@1.2.1':
resolution: {integrity: sha512-PtbjeMqDQy8IiPDTuaj8ZmvR42b0AsRq6RUF6wxa8dDsOzD0Dl1GcvemVGCto+/Dh8frLUmnlWF+T8riBw5rtA==}
peerDependencies:
@@ -2175,6 +2189,14 @@ packages:
peerDependencies:
'@rsbuild/core': 1.x
+ '@rsbuild/plugin-yaml@1.0.2':
+ resolution: {integrity: sha512-M7POrqJAYS8IoY4trdLe9DUhDC01MvA0ge4ZKHoVQzlNLWVj2QHHXdz55/bfpkNYhoNGdCntoDmE/dn1zIpcAw==}
+ peerDependencies:
+ '@rsbuild/core': 1.x || ^1.0.1-beta.0
+ peerDependenciesMeta:
+ '@rsbuild/core':
+ optional: true
+
'@rslib/core@0.5.5':
resolution: {integrity: sha512-RpjixdO8a4G99+jZ5P4W35fZyhHasBa13lvErUPXT0fz1QBfLiR/HS+QikjIFiyS538oAaZ8/8BLf88vHERQ0w==}
engines: {node: '>=16.7.0'}
@@ -2326,8 +2348,8 @@ packages:
react-refresh:
optional: true
- '@rspress/core@2.0.0-alpha.5':
- resolution: {integrity: sha512-neOVhD6zBG6NHMGyxSS9eh8Ju9oDicQOZziqOBiVqn6V2sw7dGc1+VwNSerREQicvnHq3L3npcrl0pNgTKaBLw==}
+ '@rspress/core@2.0.0-alpha.6':
+ resolution: {integrity: sha512-ESYWSMrYpuZFd3Fp25lIInOzwKbNRboiTafMxhaSalOyDPuigzuhWTlSbfYecvNxO6hfXTXghUBPNP4XCzoLIg==}
engines: {node: '>=14.17.6'}
'@rspress/mdx-rs-darwin-arm64@0.6.6':
@@ -2382,33 +2404,33 @@ packages:
resolution: {integrity: sha512-NpNhTKBIlV3O6ADhoZkgHvBFvXMW2TYlIWmIT1ysJESUBqDpaN9H3Teve5fugjU2pQ2ORBZO6SQGKliMw/8m/Q==}
engines: {node: '>= 10'}
- '@rspress/plugin-auto-nav-sidebar@2.0.0-alpha.5':
- resolution: {integrity: sha512-dhJNaafPOtIYUNrk/e4c2DKWUvDaXZP4f+eVMplJAXA06/XjNIm5QPDP0ubrAutlnZYBm8Df9UL0vfZTOW7wFA==}
+ '@rspress/plugin-auto-nav-sidebar@2.0.0-alpha.6':
+ resolution: {integrity: sha512-w3eVBhskuWwuyYqwnLeWaJXS9ZWhh4sByNanTiBMj8T3gUFunU/IuMXhFKKPIPjVSi9HXQyWgbZ9p89bSaWlWA==}
engines: {node: '>=14.17.6'}
- '@rspress/plugin-container-syntax@2.0.0-alpha.5':
- resolution: {integrity: sha512-wcSgsY7b5eZ17N0p9t0x2UVQ9a5BiicFHYzSFsUrbofnHcDdUgE1hchhqbpx3845QLLJ6CIko6zcaJ566ziXOA==}
+ '@rspress/plugin-container-syntax@2.0.0-alpha.6':
+ resolution: {integrity: sha512-fkcWFsTR8E2o9xk4ay5MvoiDPZMvbnmPnq2Uv4zEJc/U4D5IHsSI9JCmLuWxXZLtwNlxfxUN09XNAW2eydjz7A==}
engines: {node: '>=14.17.6'}
- '@rspress/plugin-last-updated@2.0.0-alpha.5':
- resolution: {integrity: sha512-v8r2yI6J1PhkBjYnDschEM58yLfGYxObGrLxifa8ZBFFrc3RBNANEu0XQzRm2OkB4CjdD4QCz4BmsEuci2Wj5w==}
+ '@rspress/plugin-last-updated@2.0.0-alpha.6':
+ resolution: {integrity: sha512-1M8ejomLtVEYPm61ZqKyV4S13Q33vZJk42EOzAkbm7QCm0cHcfT6JwGF+3NlIkxSbbmpCrBtpEt85Arjn32XKg==}
engines: {node: '>=14.17.6'}
- '@rspress/plugin-medium-zoom@2.0.0-alpha.5':
- resolution: {integrity: sha512-qCZP8Tb8p7dH+9rjBhrwqwS2CzuglTaok7hcxCXm5vsp64ES4Yl2L+X391FXDT71koL6eMyRmVCWCTgjHWn/hQ==}
+ '@rspress/plugin-medium-zoom@2.0.0-alpha.6':
+ resolution: {integrity: sha512-Og2FQq6hZtN04OO4ADi8GLe+THSk/y0skMghxKKlBBFW7HLlZiSngn84GUaloFPyUqJVEF4URpLcjS16jTidHA==}
engines: {node: '>=14.17.6'}
peerDependencies:
- '@rspress/runtime': ^2.0.0-alpha.5
+ '@rspress/runtime': ^2.0.0-alpha.6
- '@rspress/runtime@2.0.0-alpha.5':
- resolution: {integrity: sha512-8RNw4HV2CYAUsVT+86VaiksuGRGwVqYEwO6JMSddfjRKb6Kd7V2H3HAhHy9hop4nRIQacGbLkFxCz0+sSXdAKg==}
+ '@rspress/runtime@2.0.0-alpha.6':
+ resolution: {integrity: sha512-4oiLEqTv8OxG2QjMNdPPwz0NmIDxjvmaFGTBBgs6xuB0IFlZOBwNWwgH1lrqoggX11vRSnzDx6zgTFHRnTTovg==}
engines: {node: '>=14.17.6'}
- '@rspress/shared@2.0.0-alpha.5':
- resolution: {integrity: sha512-7BjBKV1m8v8izyrKoXWiuB87mG2fHpGKqG3bOf2+bmCsrYKCidt9SnM315jHMkG0G69FndhlZNMTaizsJ/R8bw==}
+ '@rspress/shared@2.0.0-alpha.6':
+ resolution: {integrity: sha512-fAsyLJPQedyA/M7e+WNmdiUieFRvoBSvM+uEqipapVQYgSTJ3O9N1aOqd58zIPjDsDpzw0x2njIks48lyqTjhw==}
- '@rspress/theme-default@2.0.0-alpha.5':
- resolution: {integrity: sha512-6l7yL/WRHhst74C/z3+ox3129FHiI/uFY1GfNO42bLwNWDIlOsi+HcdMpWOw7SkWwN4B3jhk75oy8i8gh3e8yA==}
+ '@rspress/theme-default@2.0.0-alpha.6':
+ resolution: {integrity: sha512-ciINP9+wBQkzIiy6ESB67a3LnwB9zt2xnsHAPXxrUWZ6Gjh0QomsLxO9X79C7T/yWVLr8WgCEmwmZPHCN75Q2A==}
engines: {node: '>=14.17.6'}
'@rstack-dev/doc-ui@1.7.3':
@@ -5745,8 +5767,8 @@ packages:
rspress-plugin-font-open-sans@1.0.0:
resolution: {integrity: sha512-4GP0pd7h3W8EWdqE0VkA62nzUJZNy4ZnYK7be8+lOKHQKsQ5nZ+22A/VurNssi1eZFx3kjwbmIuoAkgb5W8S9Q==}
- rspress@2.0.0-alpha.5:
- resolution: {integrity: sha512-LAxNujGKTzK2xX7wPFrSV6V2xwiNPNRTHtrvp04TJTdyLH5WGIQgZPzSB0X/qShAWyUG3gt9cLdzL6sYcA6AkQ==}
+ rspress@2.0.0-alpha.6:
+ resolution: {integrity: sha512-SB1iinwQi1zsiXJIixEyHUt2N+aWUFYya8ofhMf8FNAyx3J1TzXTwSkXHA/QqtqTohUQL7W846Fpv0pUlaYpvg==}
hasBin: true
run-parallel@1.2.0:
@@ -6338,6 +6360,9 @@ packages:
resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==}
engines: {node: '>=0.6'}
+ toml@3.0.0:
+ resolution: {integrity: sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==}
+
totalist@3.0.1:
resolution: {integrity: sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==}
engines: {node: '>=6'}
@@ -8066,6 +8091,12 @@ snapshots:
- supports-color
- typescript
+ '@rsbuild/plugin-toml@1.1.0(@rsbuild/core@1.3.0-beta.2)':
+ dependencies:
+ toml: 3.0.0
+ optionalDependencies:
+ '@rsbuild/core': 1.3.0-beta.2
+
'@rsbuild/plugin-type-check@1.2.1(@rsbuild/core@1.3.0-beta.2)(@rspack/core@1.3.0-beta.1(@swc/helpers@0.5.15))(typescript@5.8.2)':
dependencies:
deepmerge: 4.3.1
@@ -8095,6 +8126,10 @@ snapshots:
- vue
- webpack-cli
+ '@rsbuild/plugin-yaml@1.0.2(@rsbuild/core@1.3.0-beta.2)':
+ optionalDependencies:
+ '@rsbuild/core': 1.3.0-beta.2
+
'@rslib/core@0.5.5(@microsoft/api-extractor@7.52.1(@types/node@22.8.1))(typescript@5.8.2)':
dependencies:
'@rsbuild/core': 1.2.19
@@ -8216,7 +8251,7 @@ snapshots:
optionalDependencies:
react-refresh: 0.16.0
- '@rspress/core@2.0.0-alpha.5(webpack@5.98.0)':
+ '@rspress/core@2.0.0-alpha.6(webpack@5.98.0)':
dependencies:
'@mdx-js/loader': 2.3.0(webpack@5.98.0)
'@mdx-js/mdx': 2.3.0
@@ -8224,13 +8259,13 @@ snapshots:
'@rsbuild/core': 1.2.19
'@rsbuild/plugin-react': 1.1.1(@rsbuild/core@1.2.19)
'@rspress/mdx-rs': 0.6.6
- '@rspress/plugin-auto-nav-sidebar': 2.0.0-alpha.5
- '@rspress/plugin-container-syntax': 2.0.0-alpha.5
- '@rspress/plugin-last-updated': 2.0.0-alpha.5
- '@rspress/plugin-medium-zoom': 2.0.0-alpha.5(@rspress/runtime@2.0.0-alpha.5)
- '@rspress/runtime': 2.0.0-alpha.5
- '@rspress/shared': 2.0.0-alpha.5
- '@rspress/theme-default': 2.0.0-alpha.5
+ '@rspress/plugin-auto-nav-sidebar': 2.0.0-alpha.6
+ '@rspress/plugin-container-syntax': 2.0.0-alpha.6
+ '@rspress/plugin-last-updated': 2.0.0-alpha.6
+ '@rspress/plugin-medium-zoom': 2.0.0-alpha.6(@rspress/runtime@2.0.0-alpha.6)
+ '@rspress/runtime': 2.0.0-alpha.6
+ '@rspress/shared': 2.0.0-alpha.6
+ '@rspress/theme-default': 2.0.0-alpha.6
enhanced-resolve: 5.18.1
github-slugger: 2.0.0
hast-util-from-html: 2.0.3
@@ -8293,32 +8328,32 @@ snapshots:
'@rspress/mdx-rs-win32-arm64-msvc': 0.6.6
'@rspress/mdx-rs-win32-x64-msvc': 0.6.6
- '@rspress/plugin-auto-nav-sidebar@2.0.0-alpha.5':
+ '@rspress/plugin-auto-nav-sidebar@2.0.0-alpha.6':
dependencies:
- '@rspress/shared': 2.0.0-alpha.5
+ '@rspress/shared': 2.0.0-alpha.6
transitivePeerDependencies:
- '@rspack/tracing'
- '@rspress/plugin-container-syntax@2.0.0-alpha.5':
+ '@rspress/plugin-container-syntax@2.0.0-alpha.6':
dependencies:
- '@rspress/shared': 2.0.0-alpha.5
+ '@rspress/shared': 2.0.0-alpha.6
transitivePeerDependencies:
- '@rspack/tracing'
- '@rspress/plugin-last-updated@2.0.0-alpha.5':
+ '@rspress/plugin-last-updated@2.0.0-alpha.6':
dependencies:
- '@rspress/shared': 2.0.0-alpha.5
+ '@rspress/shared': 2.0.0-alpha.6
transitivePeerDependencies:
- '@rspack/tracing'
- '@rspress/plugin-medium-zoom@2.0.0-alpha.5(@rspress/runtime@2.0.0-alpha.5)':
+ '@rspress/plugin-medium-zoom@2.0.0-alpha.6(@rspress/runtime@2.0.0-alpha.6)':
dependencies:
- '@rspress/runtime': 2.0.0-alpha.5
+ '@rspress/runtime': 2.0.0-alpha.6
medium-zoom: 1.1.0
- '@rspress/runtime@2.0.0-alpha.5':
+ '@rspress/runtime@2.0.0-alpha.6':
dependencies:
- '@rspress/shared': 2.0.0-alpha.5
+ '@rspress/shared': 2.0.0-alpha.6
react: 18.3.1
react-dom: 18.3.1(react@18.3.1)
react-helmet-async: 2.0.5(react@18.3.1)
@@ -8326,7 +8361,7 @@ snapshots:
transitivePeerDependencies:
- '@rspack/tracing'
- '@rspress/shared@2.0.0-alpha.5':
+ '@rspress/shared@2.0.0-alpha.6':
dependencies:
'@rsbuild/core': 1.2.19
gray-matter: 4.0.3
@@ -8335,11 +8370,11 @@ snapshots:
transitivePeerDependencies:
- '@rspack/tracing'
- '@rspress/theme-default@2.0.0-alpha.5':
+ '@rspress/theme-default@2.0.0-alpha.6':
dependencies:
'@mdx-js/react': 2.3.0(react@18.3.1)
- '@rspress/runtime': 2.0.0-alpha.5
- '@rspress/shared': 2.0.0-alpha.5
+ '@rspress/runtime': 2.0.0-alpha.6
+ '@rspress/shared': 2.0.0-alpha.6
body-scroll-lock: 4.0.0-beta.0
copy-to-clipboard: 3.3.3
flexsearch: 0.7.43
@@ -12290,11 +12325,11 @@ snapshots:
rspress-plugin-font-open-sans@1.0.0: {}
- rspress@2.0.0-alpha.5(webpack@5.98.0):
+ rspress@2.0.0-alpha.6(webpack@5.98.0):
dependencies:
'@rsbuild/core': 1.2.19
- '@rspress/core': 2.0.0-alpha.5(webpack@5.98.0)
- '@rspress/shared': 2.0.0-alpha.5
+ '@rspress/core': 2.0.0-alpha.6(webpack@5.98.0)
+ '@rspress/shared': 2.0.0-alpha.6
cac: 6.7.14
chokidar: 3.6.0
picocolors: 1.1.1
@@ -12929,6 +12964,8 @@ snapshots:
toidentifier@1.0.1: {}
+ toml@3.0.0: {}
+
totalist@3.0.1: {}
tree-dump@1.0.2(tslib@2.8.1):
diff --git a/tests/integration/asset/__snapshots__/index.test.ts.snap b/tests/integration/asset/__snapshots__/index.test.ts.snap
index bd435f88a..dc7a54e63 100644
--- a/tests/integration/asset/__snapshots__/index.test.ts.snap
+++ b/tests/integration/asset/__snapshots__/index.test.ts.snap
@@ -12,26 +12,6 @@ export { draft_rslib_entry_namespaceObject as default };
"
`;
-exports[`use json 1`] = `
-"var data_namespaceObject = {
- R: 1,
- K: [
- "2"
- ]
-};
-console.log(data_namespaceObject.R);
-console.log(data_namespaceObject.K);
-"
-`;
-
-exports[`use json 2`] = `
-"var data_rslib_entry_namespaceObject = JSON.parse('{"foo":1,"bar":["2"]}');
-var __webpack_exports__bar = data_rslib_entry_namespaceObject.bar;
-var __webpack_exports__foo = data_rslib_entry_namespaceObject.foo;
-export { __webpack_exports__bar as bar, __webpack_exports__foo as foo };
-"
-`;
-
exports[`use source.assetInclude 1`] = `
"import draft_namespaceObject from "./static/assets/draft.txt";
console.log(draft_namespaceObject);
diff --git a/tests/integration/asset/hash/package.json b/tests/integration/asset/hash/package.json
index 9a005dec1..c398a081b 100644
--- a/tests/integration/asset/hash/package.json
+++ b/tests/integration/asset/hash/package.json
@@ -1,5 +1,5 @@
{
- "name": "asset-name-test",
+ "name": "asset-hash-test",
"version": "1.0.0",
"private": true,
"type": "module",
diff --git a/tests/integration/asset/index.test.ts b/tests/integration/asset/index.test.ts
index 15cdc6a49..2c3d91f70 100644
--- a/tests/integration/asset/index.test.ts
+++ b/tests/integration/asset/index.test.ts
@@ -258,18 +258,108 @@ test('set the assets public path', async () => {
`);
});
-test('use json', async () => {
+test('use json / yaml / toml', async () => {
const fixturePath = join(__dirname, 'json');
const { contents } = await buildAndGetResults({ fixturePath });
// 0. bundle
// esm
- const { content: indexJs } = queryContent(contents.esm0!, /index\.js/);
- expect(indexJs).matchSnapshot();
+ const { path: bundleIndexJs } = queryContent(contents.esm0!, /index\.js/);
+ expect(await import(bundleIndexJs)).toMatchInlineSnapshot(`
+ {
+ "Object": {
+ "jsonDefault": {
+ "items": [
+ 1,
+ 2,
+ ],
+ "name": "default",
+ },
+ "jsonNamed": {
+ "items": [
+ 3,
+ 4,
+ ],
+ "name": "named",
+ },
+ "tomlDefault": {
+ "foo": {
+ "bar": "baz",
+ },
+ "hello": "world",
+ },
+ "yamlDefault": {
+ "foo": {
+ "bar": "baz",
+ },
+ "hello": "world",
+ },
+ },
+ }
+ `);
// 1. bundleless
// esm
- const { content: dataJs } = queryContent(contents.esm1!, /assets\/data\.js/);
- expect(dataJs).matchSnapshot();
+ const { path: bundlelessIndexJs } = queryContent(contents.esm1!, /index\.js/);
+ expect(await import(bundlelessIndexJs)).toMatchInlineSnapshot(`
+ {
+ "Object": {
+ "jsonNamed": {
+ "items": [
+ 3,
+ 4,
+ ],
+ "name": "named",
+ },
+ "tomlDefault": {
+ "foo": {
+ "bar": "baz",
+ },
+ "hello": "world",
+ },
+ "yamlDefault": {
+ "foo": {
+ "bar": "baz",
+ },
+ "hello": "world",
+ },
+ },
+ }
+ `);
+ const { path: jsonFile } = queryContent(
+ contents.esm1!,
+ /json-named-example\.js/,
+ );
+ expect(await import(jsonFile)).toMatchInlineSnapshot(`
+ {
+ "items": [
+ 3,
+ 4,
+ ],
+ "name": "named",
+ }
+ `);
+ const { path: yamlFile } = queryContent(contents.esm1!, /yaml-example\.js/);
+ expect(await import(yamlFile)).toMatchInlineSnapshot(`
+ {
+ "default": {
+ "foo": {
+ "bar": "baz",
+ },
+ "hello": "world",
+ },
+ }
+ `);
+ const { path: tomlFile } = queryContent(contents.esm1!, /toml-example\.js/);
+ expect(await import(tomlFile)).toMatchInlineSnapshot(`
+ {
+ "default": {
+ "foo": {
+ "bar": "baz",
+ },
+ "hello": "world",
+ },
+ }
+ `);
});
test('use svgr', async () => {
diff --git a/tests/integration/asset/json/package.json b/tests/integration/asset/json/package.json
index 55a5fb838..13ff5c122 100644
--- a/tests/integration/asset/json/package.json
+++ b/tests/integration/asset/json/package.json
@@ -1,5 +1,5 @@
{
- "name": "asset-types-test",
+ "name": "asset-json-test",
"version": "1.0.0",
"private": true,
"type": "module"
diff --git a/tests/integration/asset/json/rslib.config.ts b/tests/integration/asset/json/rslib.config.ts
index 37cc90927..de8fde885 100644
--- a/tests/integration/asset/json/rslib.config.ts
+++ b/tests/integration/asset/json/rslib.config.ts
@@ -1,3 +1,5 @@
+import { pluginToml } from '@rsbuild/plugin-toml';
+import { pluginYaml } from '@rsbuild/plugin-yaml';
import { defineConfig } from '@rslib/core';
import { generateBundleEsmConfig } from 'test-helper';
@@ -10,8 +12,10 @@ export default defineConfig({
distPath: {
root: './dist/esm/bundle',
},
- filename: {
- image: '[name].[contenthash:8][ext]',
+ },
+ source: {
+ entry: {
+ index: './src/bundle.ts',
},
},
}),
@@ -24,8 +28,14 @@ export default defineConfig({
distPath: {
root: './dist/esm/bundleless',
},
- filename: {
- image: '[name].[contenthash:16][ext]',
+ },
+ source: {
+ entry: {
+ index: [
+ './src/**/*',
+ '!./src/bundle.ts',
+ '!./src/assets/json-example.json',
+ ],
},
},
}),
@@ -33,4 +43,5 @@ export default defineConfig({
output: {
target: 'web',
},
+ plugins: [pluginYaml(), pluginToml()],
});
diff --git a/tests/integration/asset/json/src/assets/data.json b/tests/integration/asset/json/src/assets/data.json
deleted file mode 100644
index 5743be16e..000000000
--- a/tests/integration/asset/json/src/assets/data.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "foo": 1,
- "bar": ["2"]
-}
diff --git a/tests/integration/asset/json/src/assets/json-example.json b/tests/integration/asset/json/src/assets/json-example.json
new file mode 100644
index 000000000..b2bf7b18a
--- /dev/null
+++ b/tests/integration/asset/json/src/assets/json-example.json
@@ -0,0 +1,4 @@
+{
+ "name": "default",
+ "items": [1, 2]
+}
diff --git a/tests/integration/asset/json/src/assets/json-named-example.json b/tests/integration/asset/json/src/assets/json-named-example.json
new file mode 100644
index 000000000..02a25c94f
--- /dev/null
+++ b/tests/integration/asset/json/src/assets/json-named-example.json
@@ -0,0 +1,4 @@
+{
+ "name": "named",
+ "items": [3, 4]
+}
diff --git a/tests/integration/asset/json/src/assets/toml-example.toml b/tests/integration/asset/json/src/assets/toml-example.toml
new file mode 100644
index 000000000..4a5d1525a
--- /dev/null
+++ b/tests/integration/asset/json/src/assets/toml-example.toml
@@ -0,0 +1,4 @@
+hello = "world"
+
+[foo]
+bar = "baz"
\ No newline at end of file
diff --git a/tests/integration/asset/json/src/assets/yaml-example.yaml b/tests/integration/asset/json/src/assets/yaml-example.yaml
new file mode 100644
index 000000000..22c671b2d
--- /dev/null
+++ b/tests/integration/asset/json/src/assets/yaml-example.yaml
@@ -0,0 +1,3 @@
+hello: world
+foo:
+ bar: baz
diff --git a/tests/integration/asset/json/src/bundle.ts b/tests/integration/asset/json/src/bundle.ts
new file mode 100644
index 000000000..b8793a02e
--- /dev/null
+++ b/tests/integration/asset/json/src/bundle.ts
@@ -0,0 +1,23 @@
+import exampleJson from './assets/json-example.json';
+import { items, name } from './assets/json-named-example.json';
+import exampleToml from './assets/toml-example.toml';
+import exampleYaml from './assets/yaml-example.yaml';
+
+export const Object = {
+ jsonDefault: {
+ name: exampleJson.name,
+ items: exampleJson.items,
+ },
+ jsonNamed: {
+ name,
+ items,
+ },
+ yamlDefault: {
+ hello: exampleYaml.hello,
+ foo: exampleYaml.foo,
+ },
+ tomlDefault: {
+ hello: exampleToml.hello,
+ foo: exampleToml.foo,
+ },
+};
diff --git a/tests/integration/asset/json/src/env.d.ts b/tests/integration/asset/json/src/env.d.ts
new file mode 100644
index 000000000..ce107c108
--- /dev/null
+++ b/tests/integration/asset/json/src/env.d.ts
@@ -0,0 +1 @@
+///
diff --git a/tests/integration/asset/json/src/index.js b/tests/integration/asset/json/src/index.js
deleted file mode 100644
index fff715a3c..000000000
--- a/tests/integration/asset/json/src/index.js
+++ /dev/null
@@ -1,4 +0,0 @@
-import { bar, foo } from './assets/data.json';
-
-console.log(foo);
-console.log(bar);
diff --git a/tests/integration/asset/json/src/index.ts b/tests/integration/asset/json/src/index.ts
new file mode 100644
index 000000000..cd38f062f
--- /dev/null
+++ b/tests/integration/asset/json/src/index.ts
@@ -0,0 +1,18 @@
+import { items, name } from './assets/json-named-example.json';
+import exampleToml from './assets/toml-example.toml';
+import exampleYaml from './assets/yaml-example.yaml';
+
+export const Object = {
+ jsonNamed: {
+ name,
+ items,
+ },
+ yamlDefault: {
+ hello: exampleYaml.hello,
+ foo: exampleYaml.foo,
+ },
+ tomlDefault: {
+ hello: exampleToml.hello,
+ foo: exampleToml.foo,
+ },
+};
diff --git a/tests/package.json b/tests/package.json
index 70c7e98e5..b496d9c75 100644
--- a/tests/package.json
+++ b/tests/package.json
@@ -19,7 +19,9 @@
"@rsbuild/plugin-less": "^1.1.1",
"@rsbuild/plugin-react": "^1.1.1",
"@rsbuild/plugin-sass": "^1.2.2",
+ "@rsbuild/plugin-toml": "^1.1.0",
"@rsbuild/plugin-typed-css-modules": "^1.0.2",
+ "@rsbuild/plugin-yaml": "^1.0.2",
"@rslib/core": "workspace:*",
"@rslib/tsconfig": "workspace:*",
"@types/fs-extra": "^11.0.4",
diff --git a/website/docs/en/guide/advanced/json-files.mdx b/website/docs/en/guide/advanced/json-files.mdx
index 497861a66..aae3b6dac 100644
--- a/website/docs/en/guide/advanced/json-files.mdx
+++ b/website/docs/en/guide/advanced/json-files.mdx
@@ -132,20 +132,20 @@ export default {
-```js
-import { name } from './example.yaml';
+```ts
+import example from './example.yaml';
-console.log(name); // 'foo';
+console.log(example.hello); // 'world';
+console.log(example.foo); // { bar: 'baz' };
```
```yaml
-name: foo
-items:
- - 1
- - 2
+hello: world
+foo:
+ bar: baz
```
@@ -176,18 +176,21 @@ export default {
-```js
-import { name } from './example.toml';
+```ts
+import example from './example.toml';
-console.log(name); // 'foo';
+console.log(example.hello); // 'world';
+console.log(example.foo); // { bar: 'baz' };
```
```toml
-name = "foo"
-items = [1, 2]
+hello = "world"
+
+[foo]
+bar = "baz"
```
@@ -195,9 +198,9 @@ items = [1, 2]
## Type declaration
-When you import YAML or Toml files in TypeScript code, please create a `src/env.d.ts` file in your project and add the corresponding type declarations.
+When you import YAML or TOML files in TypeScript code, please create a `src/env.d.ts` file in your project and add the corresponding type declarations.
-- Method 1: If the `@rslib/core` package is installed, you can reference the **preset types** provided by `@rslib/core`:
+- Method 1: If the `@rslib/core` package is installed, you can reference the [preset types](/guide/basic/typescript#preset-types) provided by `@rslib/core`:
```ts title="src/env.d.ts"
///
diff --git a/website/docs/en/guide/advanced/static-assets.mdx b/website/docs/en/guide/advanced/static-assets.mdx
index 66612a8bb..ea8b44c4d 100644
--- a/website/docs/en/guide/advanced/static-assets.mdx
+++ b/website/docs/en/guide/advanced/static-assets.mdx
@@ -225,7 +225,7 @@ TS2307: Cannot find module './logo.png' or its corresponding type declarations.
To fix this, you need to add a type declaration file for the static assets, please create a `src/env.d.ts` file, and add the corresponding type declaration.
-- Method 1: If the `@rslib/core` package is installed, you can reference the **preset types** provided by `@rslib/core`:
+- Method 1: If the `@rslib/core` package is installed, you can reference the [preset types](/guide/basic/typescript#preset-types) provided by `@rslib/core`:
```ts
///
diff --git a/website/docs/en/guide/basic/typescript.mdx b/website/docs/en/guide/basic/typescript.mdx
index faa6f4782..d110295c2 100644
--- a/website/docs/en/guide/basic/typescript.mdx
+++ b/website/docs/en/guide/basic/typescript.mdx
@@ -30,6 +30,16 @@ export type { SomeType } from './types';
> See [SWC - Migrating from tsc](https://swc.rs/docs/migrating-from-tsc) for more details about the differences between SWC and tsc.
+## Preset types
+
+`@rslib/core` provides some preset type definitions, including CSS Modules, static assets, `import.meta` and other types.
+
+You can create a `src/env.d.ts` file to reference it:
+
+```ts title="src/env.d.ts"
+///
+```
+
## tsconfig.json path
Rslib by default reads the `tsconfig.json` file from the root directory. You can use [source.tsconfigPath](/config/rsbuild/source#sourcetsconfigpath) to configure a custom `tsconfig.json` file path.
diff --git a/website/docs/zh/guide/advanced/json-files.mdx b/website/docs/zh/guide/advanced/json-files.mdx
index 6a85790fa..44a24ca8d 100644
--- a/website/docs/zh/guide/advanced/json-files.mdx
+++ b/website/docs/zh/guide/advanced/json-files.mdx
@@ -1,6 +1,6 @@
# 引用 JSON 文件
-Rslib 支持在代码中引用 JSON 文件,同时也支持引用 [YAML](https://yaml.org/) 和 [TOML](https://toml.io/cn/) 文件并将其转换为 JSON 格式。
+Rslib 支持在代码中引用 JSON 文件,也支持引用 [YAML](https://yaml.org/) 和 [TOML](https://toml.io/cn/) 文件并将其转换为 JSON 格式。
## JSON 文件
@@ -129,20 +129,20 @@ export default {
-```js
-import { name } from './example.yaml';
+```ts
+import example from './example.yaml';
-console.log(name); // 'foo';
+console.log(example.hello); // 'world';
+console.log(example.foo); // { bar: 'baz' };
```
```yaml
-name: foo
-items:
- - 1
- - 2
+hello: world
+foo:
+ bar: baz
```
@@ -150,7 +150,7 @@ items:
## TOML 文件
-[TOML](https://toml.io/cn/) 是一种数据序列化语言,通常用于编写配置文件。
+[TOML](https://toml.io/cn/) 是一种语义明显、易于阅读的配置文件格式。
通过添加 [@rsbuild/plugin-toml](https://github.com/rspack-contrib/rsbuild-plugin-toml) 插件,你可以在 JavaScript 中引用 `.toml` 文件,它们会被自动转换为 JavaScript 对象。
@@ -173,18 +173,21 @@ export default {
-```js
-import { name } from './example.toml';
+```ts
+import example from './example.toml';
-console.log(name); // 'foo';
+console.log(example.hello); // 'world';
+console.log(example.foo); // { bar: 'baz' };
```
```toml
-name = "foo"
-items = [1, 2]
+hello = "world"
+
+[foo]
+bar = "baz"
```
@@ -192,9 +195,9 @@ items = [1, 2]
## 类型声明
-当你在 TypeScript 代码中引用 YAML 或 TOML 文件时,请在项目中创建 src/env.d.ts 文件,并添加相应的类型声明。
+当你在 TypeScript 代码中引用 YAML 或 TOML 文件时,请在项目中创建 `src/env.d.ts` 文件,并添加相应的类型声明。
-- 方法一:如果项目里安装了 `@rslib/core` 包,你可以直接引用 `@rslib/core` 提供的**预设类型**:
+- 方法一:如果项目里安装了 `@rslib/core` 包,你可以直接引用 `@rslib/core` 提供的 [预设类型](/guide/basic/typescript#预设类型):
```ts title="src/env.d.ts"
///
diff --git a/website/docs/zh/guide/advanced/static-assets.mdx b/website/docs/zh/guide/advanced/static-assets.mdx
index a3cdc83b4..77096a586 100644
--- a/website/docs/zh/guide/advanced/static-assets.mdx
+++ b/website/docs/zh/guide/advanced/static-assets.mdx
@@ -225,7 +225,7 @@ TS2307: Cannot find module './logo.png' or its corresponding type declarations.
此时你需要为静态资源添加类型声明文件,请在项目中创建 `src/env.d.ts` 文件,并添加相应的类型声明。
-- 方法一:如果项目里安装了 `@rslib/core` 包,你可以直接引用 `@rslib/core` 提供的**预设类型**:
+- 方法一:如果项目里安装了 `@rslib/core` 包,你可以直接引用 `@rslib/core` 提供的 [预设类型](/guide/basic/typescript#预设类型):
```ts
///
diff --git a/website/docs/zh/guide/basic/typescript.mdx b/website/docs/zh/guide/basic/typescript.mdx
index 3a7193de7..3ecb024e3 100644
--- a/website/docs/zh/guide/basic/typescript.mdx
+++ b/website/docs/zh/guide/basic/typescript.mdx
@@ -30,6 +30,16 @@ export type { SomeType } from './types';
> 更多关于 SWC 和 tsc 之间差异的详细信息,可以查看 [SWC - Migrating from tsc](https://swc.rs/docs/migrating-from-tsc)。
+## 预设类型
+
+`@rslib/core` 提供了一些预设的类型定义,包含 CSS Modules、静态资源、`import.meta` 等类型。
+
+你可以创建一个 `src/env.d.ts` 文件来引用:
+
+```ts title="src/env.d.ts"
+///
+```
+
## tsconfig.json 路径
Rslib 默认从根目录下读取 `tsconfig.json` 文件。你可以使用 [source.tsconfigPath](/config/rsbuild/source#sourcetsconfigpath) 配置一个自定义的 `tsconfig.json` 文件路径。
diff --git a/website/package.json b/website/package.json
index e23461f77..85c9d9e73 100644
--- a/website/package.json
+++ b/website/package.json
@@ -19,7 +19,7 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"rsbuild-plugin-google-analytics": "1.0.3",
- "rspress": "^2.0.0-alpha.5",
+ "rspress": "^2.0.0-alpha.6",
"rspress-plugin-font-open-sans": "1.0.0"
}
}