Skip to content

Commit d35325c

Browse files
committed
docs: vite plugin
1 parent f2a228e commit d35325c

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

docs/guides/rollup.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,4 @@ See the [plugin documentation](https://github.com/eik-lib/rollup-plugin#descript
5353

5454
## Vite compatibility
5555

56-
You can [use this Rollup plugin in your Vite build](https://vitejs.dev/guide/api-plugin.html#rollup-plugin-compatibility) should you need to.
57-
58-
```js
59-
import eik from "@eik/rollup-plugin";
60-
import { defineConfig } from "vite";
61-
62-
export default defineConfig({
63-
plugins: [
64-
{
65-
...eik(),
66-
enforce: "pre",
67-
// only apply plugin for client code, while building
68-
apply: (_config, { command, isSsrBuild }) => command === "build" && !isSsrBuild,
69-
},
70-
],
71-
};
72-
```
56+
See [Using Eik with Vite](/docs/guides/vite/).

docs/guides/vite.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Using Eik with Vite
3+
---
4+
5+
This guide describes how to configure [Vite](https://vite.dev/) to use [build-time import mapping](/docs/introduction/workflow#build-time-import-mapping). The guide assumes you have an `eik.json` containing at least one [`"import-map"`](/docs/reference/eik-json#import-map).
6+
7+
## Getting started
8+
9+
Install [`@eik/vite-plugin`](https://github.com/eik-lib/vite-plugin#readme), and `vite` if you haven't already.
10+
11+
```sh
12+
npm install --save-dev vite @eik/vite-plugin
13+
```
14+
15+
## Configure your build
16+
17+
Create or edit `vite.config.ts` to add the Eik plugin.
18+
19+
```ts
20+
import eik from "@eik/vite-plugin";
21+
import { defineConfig } from "vite";
22+
23+
export default defineConfig({
24+
plugins: [eik()],
25+
});
26+
```
27+
28+
## Run your build
29+
30+
Add these scripts to `package.json` if you haven't already.
31+
32+
```json
33+
{
34+
"scripts": {
35+
"dev": "vite",
36+
"build": "vite build"
37+
}
38+
}
39+
```
40+
41+
Now you can run a production build using the Eik plugin by running this command.
42+
43+
```sh
44+
npm run build
45+
```
46+
47+
## Advanced usage
48+
49+
See the [plugin documentation](https://github.com/eik-lib/vite-plugin?tab=readme-ov-file#options) for advanced options on loading import maps.

sidebars.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ module.exports = {
3737
items: [
3838
"guides/browser-importmap",
3939
"guides/esbuild",
40-
"guides/rollup",
4140
"guides/postcss",
41+
"guides/rollup",
42+
"guides/vite",
4243
"guides/webpack",
4344
"guides/github-actions",
4445
"guides/github-actions-images",

0 commit comments

Comments
 (0)