Fix vite react variable issue
This commit is contained in:
parent
3ed9a219c7
commit
9bf98ab53a
@ -17,10 +17,9 @@
|
|||||||
"semantic-ui-react": "^2.1.4"
|
"semantic-ui-react": "^2.1.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "vite preview --host 0.0.0.0",
|
||||||
"build": "react-scripts build",
|
"build": "vite build",
|
||||||
"test": "react-scripts test",
|
"dev": "vite dev"
|
||||||
"eject": "react-scripts eject"
|
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
|
@ -1,44 +1,30 @@
|
|||||||
import fs from "node:fs";
|
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
import * as esbuild from "esbuild";
|
import * as esbuild from "esbuild";
|
||||||
|
import fs from 'fs/promises';
|
||||||
|
|
||||||
const sourceJSPattern = /\/src\/.*\.js$/;
|
export default defineConfig(() => ({
|
||||||
const rollupPlugin = (matchers) => ({
|
plugins: [react()],
|
||||||
name: "js-in-jsx",
|
esbuild: {
|
||||||
load(id) {
|
loader: "jsx",
|
||||||
if (matchers.some(matcher => matcher.test(id))) {
|
include: /src\/.*\.jsx?$/,
|
||||||
const file = fs.readFileSync(id, { encoding: "utf-8" });
|
// loader: "tsx",
|
||||||
return esbuild.transformSync(file, { loader: "jsx" });
|
// include: /src\/.*\.[tj]sx?$/,
|
||||||
}
|
exclude: [],
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [
|
|
||||||
react()
|
|
||||||
],
|
|
||||||
build: {
|
|
||||||
outDir: "./build",
|
|
||||||
rollupOptions: {
|
|
||||||
plugins: [
|
|
||||||
rollupPlugin([sourceJSPattern])
|
|
||||||
],
|
|
||||||
},
|
|
||||||
commonjsOptions: {
|
|
||||||
transformMixedEsModules: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
esbuildOptions: {
|
esbuildOptions: {
|
||||||
loader: {
|
plugins: [
|
||||||
".js": "jsx",
|
{
|
||||||
},
|
name: "load-js-files-as-jsx",
|
||||||
|
setup(build) {
|
||||||
|
build.onLoad({ filter: /src\/.*\.js$/ }, async (args) => ({
|
||||||
|
loader: "jsx",
|
||||||
|
contents: await fs.readFile(args.path, "utf8"),
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
esbuild: {
|
}));
|
||||||
loader: "jsx",
|
|
||||||
include: [sourceJSPattern],
|
|
||||||
exclude: [],
|
|
||||||
},
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user