Replace create-react-app with vite

create-react-app seems to struggle a bit [1] and many folks are
recommending vite as an alternative, as that project is more active.
For me the reason to switch to vite is to reduce dependencies and speed
up the build process.

Replacing create-react-app with vite reduce the number of dependencies
from 1762 to 444.

I was also quite surprised, by how small the actual diff in this commit
is. From that perspective there is almost no discernible difference
between the two tools.

[1]: https://github.com/reactjs/react.dev/pull/5487#issuecomment-1409720741
This commit is contained in:
ZauberNerd
2023-07-07 13:36:32 +02:00
parent 9a69273ce4
commit a3da33d824
11 changed files with 79 additions and 130 deletions

View File

@@ -1,28 +1,19 @@
import { OpenAIMessage } from "../chat/types";
import type { ChatHistoryTrimmerOptions } from "./chat-history-trimmer";
// @ts-ignore
import tokenizer from 'workerize-loader!./worker';
import tokenizer from "./worker?worker&url";
let worker: any;
const worker = new ComlinkWorker<typeof import("./worker")>(
new URL(tokenizer, import.meta.url)
);
async function getWorker() {
if (!worker) {
worker = await tokenizer();
}
return worker;
}
export async function runChatTrimmer(messages: OpenAIMessage[], options: ChatHistoryTrimmerOptions): Promise<OpenAIMessage[]> {
const worker = await getWorker();
return worker.runChatTrimmer(messages, options);
export async function runChatTrimmer(
messages: OpenAIMessage[],
options: ChatHistoryTrimmerOptions
): Promise<OpenAIMessage[]> {
return worker.runChatTrimmer(messages, options);
}
export async function countTokens(messages: OpenAIMessage[]) {
const worker = await getWorker();
return await worker.countTokensForMessages(messages);
return await worker.countTokensForMessages(messages);
}
// preload the worker
getWorker().then(w => {
(window as any).worker = w;
})

View File

@@ -12,7 +12,7 @@ import store, { persistor } from './store';
import ChatPage from './components/pages/chat';
import LandingPage from './components/pages/landing';
import './index.scss';
import "./index.css";
const router = createBrowserRouter([
{

View File

@@ -1 +0,0 @@
/// <reference types="react-scripts" />

1
app/src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="vite-plugin-comlink/client" />