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

[Redeploy] Migrate a module bundler from webpack to vite #835

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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"es6": true,
"node": true,
"jest": true,
"jasmine": true
"jasmine": true,
"browser": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["react", "prettier"],
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
"web-vitals": "^1.1.0"
},
"scripts": {
"start": "NODE_OPTIONS=--openssl-legacy-provider react-scripts start",
"start": "vite",
"type-check": "tsc --noEmit",
"build": "yarn type-check && NODE_OPTIONS=--openssl-legacy-provider react-scripts build",
"lint": "eslint src --ext .ts,.tsx",
"build": "yarn type-check && yarn lint && vite build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"format": "prettier --write './src/**/*.{ts,tsx}'",
Expand Down Expand Up @@ -98,7 +99,9 @@
"@types/wicg-file-system-access": "^2020.9.7",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^7.11.0",
"@vitejs/plugin-react": "^4.3.0",
"babel-eslint": "^10.1.0",
"eslint": "8.57.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.21.5",
Expand All @@ -107,7 +110,9 @@
"lint-staged": "^10.5.3",
"prettier": "^3.2.5",
"react-scripts": "^4.0.1",
"sinon": "^11.1.2"
"sinon": "^11.1.2",
"vite": "^5.2.12",
"vite-plugin-node-polyfills": "^0.22.0"
},
"husky": {
"hooks": {
Expand All @@ -124,5 +129,6 @@
"git add"
]
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"type": "module"
}
17 changes: 7 additions & 10 deletions public/index.html → src/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head prefix="og: http://ogp.me/ns#">
<!-- Global site tag (gtag.js) - Google Analytics -->
Expand All @@ -12,7 +12,7 @@
</script>

<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="/favicon.ico" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
Expand Down Expand Up @@ -43,15 +43,11 @@
content="Remap allows you to find, build, set up and customize your keyboard quickly and easily in Web Browser."
data-rh="true"
/>
<meta property="og:url" content="%PUBLIC_URL%" data-rh="true" />
<meta
property="og:image"
content="%PUBLIC_URL%/ogp_image.png"
data-rh="true"
/>
<meta property="og:url" content="https://remap-keys.app" data-rh="true" />
<meta property="og:image" content="/ogp_image.png" data-rh="true" />

<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<script type="application/ld+json">
{
"@context": "https://schema.org",
Expand All @@ -72,6 +68,7 @@
"keywords": "remap,keyboard,keymap,qmk,via,customize,led,diy,webhid"
}
</script>
<script type="module" src="./index.tsx"></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
18 changes: 9 additions & 9 deletions src/services/provider/Firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ import { IDeviceInformation } from '../hid/Hid';
import * as crypto from 'crypto';
import { IBootloaderType } from '../firmware/Types';

const config = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGE_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID,
measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID,
export type IFirebaseConfiguration = {
apiKey: string;
authDomain: string;
projectId: string;
storageBucket: string;
messagingSenderId: string;
appId: string;
measurementId: string;
};

const FUNCTIONS_REGION = 'asia-northeast1';
Expand All @@ -71,7 +71,7 @@ export class FirebaseProvider implements IStorage, IAuth {
private functions: firebase.functions.Functions;
private unsubscribeAuthStateChanged?: firebase.Unsubscribe;

constructor() {
constructor(config: IFirebaseConfiguration) {
firebase.initializeApp(config);
firebase.analytics();
const app = firebase.app();
Expand Down
11 changes: 11 additions & 0 deletions src/services/provider/FirebaseConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IFirebaseConfiguration } from './Firebase';

export const firebaseConfiguration: IFirebaseConfiguration = {
apiKey: import.meta.env.REACT_APP_FIREBASE_API_KEY,
authDomain: import.meta.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: import.meta.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: import.meta.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.REACT_APP_FIREBASE_MESSAGE_SENDER_ID,
appId: import.meta.env.REACT_APP_FIREBASE_APP_ID,
measurementId: import.meta.env.REACT_APP_FIREBASE_MEASUREMENT_ID,
};
5 changes: 3 additions & 2 deletions src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { IFirmwareWriter } from '../services/firmware/FirmwareWriter';
import { FirmwareWriterWebApiImpl } from '../services/firmware/FirmwareWriterWebApiImpl';
import { IBootloaderType } from '../services/firmware/Types';
import { getLocalAuthenticationUid } from '../utils/AuthUtils';
import { firebaseConfiguration } from '../services/provider/FirebaseConfiguration';

export type ISetupPhase =
| 'init'
Expand Down Expand Up @@ -488,9 +489,9 @@ export type RootState = {

let firebaseProvider;
try {
firebaseProvider = new FirebaseProvider();
firebaseProvider = new FirebaseProvider(firebaseConfiguration);
} catch (cause) {
if (process.env.NODE_ENV === 'production') {
if (import.meta.env.NODE_ENV === 'production') {
throw cause;
} else {
console.warn(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/GoogleAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let analytics: firebase.analytics.Analytics | null;
try {
analytics = firebase.analytics();
} catch (cause) {
if (process.env.NODE_ENV === 'production') {
if (import.meta.env.NODE_ENV === 'production') {
throw cause;
} else {
analytics = null;
Expand Down
15 changes: 12 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"target": "esnext",
"lib": ["dom", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand All @@ -15,7 +15,16 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"typeRoots": ["node_modules/@types"]
"typeRoots": ["node_modules/@types", "node_modules", "src/@types"],
"types": [
"node",
"@types/jest",
"@types/w3c-web-hid",
"@types/w3c-web-usb",
"@types/w3c-web-serial",
"@types/wicg-file-system-access",
"vite/client"
]
},
"include": ["src"]
}
36 changes: 36 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import react from '@vitejs/plugin-react';
import { defineConfig, Plugin, loadEnv } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';

export default defineConfig(({ mode }) => {
return {
plugins: [react(), envPlugin(), nodePolyfills()],
esbuild: {},
root: 'src',
publicDir: '../public',
build: {
sourcemap: true,
outDir: '../build',
},
server: {
port: 3000,
},
};
});

function envPlugin(): Plugin {
return {
name: 'env-plugin',
config(_, { mode }) {
const env = loadEnv(mode, '.', ['REACT_APP_', 'NODE_ENV']);
return {
define: Object.fromEntries(
Object.entries(env).map(([key, value]) => [
`import.meta.env.${key}`,
JSON.stringify(value),
])
),
};
},
};
}
Loading
Loading