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

Rework Vite plugin #60

Merged
merged 6 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .changeset/tall-items-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@navita/vite-plugin': major
---

Adding Remix-specific vite plugin.

Instead of allowing Vite to extract the CSS, we use a virtual file, and send HMR updates to that file instead.

During the build, we extract the CSS and write it to a file.
53 changes: 53 additions & 0 deletions documentation/200-integrations/250-remix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Remix
description:
---

# Remix

A plugin for integrating Navita with [Remix](https://remix.run/).

> Navita has first-class support for Remix! It works both in the server and on the client! 🎉

## Installation

```bash
npm install --save-dev @navita/vite-plugin
```

## Setup

Add the plugin to your Vite configuration, along with any desired [plugin configuration](#configuration).

```js
// vite.config.js
import { navitaRemix } from '@navita/vite-plugin/remix';

export default {
plugins: [
navitaRemix({
// configuration
}),
// ...other plugins
]
};
```

Please note that the import is different from the Vite plugin. The Remix plugin is based on, and uses the Vite plugin,
but we've added some extra functionality to make it better suited for Remix.

One example of this is that you would be able to use Navita styles in your server as well.
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.

## Configuration

> The Remix plugin is based on the Vite plugin, so you can use the same configuration options.

The plugin accepts the following as optional configuration:

#### `importMap?: { callee: string, source: string }[]`
*Default*: `import { importMap } from "@navita/css"`

ImportMap is a feature that allows you to extend the functionality of Navita.

If you provide your own, it will be merged with the default importMap.
3 changes: 2 additions & 1 deletion examples/with-remix/app/components/box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { style } from "@navita/css";
import React from "react";

const box = style({
background: 'hotpink',
background: 'green',
color: 'white',
fontSize: 20,
padding: 20,
Expand Down
2 changes: 1 addition & 1 deletion examples/with-remix/app/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { style } from "@navita/css";

const button = style({
background: 'red',
background: 'hotpink',
color: 'white',
padding: '10px',
});
Expand Down
4 changes: 2 additions & 2 deletions examples/with-remix/app/components/specificity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { style } from "@navita/css";
const container = style({
width: 500,
height: 500,
background: 'green',
background: 'rebeccapurple',

'@media (min-width: 600px)': {
background: 'red',
background: 'royalblue',
},
});

Expand Down
2 changes: 1 addition & 1 deletion examples/with-remix/app/consts.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const background = 'orange';
export const background = 'yellow';
4 changes: 2 additions & 2 deletions examples/with-remix/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { navita } from "@navita/vite-plugin";
import { navitaRemix } from "@navita/vite-plugin/remix";
import { vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
plugins: [
navita(),
navitaRemix(),
remix({
future: {
v3_fetcherPersist: true,
Expand Down
4 changes: 2 additions & 2 deletions examples/with-vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useState } from 'react';
import { Button } from "./components/button.tsx";

const x = style({
background: 'red',
background: 'orange',
color: 'blue',
});

const button = style({
background: 'green',
background: 'lawngreen',
});

function App() {
Expand Down
8 changes: 7 additions & 1 deletion packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./src/index.ts"
},
"./remix": {
"import": "./dist/remix.mjs",
"require": "./dist/remix.cjs",
"types": "./src/remix.ts"
}
},
"publishConfig": {
Expand All @@ -30,7 +35,8 @@
"@navita/css": "workspace:*"
},
"devDependencies": {
"vite": "5.4.8"
"vite": "5.4.8",
"rollup": "^4.20.0"
},
"license": "MIT",
"author": "Eagerpatch",
Expand Down
Loading
Loading