Skip to content

Commit 9469ff3

Browse files
committed
feat(html): support vite-ignore attribute to opt-out of processing
1 parent 8589b7d commit 9469ff3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

guide/features.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Vite は `esbuild` と同じ動作に従い、`tsconfig.json` 内の `target`
9393
開発中に target を指定するには [`esbuild.target`](/config/shared-options.html#esbuild) オプションを使用することができ、トランスパイルを最小限に抑えるためにデフォルトで `esnext` に設定されます。ビルドでは、[`build.target`](/config/build-options.html#build-target) オプションが優先され、必要に応じて設定することができます。
9494

9595
::: warning `useDefineForClassFields`
96+
9697
`tsconfig.json` 内の `target``ESNext` または `ES2022` 以降でない場合、または `tsconfig.json` ファイルがない場合、`useDefineForClassFields` のデフォルトは `false` になり、`esbuild.target` のデフォルト値が `esnext` の場合に問題が発生する可能性があります。これは[静的初期化ブロック](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks#browser_compatibility)にトランスパイルされる可能性があり、ブラウザーでサポートされていない可能性があります。
9798

9899
そのため、`tsconfig.json` を設定する際には、`target``ESNext` または `ES2022` 以降に設定するか、`useDefineForClassFields` を明示的に `true` に設定することをおすすめします。
@@ -159,6 +160,35 @@ Vite はデフォルトでは Node.js の API を提供します。Vite でク
159160

160161
:::
161162

163+
## HTML
164+
165+
HTML ファイルは、Vite プロジェクトの[中心](/guide/#index-html-and-project-root)に位置し、アプリケーションのエントリーポイントとして機能し、シングルページアプリケーションおよび[マルチページアプリケーション](/guide/build.html#multi-page-app)の構築をシンプルにします。
166+
167+
プロジェクトルート内の HTML ファイルは、それぞれのディレクトリパスで直接アクセスできます:
168+
169+
- `<root>/index.html` -> `http://localhost:5173/`
170+
- `<root>/about.html` -> `http://localhost:5173/about.html`
171+
- `<root>/blog/index.html` -> `http://localhost:5173/blog/index.html`
172+
173+
デフォルトでは、`<script type="module">``<link href>` タグなどの HTML 要素が処理され、リンクされたファイルで Vite の機能を使用できるようになります。また、`<img src>``<video src>``<source src>` などの一般的なアセット要素もリベースされ、最適化され、正しいパスにリンクされるようになります。
174+
175+
```html
176+
<!doctype html>
177+
<html>
178+
<head>
179+
<link rel="icon" href="/favicon.ico" />
180+
<link rel="stylesheet" href="/src/styles.css" />
181+
</head>
182+
<body>
183+
<div id="app"></div>
184+
<img src="/src/images/logo.svg" alt="logo" />
185+
<script type="module" src="/src/main.js"></script>
186+
</body>
187+
</html>
188+
```
189+
190+
特定の要素の HTML 処理をオプトアウトするには、その要素に `vite-ignore` 属性を追加します。これは、外部アセットや CDN を参照する際に便利です。
191+
162192
## Vue
163193

164194
Vite は Vue に対して最高のサポートをします:

0 commit comments

Comments
 (0)