Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 43 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,46 @@ A feature flag plugin for Vite.

## How to use

1. Install the plugin.

```bash
pnpm add -D @virtual-live-lab/vite-plugin-feature-flags
```

2. Add this plugin to `vite.config.ts`.

```ts
import { defineConfig } from "vite";
import { featuresPlugin } from "vite-plugin-feature-flags";

export default defineConfig({
plugins: [
featuresPlugin({
// your feature flags
hoge: true,
fuga: false,
}),
],
});
```

3. Add type declaration for feature flags.

```ts
/// <reference types="@virtual-live-lab/vite-plugin-feature-flags/client" />

interface ImportMetaFeatures {
hoge: boolean;
fuga: boolean;
}
```

4. Use feature flags in your code.

```ts
if (import.meta.features.hoge) {
console.log("hoge is enabled");
}
```
1. Install the plugin.

```bash
pnpm add -D @virtual-live-lab/vite-plugin-feature-flags
```

2. Add this plugin to `vite.config.ts`.

```ts
import { defineConfig } from "vite";
import { featuresPlugin } from "vite-plugin-feature-flags";

export default defineConfig({
plugins: [
featuresPlugin({
// your feature flags
hoge: true,
fuga: false,
}),
],
});
```

3. Add type declaration for feature flags.

```ts
declare module "@virtual-live-lab/vite-plugin-feature-flags/client" {
interface ImportMetaFeatures {
hoge: boolean;
fuga: boolean;
}
}

export {}; // Declaration merging is only available in modules.
```

4. Use feature flags in your code.

```ts
if (import.meta.features.hoge) {
console.log("hoge is enabled");
}
```