-
I would like to use the zero runtime CSS-in-JS library Linaria in my electron-vite project which uses React with TypeScript for the renderer, but I just can't get the Babel plugin working correctly when running the project either in dev mode or build mode. Is it even possible to use this library with electron-vite? I would really like to use CSS-in-JS in my electron-vite project. |
Beta Was this translation helpful? Give feedback.
Answered by
aabmets
Oct 10, 2024
Replies: 1 comment
-
Here is the solution:Note: the contents of the
bun add --dev @linaria/core @linaria/react @wyw-in-js/vite @vitejs/plugin-react vite-tsconfig-paths
import wyw from "@wyw-in-js/vite";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig, bytecodePlugin, externalizeDepsPlugin, swcPlugin } from "electron-vite";
import type { Plugin } from "vite";
function getNodePlugins(env: ConfigEnv): (Plugin | null)[] {
if (env.mode === "production") {
return [swcPlugin(), externalizeDepsPlugin(), bytecodePlugin()];
}
return [swcPlugin()];
}
module.exports = defineConfig((env: ConfigEnv) => {
return {
main: {
plugins: getNodePlugins(env),
},
preload: {
plugins: getNodePlugins(env),
},
renderer: {
plugins: [
react(),
tsconfigPaths(),
wyw()
],
},
};
});
import { css } from "@linaria/core";
import { Fragment, type ReactNode } from "react";
export default function App(): ReactNode {
const title = css`
text-transform: uppercase;
background-color: goldenrod;
font-family: "Menlo", "Lucida Console", monospace;
font-size: 20px;
`;
return (
<Fragment>
<div className={title}>Linaria</div>
</Fragment>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
aabmets
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the solution:
Note: the contents of the
wyw
plugin to yourelectron.vite.config.ts
file as follows: