Skip to content

Commit

Permalink
docs(site): __filename, __dirname under ESM (#3181)
Browse files Browse the repository at this point in the history
* docs(site): fix typo of site/docs/esm.md

* docs(site): __filename, __dirname under ESM
  • Loading branch information
waitingsong authored Aug 22, 2023
1 parent a5e7ff3 commit bf2e121
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion site/docs/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ import { helper } from "./foo"; // only works in CJS

4、你不能在代码中使用 `__dirname``__filename` 等和路径相关关键字

所以配置的部分,必须使用对象模式。
```typescript
// ESM solution
import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(fileURLToPath(import.meta.url))
```

所有配置的部分,必须使用对象模式。

```typescript
import { Configuration } from '@midwayjs/core';
Expand Down
9 changes: 9 additions & 0 deletions site/i18n/en/docusaurus-plugin-content-docs/current/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ Only the `import` keyword can be used.

4. You cannot use `__dirname`, `__filename`, etc. and path-related keywords in the code

```typescript
// ESM solution
import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(fileURLToPath(import.meta.url))
```

Therefore, the configuration part must use the object mode.

```typescript
Expand Down

0 comments on commit bf2e121

Please sign in to comment.