0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor: use vite for demo app

This commit is contained in:
Gao Sun 2024-07-23 14:52:45 +08:00
parent 32e33487bd
commit 536f242fcc
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
7 changed files with 244 additions and 169 deletions

View file

@ -37,13 +37,15 @@ export default function koaSpaProxy<StateT, ContextT extends IRouterParamContext
changeOrigin: true, changeOrigin: true,
logs: true, logs: true,
rewrite: (requestPath) => { rewrite: (requestPath) => {
const fullPath = '/' + path.join(prefix, requestPath);
// Static files // Static files
if (requestPath.includes('.')) { if (requestPath.includes('.')) {
return '/' + path.join(prefix, requestPath); return fullPath;
} }
// In-app routes // In-app routes
return requestPath; // We'll gradually migrate our single-page apps to use vite, which can directly return the full path
return packagePath === 'demo-app' ? fullPath : requestPath;
}, },
}); });

View file

@ -1,7 +0,0 @@
{
"extends": "@parcel/config-default",
"optimizers": {
// Disable optimizers in arm64 arch https://github.com/parcel-bundler/parcel/issues/7402
"*.{jpg,jpeg,png}": []
}
}

View file

@ -11,7 +11,7 @@
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="app"></div> <div id="app"></div>
<script type="module" src="index.tsx"></script> <script type="module" src="src/index.tsx"></script>
</body> </body>
</html> </html>

View file

@ -5,15 +5,16 @@
"author": "Silverhand Inc. <contact@silverhand.io>", "author": "Silverhand Inc. <contact@silverhand.io>",
"license": "MPL-2.0", "license": "MPL-2.0",
"private": true, "private": true,
"type": "module",
"files": [ "files": [
"dist" "dist"
], ],
"scripts": { "scripts": {
"precommit": "lint-staged", "precommit": "lint-staged",
"start": "parcel src/index.html", "start": "vite",
"dev": "cross-env PORT=5003 parcel src/index.html --public-url /demo-app --no-cache --hmr-port 6003", "dev": "vite",
"check": "tsc --noEmit", "check": "tsc --noEmit",
"build": "pnpm check && rm -rf dist && parcel build src/index.html --no-autoinstall --no-cache --public-url /demo-app", "build": "pnpm check && vite build",
"lint": "eslint --ext .ts --ext .tsx src", "lint": "eslint --ext .ts --ext .tsx src",
"lint:report": "pnpm lint --format json --output-file report.json", "lint:report": "pnpm lint --format json --output-file report.json",
"stylelint": "stylelint \"src/**/*.scss\"" "stylelint": "stylelint \"src/**/*.scss\""
@ -24,8 +25,6 @@
"@logto/phrases": "workspace:^1.12.0", "@logto/phrases": "workspace:^1.12.0",
"@logto/react": "^3.0.12", "@logto/react": "^3.0.12",
"@logto/schemas": "workspace:^1.18.0", "@logto/schemas": "workspace:^1.18.0",
"@parcel/core": "2.9.3",
"@parcel/transformer-sass": "2.9.3",
"@silverhand/eslint-config": "6.0.1", "@silverhand/eslint-config": "6.0.1",
"@silverhand/eslint-config-react": "6.0.2", "@silverhand/eslint-config-react": "6.0.2",
"@silverhand/ts-config": "6.0.0", "@silverhand/ts-config": "6.0.0",
@ -39,7 +38,6 @@
"i18next-browser-languagedetector": "^8.0.0", "i18next-browser-languagedetector": "^8.0.0",
"jose": "^5.6.3", "jose": "^5.6.3",
"lint-staged": "^15.0.0", "lint-staged": "^15.0.0",
"parcel": "2.9.3",
"postcss": "^8.4.31", "postcss": "^8.4.31",
"prettier": "^3.0.0", "prettier": "^3.0.0",
"react": "^18.3.1", "react": "^18.3.1",
@ -47,22 +45,12 @@
"react-i18next": "^12.3.1", "react-i18next": "^12.3.1",
"stylelint": "^15.0.0", "stylelint": "^15.0.0",
"typescript": "^5.5.3", "typescript": "^5.5.3",
"vite": "^5.3.4",
"zod": "^3.23.8" "zod": "^3.23.8"
}, },
"engines": { "engines": {
"node": "^20.9.0" "node": "^20.9.0"
}, },
"//": "https://github.com/parcel-bundler/parcel/issues/7636",
"targets": {
"default": {
"engines": {
"browsers": "defaults"
}
}
},
"alias": {
"@/*": "./src/$1"
},
"eslintConfig": { "eslintConfig": {
"extends": "@silverhand/react" "extends": "@silverhand/react"
}, },

View file

@ -2,5 +2,6 @@
"extends": "./tsconfig.base", "extends": "./tsconfig.base",
"include": [ "include": [
"src", "src",
"*.config.ts"
] ]
} }

View file

@ -0,0 +1,47 @@
import { defineConfig } from 'vite';
export default defineConfig({
base: '/demo-app',
server: {
port: 5003,
hmr: {
port: 6003,
},
},
resolve: {
alias: [
{
find: /^@\//,
replacement: '/src/',
},
],
},
optimizeDeps: {
include: ['@logto/phrases', '@logto/phrases-experience', '@logto/schemas'],
},
build: {
sourcemap: process.env.NODE_ENV === 'production',
rollupOptions: {
output: {
manualChunks(id) {
if (/\/react[^/]*\//.test(id)) {
return 'react';
}
if (id.includes('/@logto/')) {
return 'logto';
}
if (id.includes('/node_modules/')) {
return 'vendors';
}
const match = /\/lib\/locales\/([^/]+)/.exec(id);
if (match?.[1]) {
return `phrases-${match[1]}`;
}
},
},
},
},
});

File diff suppressed because it is too large Load diff