From 5638fba3a26b89b5a5e87eafafab972f4dda8fb9 Mon Sep 17 00:00:00 2001
From: Nin3 <30520689+Nin3lee@users.noreply.github.com>
Date: Mon, 28 Apr 2025 16:30:54 +0800
Subject: [PATCH 1/2] i18n(zh-cn): Update `imports.mdx`
---
src/content/docs/zh-cn/guides/imports.mdx | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/content/docs/zh-cn/guides/imports.mdx b/src/content/docs/zh-cn/guides/imports.mdx
index 9e3be5d78730f..4184452148d46 100644
--- a/src/content/docs/zh-cn/guides/imports.mdx
+++ b/src/content/docs/zh-cn/guides/imports.mdx
@@ -358,21 +358,23 @@ Astro 支持使用浏览器的 [`WebAssembly`](https://developer.mozilla.org/en-
## Node 内置模块
-我们鼓励 Astro 用户尽可能避免使用 Node.js 内置模块(`fs`、`path` 等)。Astro 兼容多个运行时使用 [适配器](/zh-cn/guides/on-demand-rendering/)。这包括 [Deno](https://github.com/denoland/deno-astro-adapter) 和 [Cloudflare Workers](/zh-cn/guides/integrations-guide/cloudflare/),它们不支持 Node 内置模块,例如 `fs`。
+Astro 支持通过 Node.js 较新的 `node:` 前缀来调用其内置模块,但仍存在部分限制。比如可能在开发和生产环境中可能存在差异,且部分功能可能与按需渲染不兼容。部分 [适配器](/zh-cn/guides/on-demand-rendering/) 可能也与内置模块不兼容,或需要额外配置才能支持(例如 [Cloudflare Workers](/zh-cn/guides/integrations-guide/cloudflare/) 或 [Deno](https://github.com/denoland/deno-astro-adapter))。
我们致力于为常用的 Node.js 内置模块提供 Astro 化的替代品,不过现在还没有实现。因此,如果你**真的**需要,我们不会阻止你使用这些内置模块。Astro 支持使用较新 `node:` 前缀来支持 Node.js 内置模块。例如,如果你想读取一个文件,你可以这样做:
+下面的示例展示了从 Node 中导入 `util` 模块,用以解析媒体类型(MIME):
+
```astro title="src/components/MyComponent.astro"
---
-// 示例:从 Node.js 中导入内置模块 "fs/promises"
-import fs from 'node:fs/promises';
-
-const url = new URL('../../package.json', import.meta.url);
-const json = await fs.readFile(url, 'utf-8');
-const data = JSON.parse(json);
+// 示例:从 Node.js 中导入内置模块 "util"
+import util from 'node:util';
+export interface Props {
+ mimeType: string,
+}
+const mime = new util.MIMEType(Astro.props.mimeType)
---
-
-Version: {data.version}
+Type: {mime.type}
+SubType: {mime.subtype}
```
## 扩展文件类型支持
From 11c814964be747b3ac2438d1e556d2ebe62e4232 Mon Sep 17 00:00:00 2001
From: Nin3 <30520689+Nin3lee@users.noreply.github.com>
Date: Mon, 28 Apr 2025 16:35:27 +0800
Subject: [PATCH 2/2] fix: typo
---
src/content/docs/zh-cn/guides/imports.mdx | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/content/docs/zh-cn/guides/imports.mdx b/src/content/docs/zh-cn/guides/imports.mdx
index 4184452148d46..5e675757a2451 100644
--- a/src/content/docs/zh-cn/guides/imports.mdx
+++ b/src/content/docs/zh-cn/guides/imports.mdx
@@ -360,8 +360,6 @@ Astro 支持使用浏览器的 [`WebAssembly`](https://developer.mozilla.org/en-
Astro 支持通过 Node.js 较新的 `node:` 前缀来调用其内置模块,但仍存在部分限制。比如可能在开发和生产环境中可能存在差异,且部分功能可能与按需渲染不兼容。部分 [适配器](/zh-cn/guides/on-demand-rendering/) 可能也与内置模块不兼容,或需要额外配置才能支持(例如 [Cloudflare Workers](/zh-cn/guides/integrations-guide/cloudflare/) 或 [Deno](https://github.com/denoland/deno-astro-adapter))。
-我们致力于为常用的 Node.js 内置模块提供 Astro 化的替代品,不过现在还没有实现。因此,如果你**真的**需要,我们不会阻止你使用这些内置模块。Astro 支持使用较新 `node:` 前缀来支持 Node.js 内置模块。例如,如果你想读取一个文件,你可以这样做:
-
下面的示例展示了从 Node 中导入 `util` 模块,用以解析媒体类型(MIME):
```astro title="src/components/MyComponent.astro"