Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vite plugin (5.x) #2935

Open
wants to merge 6 commits into
base: 5.x
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
docs: add vite-plugin to readmes
  • Loading branch information
tomrav committed Jan 2, 2024
commit af4f1e349bee010ef09224fb7f6ccbd671e583af
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ This repository is a `mono-repo` containing multiple `packages` that together co
| [webpack-plugin](./packages/webpack-plugin) | `@stylable/webpack-plugin` | [![npm version](https://img.shields.io/npm/v/@stylable/webpack-plugin.svg)](https://www.npmjs.com/package/@stylable/webpack-plugin) | `webpack` (`^5.30.0`) integration plugin |
| [experimental-loader](./packages/experimental-loader) | `@stylable/experimental-loader` | [![npm version](https://img.shields.io/npm/v/@stylable/experimental-loader.svg)](https://www.npmjs.com/package/@stylable/experimental-loader) | experimental `webpack` loader - not recommended for production use |
| [rollup-plugin](./packages/rollup-plugin) | `@stylable/rollup-plugin` | [![npm version](https://img.shields.io/npm/v/@stylable/rollup-plugin.svg)](https://www.npmjs.com/package/@stylable/rollup-plugin) | Rollup (`v2.x`) integration plugin |
| [vite-plugin](./packages/vite-plugin) | `@stylable/vite-plugin` | [![npm version](https://img.shields.io/npm/v/@stylable/vite-plugin.svg)](https://www.npmjs.com/package/@stylable/vite-plugin) | Vite (`v4.x`) integration plugin |
| [esbuild](./packages/esbuild) | `@stylable/esbuild` | [![npm version](https://img.shields.io/npm/v/@stylable/rollup-plugin.svg)](https://www.npmjs.com/package/@stylable/esbuild) | esbuild integration plugin |

### Test-kits
55 changes: 55 additions & 0 deletions packages/vite-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

# @stylable/vite-plugin

[![npm version](https://img.shields.io/npm/v/@stylable/vite-plugin.svg)](https://www.npmjs.com/package/@stylable/vite-plugin)

### Installation

`npm i @stylable/vite-plugin -D`

or

`yarn add @stylable/vite-plugin --dev`

### Example Usage
```js
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { viteStylable } from '@stylable/vite';

export default defineConfig({
plugins: [react(), viteStylable({})],
});


```
> If you use any other vite CSS plugins you should exclude Stylable files (`*.st.css`) from them.


### Plugin Options

```ts
export interface StylableVitePluginOptions {
optimization?: {
minify?: boolean;
};
inlineAssets?: boolean | ((filepath: string, buffer: Buffer) => boolean);
fileName?: string;
mode?: 'development' | 'production';
diagnosticsMode?: DiagnosticsMode;
resolveNamespace?: typeof resolveNamespaceNode;
/**
* Runs "stc" programmatically with the webpack compilation.
* true - it will automatically detect the closest "stylable.config.js" file and use it.
* string - it will use the provided string as the "stcConfig" file path.
*/
stcConfig?: boolean | string;
projectRoot?: string;
}
```

> This package provides a **naive** Stylable vite plugin. It is in early development stages and may not behave expectedly in all cases. Please open a PR/issue if you encounter any problems.

## License
Copyright (c) 2024 Wix.com Ltd. All Rights Reserved. Use of this source code is governed by an [MIT license](./LICENSE).