Skip to content

Commit

Permalink
use react in dist build instead of preact
Browse files Browse the repository at this point in the history
preact seemed like it lags more when typing in the editor
  • Loading branch information
jcv8000 committed Nov 8, 2023
1 parent ca8d911 commit 078b1e8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 209 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@
"validator": "^13.11.0"
},
"devDependencies": {
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@preact/compat": "^17.1.2",
"@preact/preset-vite": "^2.6.0",
"@types/color": "^3.0.6",
"@types/d3": "^7.4.3",
"@types/katex": "^0.16.6",
Expand All @@ -102,7 +99,6 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"node-fetch": "^2.7.0",
"preact": "10.17.1",
"prettier": "^3.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
98 changes: 36 additions & 62 deletions packages/renderer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { resolve } from "path";
import { defineConfig, PluginOption, UserConfig } from "vite";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import react from "@vitejs/plugin-react";
import preact from "@preact/preset-vite";
import { viteStaticCopy } from "vite-plugin-static-copy";
import nodeFetch from "node-fetch";
import pkg from "../../package.json";
Expand Down Expand Up @@ -37,39 +36,7 @@ const getVersions = async () => {
}
};

const common: Partial<UserConfig> = {
root: __dirname,
clearScreen: false,
base: "./",
build: {
outDir: resolve(PROJECT_ROOT, ".vite/renderer/"),
emptyOutDir: false,
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
about: resolve(__dirname, "about/about.html")
}
}
},
appType: "mpa"
};

const plugins: PluginOption[] = [
tsconfigPaths({ root: __dirname }),
viteStaticCopy({
targets: [
{
src: "../../node_modules/highlight.js/styles/*.css",
dest: "assets/hljs"
},
{
src: "../../node_modules/highlight.js/styles/base16/*.css",
dest: "assets/hljs/base16"
}
]
})
];

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default defineConfig(async (mode) => {
process.env.VITE_APP_VERSION = process.env.npm_package_version;

Expand All @@ -78,32 +45,39 @@ export default defineConfig(async (mode) => {
process.env.VITE_NODE_VERSION = versions.node;
process.env.VITE_CHROMIUM_VERSION = versions.chromium;

if (mode.command == "serve") {
console.log("Serving app with \x1b[96mReact\x1b[0m");
return {
...common,
server: {
host: "127.0.0.1",
port: 5173
},
build: {
minify: false,
sourcemap: "inline"
},
plugins: [...plugins, react()]
};
} else {
console.log("Building app with \x1b[35mPreact\x1b[0m");
return {
...common,
plugins: [
...plugins,
preact({
babel: {
cwd: __dirname
console.log("Building app with \x1b[96mReact\x1b[0m");

return {
root: __dirname,
clearScreen: false,
base: "./",
build: {
sourcemap: true,
outDir: resolve(PROJECT_ROOT, ".vite/renderer/"),
emptyOutDir: true,
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
about: resolve(__dirname, "about/about.html")
}
}
},
appType: "mpa",
plugins: [
tsconfigPaths({ root: __dirname }),
viteStaticCopy({
targets: [
{
src: "../../node_modules/highlight.js/styles/*.css",
dest: "assets/hljs"
},
{
src: "../../node_modules/highlight.js/styles/base16/*.css",
dest: "assets/hljs/base16"
}
})
]
};
}
]
}),
react()
]
};
});
144 changes: 1 addition & 143 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 078b1e8

Please sign in to comment.