mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
wip
This commit is contained in:
@@ -1,57 +1,20 @@
|
||||
// @ts-nocheck
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import legacy from '@vitejs/plugin-legacy';
|
||||
import path from 'node:path';
|
||||
import { defineConfig, loadEnv, Plugin } from 'vite';
|
||||
import { defineConfig, loadEnv, type PluginOption } from 'vite';
|
||||
import fixReactVirtualized from 'esbuild-plugin-react-virtualized';
|
||||
|
||||
const allowedEnvPrefixes = ['VITE_', 'REACT_APP_', 'PUBLIC_URL'];
|
||||
|
||||
const reactVirtualizedCompat = (): Plugin => ({
|
||||
name: 'react-virtualized-compat',
|
||||
enforce: 'pre',
|
||||
transform(code, id) {
|
||||
const needsShim =
|
||||
id.includes(
|
||||
'node_modules/react-virtualized/dist/es/WindowScroller/utils/onScroll.js',
|
||||
) ||
|
||||
id.includes(
|
||||
'node_modules/react-virtualized/dist/es/WindowScroller/utils/dimensions.js',
|
||||
);
|
||||
if (needsShim) {
|
||||
console.info('Applying react-virtualized shim:', id);
|
||||
return code.replace(
|
||||
/import \{ bpfrpt_proptype_WindowScroller \} from "\.\.\/WindowScroller\.js";/g,
|
||||
'const bpfrpt_proptype_WindowScroller = null;',
|
||||
);
|
||||
const pickClientEnv = (env: Record<string, string>) =>
|
||||
Object.keys(env).reduce<Record<string, string>>((acc, key) => {
|
||||
if (allowedEnvPrefixes.some((prefix) => key.startsWith(prefix))) {
|
||||
acc[key] = env[key];
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
const reactVirtualizedOptimizePatch = () => ({
|
||||
name: 'react-virtualized-optimize-patch',
|
||||
setup(build) {
|
||||
const filter =
|
||||
/react-virtualized\/dist\/es\/WindowScroller\/utils\/(onScroll|dimensions)\.js$/;
|
||||
build.onLoad({ filter }, async args => {
|
||||
const contents = await readFile(args.path, 'utf-8');
|
||||
return {
|
||||
contents: contents.replace(
|
||||
/import \{ bpfrpt_proptype_WindowScroller \} from "\.\.\/WindowScroller\.js";/g,
|
||||
'const bpfrpt_proptype_WindowScroller = null;',
|
||||
),
|
||||
loader: 'js',
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const pickClientEnv = (env: Record<string, string>) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(env).filter(([key]) =>
|
||||
allowedEnvPrefixes.some(prefix => key.startsWith(prefix)),
|
||||
),
|
||||
);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(({ mode }) => {
|
||||
@@ -59,9 +22,16 @@ export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, rootDir, '');
|
||||
const clientEnv = pickClientEnv(env);
|
||||
const port = Number(env.PORT) || 4000;
|
||||
const plugins: PluginOption[] = [
|
||||
react(),
|
||||
legacy({
|
||||
targets: ['defaults', 'not IE 11'],
|
||||
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
|
||||
}),
|
||||
];
|
||||
|
||||
return {
|
||||
plugins: [react(), reactVirtualizedCompat()],
|
||||
plugins,
|
||||
root: rootDir,
|
||||
resolve: {
|
||||
alias: {
|
||||
@@ -92,9 +62,8 @@ export default defineConfig(({ mode }) => {
|
||||
},
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
plugins: [reactVirtualizedOptimizePatch()],
|
||||
plugins: [fixReactVirtualized],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user