Skip to content

Commit

Permalink
README update
Browse files Browse the repository at this point in the history
  • Loading branch information
HorusGoul committed Jun 11, 2024
1 parent b32397e commit db0b601
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pnpm add --save-dev vite-plugin-stylex

## Setup

For a basic SPA setup, you only need to add the plugin to your Vite config:
### Plugin configuration

Add the plugin to your Vite config:

```ts
// ... other imports
Expand All @@ -33,6 +35,24 @@ export default defineConfig({
});
```

### Including StyleX styles in your project

Create a CSS file in your project and add the following:

```css
/* stylex.css */
@stylex stylesheet;

/* You can use other styles here */
```

Finally, import the CSS file in your entrypoint:

```ts
// index.tsx or however your entrypoint is named
import "./stylex.css";
```

### Extra steps for frameworks or SSR

Other setups may require extra steps to get StyleX working. For example, Remix requires you to import the CSS output in your root component.
Expand Down Expand Up @@ -60,6 +80,18 @@ Other setups may require extra steps to get StyleX working. For example, Remix r
import "./index.css";
```

> [!NOTE]
> You might also want to import the CSS file using url import syntax in your `app/root.tsx` file, and then return it
> from the links array
>
> ```ts
> import stylexCSS from "./stylex.css?url";
>
> export const links = () => [{ rel: "stylesheet", href: stylexCSS }];
>
> ...
> ```
#### SvelteKit

Create a `+layout.svelte` file in your `src/routes` directory:
Expand Down Expand Up @@ -117,22 +149,22 @@ Open the `src/global.css` file and add the following:
Add an import source in your Vite config, like so:

```ts
import { defineConfig } from 'vite';
import styleX from 'vite-plugin-stylex';
import { defineConfig } from "vite";
import styleX from "vite-plugin-stylex";

export default defineConfig({
plugins: [
// ...other plugins
styleX({
importSources: [
{
from: 'react-strict-dom',
as: 'css',
from: "react-strict-dom",
as: "css",
},
],
})
]
})
}),
],
});
```

#### Other Frameworks
Expand Down

0 comments on commit db0b601

Please sign in to comment.