Skip to content

Commit

Permalink
feat: adopt @nx/vite
Browse files Browse the repository at this point in the history
  • Loading branch information
secundant committed Dec 9, 2023
1 parent 7111860 commit 286c3b1
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 31 deletions.
2 changes: 1 addition & 1 deletion apps/vite-react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example Vite React Application</title>
<title>Example Vite React Application kekw</title>
</head>
<body>
<div id="root"></div>
Expand Down
7 changes: 1 addition & 6 deletions apps/vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@
"name": "vite-react",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
"type": "module"
}
13 changes: 10 additions & 3 deletions apps/vite-react/project.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"name": "vite-react",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/vite-react/src",
"projectType": "application",
"tags": [],
"targets": {
"dev": {},
"test": {},
"lint": {},
"storybook": {},
"typecheck": {},
"storybook": {},
"test-storybook": {},
"build-storybook": {}
"build-storybook": {},
"build": {
"executor": "@nx/vite:build"
},
"serve": {},
"preview": {}
}
}
7 changes: 4 additions & 3 deletions apps/vite-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "vitest"]
"types": ["vite/client"],
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"jsx": "react-jsx"
},
"include": ["src"]
"include": ["src", "vite.config.ts"]
}
14 changes: 12 additions & 2 deletions apps/vite-react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/// <reference types="vitest" />
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({

Check warning on line 6 in apps/vite-react/vite.config.ts

View workflow job for this annotation

GitHub Actions / Changesets

Prefer named exports
plugins: [react(), tsconfigPaths()],
cacheDir: '../../node_modules/.vite/vite-react',
test: {
globals: true,
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
plugins: [react(), nxViteTsPaths()],
});
7 changes: 3 additions & 4 deletions libs/react-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["dom", "esnext"],
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node", "vitest"]
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"types": ["vitest/globals", "vitest/importMeta", "vite/client"]
},
"include": ["src", "vite.config.ts", ".storybook"],
"exclude": ["**/*.test.ts", "**/*.test.tsx"]
"include": ["src", "vite.config.ts", ".storybook"]
}
1 change: 1 addition & 0 deletions libs/react-ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

Expand Down
43 changes: 41 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,28 @@
"inputs": ["production", "^production"]
},
"dev": {
"dependsOn": ["^build", "dev"],
"cache": false
"cache": false,
"dependsOn": ["typecheck", "test", "lint", "^build", "dev"],
"executor": "@nx/vite:dev-server",
"options": {
"buildTarget": "{projectName}:build:development",
"hmr": true
}
},
"serve": {
"executor": "@nx/vite:dev-server",
"options": {
"buildTarget": "{projectName}:build:production",
"hmr": false
}
},
"preview": {
"cache": false,
"executor": "@nx/vite:preview-server",
"options": {
"buildTarget": "{projectName}:build:production"
},
"dependsOn": ["typecheck", "test", "lint", "^build"]
},
"test": {
"cache": true,
Expand Down Expand Up @@ -51,6 +71,25 @@
"command": "tsc --noEmit -p {projectRoot}/tsconfig.json"
}
},
"@nx/vite:build": {
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/{projectRoot}",
"configFile": "{projectRoot}/vite.config.ts",
"skipTypeCheck": true
},
"defaultConfiguration": "production",
"configurations": {
"development": {
"mode": "development"
},
"production": {
"mode": "production"
}
},
"cache": true,
"inputs": ["default", "^production"]
},
"@nx/vite:test": {
"cache": true,
"inputs": ["default", "^production"]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"eslint": "8.55.0",
"eslint-kit": "10.6.0",
"is-ci": "3.0.1",
"jsdom": "~22.1.0",
"lefthook": "1.5.5",
"nx": "17.1.3",
"postcss": "8.4.32",
Expand Down
Loading

0 comments on commit 286c3b1

Please sign in to comment.