Skip to content

Commit

Permalink
docs: unify __dirname usage (#1807)
Browse files Browse the repository at this point in the history
resolve #1806

vitejs/vite@4f5845a の反映です。
  • Loading branch information
shuuji3 authored Jan 16, 2025
1 parent 312b41f commit cb4093a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions guide/api-environment-frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ if (isRunnableDevEnvironment(server.environments.ssr)) {
[SSR セットアップガイド](/guide/ssr#setting-up-the-dev-server)で説明されているように、ミドルウェアモードに設定された Vite サーバーがあるとして、Environment API を使って SSR ミドルウェアを実装してみましょう。エラー処理は省略します。

```js
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { createServer } from 'vite'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const server = await createServer({
server: { middlewareMode: true },
appType: 'custom',
Expand Down
15 changes: 12 additions & 3 deletions guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ export default defineConfig({
ビルド時には、エントリーポイントとして複数の `.html` ファイルを指定するだけです:

```js twoslash [vite.config.js]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

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

export default defineConfig({
build: {
rollupOptions: {
Expand All @@ -134,9 +137,12 @@ HTML ファイルの場合、Vite は `rollupOptions.input` オブジェクト
::: code-group
```js twoslash [vite.config.js(単一エントリー)]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

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

export default defineConfig({
build: {
lib: {
Expand All @@ -162,9 +168,12 @@ export default defineConfig({
```
```js twoslash [vite.config.js(複数エントリー)]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

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

export default defineConfig({
build: {
lib: {
Expand Down

0 comments on commit cb4093a

Please sign in to comment.