Skip to content

Commit 2d1ad33

Browse files
authored
Rework Vite plugin (#60)
* documentation * reworking vite plugin completely * better vite plugin * example updates * changeset * added latest rollup to dev deps, so the types are correct
1 parent cd4ad20 commit 2d1ad33

File tree

12 files changed

+7935
-10095
lines changed

12 files changed

+7935
-10095
lines changed

.changeset/tall-items-switch.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@navita/vite-plugin': major
3+
---
4+
5+
Adding Remix-specific vite plugin.
6+
7+
Instead of allowing Vite to extract the CSS, we use a virtual file, and send HMR updates to that file instead.
8+
9+
During the build, we extract the CSS and write it to a file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Remix
3+
description:
4+
---
5+
6+
# Remix
7+
8+
A plugin for integrating Navita with [Remix](https://remix.run/).
9+
10+
> Navita has first-class support for Remix! It works both in the server and on the client! 🎉
11+
12+
## Installation
13+
14+
```bash
15+
npm install --save-dev @navita/vite-plugin
16+
```
17+
18+
## Setup
19+
20+
Add the plugin to your Vite configuration, along with any desired [plugin configuration](#configuration).
21+
22+
```js
23+
// vite.config.js
24+
import { navitaRemix } from '@navita/vite-plugin/remix';
25+
26+
export default {
27+
plugins: [
28+
navitaRemix({
29+
// configuration
30+
}),
31+
// ...other plugins
32+
]
33+
};
34+
```
35+
36+
Please note that the import is different from the Vite plugin. The Remix plugin is based on, and uses the Vite plugin,
37+
but we've added some extra functionality to make it better suited for Remix.
38+
39+
One example of this is that you would be able to use Navita styles in your server as well.
40+
You'll also get a better developer experience, since we automatically inject the virtual Navita styles into your root-component, and avoid double declarations, other solutions have.
41+
42+
## Configuration
43+
44+
> The Remix plugin is based on the Vite plugin, so you can use the same configuration options.
45+
46+
The plugin accepts the following as optional configuration:
47+
48+
#### `importMap?: { callee: string, source: string }[]`
49+
*Default*: `import { importMap } from "@navita/css"`
50+
51+
ImportMap is a feature that allows you to extend the functionality of Navita.
52+
53+
If you provide your own, it will be merged with the default importMap.

examples/with-remix/app/components/box.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { style } from "@navita/css";
2+
import React from "react";
23

34
const box = style({
4-
background: 'hotpink',
5+
background: 'green',
56
color: 'white',
67
fontSize: 20,
78
padding: 20,

examples/with-remix/app/components/button.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { style } from "@navita/css";
22

33
const button = style({
4-
background: 'red',
4+
background: 'hotpink',
55
color: 'white',
66
padding: '10px',
77
});

examples/with-remix/app/components/specificity.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { style } from "@navita/css";
33
const container = style({
44
width: 500,
55
height: 500,
6-
background: 'green',
6+
background: 'rebeccapurple',
77

88
'@media (min-width: 600px)': {
9-
background: 'red',
9+
background: 'royalblue',
1010
},
1111
});
1212

examples/with-remix/app/consts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const background = 'orange';
1+
export const background = 'yellow';

examples/with-remix/vite.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { navita } from "@navita/vite-plugin";
1+
import { navitaRemix } from "@navita/vite-plugin/remix";
22
import { vitePlugin as remix } from "@remix-run/dev";
33
import { defineConfig } from "vite";
44
import tsconfigPaths from "vite-tsconfig-paths";
55

66
export default defineConfig({
77
plugins: [
8-
navita(),
8+
navitaRemix(),
99
remix({
1010
future: {
1111
v3_fetcherPersist: true,

examples/with-vite/src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { useState } from 'react';
33
import { Button } from "./components/button.tsx";
44

55
const x = style({
6-
background: 'red',
6+
background: 'orange',
77
color: 'blue',
88
});
99

1010
const button = style({
11-
background: 'green',
11+
background: 'lawngreen',
1212
});
1313

1414
function App() {

packages/vite-plugin/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"import": "./dist/index.mjs",
1515
"require": "./dist/index.cjs",
1616
"types": "./src/index.ts"
17+
},
18+
"./remix": {
19+
"import": "./dist/remix.mjs",
20+
"require": "./dist/remix.cjs",
21+
"types": "./src/remix.ts"
1722
}
1823
},
1924
"publishConfig": {
@@ -30,7 +35,8 @@
3035
"@navita/css": "workspace:*"
3136
},
3237
"devDependencies": {
33-
"vite": "5.4.8"
38+
"vite": "5.4.8",
39+
"rollup": "^4.20.0"
3440
},
3541
"license": "MIT",
3642
"author": "Eagerpatch",

0 commit comments

Comments
 (0)