Skip to content

Commit

Permalink
feat(plugin): implement plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zkdiff committed Jan 7, 2024
0 parents commit b5b9b3b
Show file tree
Hide file tree
Showing 19 changed files with 20,216 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: release

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
release:
name: 🚀 Release

runs-on: ubuntu-latest

permissions:
contents: write
issues: write
pull-requests: write
id-token: write

if: ${{ github.repository == 'zkdiff/vite-plugin-react-router-remix-routes' && contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha',github.ref) && github.event_name == 'push' }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: Build
run: npm run build

- name: Release
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: 17
branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main',
'next',
'next-major',
{name: 'beta', prerelease: true},
{name: 'alpha', prerelease: true}
]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
tsconfig.tsbuildinfo
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Remix File-Based Routing for React Router via Vite.

Checkout the [Example](./example/) to see a working demo

### Usage

Install the dependencies
`npm install --save-dev vite-plugin-react-router-remix-routes @remix-run/dev`

Configure the vite plugin

```
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { flatRoutes } from "@remix-run/dev/dist/config/flat-routes";
import { reactRouterRemixRoutes } from "vite-plugin-react-router-remix-routes";
export default defineConfig(() => {
const config = {
plugins: [react(), reactRouterRemixRoutes(flatRoutes, "src", ["**/*.tsx.cs"], "routes"))],
};
return config;
});
```

Import the remix routes from the plugin and pass to the createRouter

```
import * as React from "react";
import * as ReactDOM from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import remixRoutes from "react-router-remix-routes";
const router = createBrowserRouter([remixRoutes]);
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>,
);
```

This is the virtual module generated by vite to contain the file base route tree
`import remixRoutes from "react-router-remix-routes";`
18 changes: 18 additions & 0 deletions example/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
};
24 changes: 24 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
30 changes: 30 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
12 changes: 12 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/entry.client.tsx"></script>
</body>
</html>
Loading

0 comments on commit b5b9b3b

Please sign in to comment.