Skip to content

Commit 4f5845a

Browse files
authored
docs: unify __dirname usage (#19176)
1 parent f2aed62 commit 4f5845a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

docs/guide/api-environment-frameworks.md

+5
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ The `runner` is evaluated eagerly when it's accessed for the first time. Beware
4646
Given a Vite server configured in middleware mode as described by the [SSR setup guide](/guide/ssr#setting-up-the-dev-server), let's implement the SSR middleware using the environment API. Error handling is omitted.
4747

4848
```js
49+
import fs from 'node:fs'
50+
import path from 'node:path'
51+
import { fileURLToPath } from 'node:url'
4952
import { createServer } from 'vite'
5053

54+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
55+
5156
const server = await createServer({
5257
server: { middlewareMode: true },
5358
appType: 'custom',

docs/guide/build.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ During dev, simply navigate or link to `/nested/` - it works as expected, just l
106106
During build, all you need to do is to specify multiple `.html` files as entry points:
107107

108108
```js twoslash [vite.config.js]
109-
import { resolve } from 'path'
109+
import { dirname, resolve } from 'node:path'
110+
import { fileURLToPath } from 'node:url'
110111
import { defineConfig } from 'vite'
111112

113+
const __dirname = dirname(fileURLToPath(import.meta.url))
114+
112115
export default defineConfig({
113116
build: {
114117
rollupOptions: {
@@ -134,9 +137,12 @@ When it is time to bundle your library for distribution, use the [`build.lib` co
134137
::: code-group
135138
136139
```js twoslash [vite.config.js (single entry)]
137-
import { resolve } from 'path'
140+
import { dirname, resolve } from 'node:path'
141+
import { fileURLToPath } from 'node:url'
138142
import { defineConfig } from 'vite'
139143

144+
const __dirname = dirname(fileURLToPath(import.meta.url))
145+
140146
export default defineConfig({
141147
build: {
142148
lib: {
@@ -162,9 +168,12 @@ export default defineConfig({
162168
```
163169
164170
```js twoslash [vite.config.js (multiple entries)]
165-
import { resolve } from 'path'
171+
import { dirname, resolve } from 'node:path'
172+
import { fileURLToPath } from 'node:url'
166173
import { defineConfig } from 'vite'
167174

175+
const __dirname = dirname(fileURLToPath(import.meta.url))
176+
168177
export default defineConfig({
169178
build: {
170179
lib: {

0 commit comments

Comments
 (0)