mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-03-19 08:06:32 +03:00
optimize for vite v8
This commit is contained in:
@@ -2,9 +2,8 @@ import preact from '@preact/preset-vite';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { visualizer } from 'rollup-plugin-visualizer';
|
import { visualizer } from 'rollup-plugin-visualizer';
|
||||||
import { Plugin, defineConfig } from 'vite';
|
import { Plugin, PluginOption, defineConfig } from 'vite';
|
||||||
import viteImagemin from 'vite-plugin-imagemin';
|
import viteImagemin from 'vite-plugin-imagemin';
|
||||||
import viteTsconfigPaths from 'vite-tsconfig-paths';
|
|
||||||
import zlib from 'zlib';
|
import zlib from 'zlib';
|
||||||
|
|
||||||
// @ts-expect-error - mock server doesn't have type declarations
|
// @ts-expect-error - mock server doesn't have type declarations
|
||||||
@@ -99,16 +98,31 @@ const createPreactPlugin = (devToolsEnabled: boolean) =>
|
|||||||
prefreshEnabled: false
|
prefreshEnabled: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Patch preact/compat to export stub React 19 APIs (use, useOptimistic) so that
|
||||||
|
// react-router v7 doesn't trigger IMPORT_IS_UNDEFINED warnings from Rolldown.
|
||||||
|
const preactCompatPatchPlugin = (): Plugin => ({
|
||||||
|
name: 'preact-compat-react19-patch',
|
||||||
|
transform(code, id) {
|
||||||
|
if (id.includes('preact') && id.includes('compat.module.js')) {
|
||||||
|
return {
|
||||||
|
code:
|
||||||
|
code +
|
||||||
|
'\nexport var use = undefined;\nexport var useOptimistic = undefined;\n',
|
||||||
|
map: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Common base plugins
|
// Common base plugins
|
||||||
const createBasePlugins = (
|
const createBasePlugins = (
|
||||||
devToolsEnabled: boolean,
|
devToolsEnabled: boolean,
|
||||||
includeBundleReporter = true
|
includeBundleReporter = true
|
||||||
) => {
|
): PluginOption[] => {
|
||||||
const plugins = [
|
const plugins: PluginOption[] = [
|
||||||
createPreactPlugin(devToolsEnabled),
|
createPreactPlugin(devToolsEnabled),
|
||||||
viteTsconfigPaths({
|
preactCompatPatchPlugin()
|
||||||
projects: ['./tsconfig.json']
|
|
||||||
})
|
|
||||||
];
|
];
|
||||||
if (includeBundleReporter) {
|
if (includeBundleReporter) {
|
||||||
plugins.push(bundleSizeReporter());
|
plugins.push(bundleSizeReporter());
|
||||||
@@ -234,7 +248,8 @@ export default defineConfig(
|
|||||||
plugins: [...createBasePlugins(true, true), mockServer()],
|
plugins: [...createBasePlugins(true, true), mockServer()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: RESOLVE_ALIASES,
|
alias: RESOLVE_ALIASES,
|
||||||
extensions: RESOLVE_EXTENSIONS
|
extensions: RESOLVE_EXTENSIONS,
|
||||||
|
tsconfigPaths: true
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
open: true,
|
open: true,
|
||||||
@@ -263,7 +278,8 @@ export default defineConfig(
|
|||||||
plugins: createBasePlugins(false, true),
|
plugins: createBasePlugins(false, true),
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: RESOLVE_ALIASES,
|
alias: RESOLVE_ALIASES,
|
||||||
extensions: RESOLVE_EXTENSIONS
|
extensions: RESOLVE_EXTENSIONS,
|
||||||
|
tsconfigPaths: true
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
...createBaseBuildConfig(),
|
...createBaseBuildConfig(),
|
||||||
@@ -297,7 +313,8 @@ export default defineConfig(
|
|||||||
],
|
],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: RESOLVE_ALIASES,
|
alias: RESOLVE_ALIASES,
|
||||||
extensions: RESOLVE_EXTENSIONS
|
extensions: RESOLVE_EXTENSIONS,
|
||||||
|
tsconfigPaths: true
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
...createBaseBuildConfig(),
|
...createBaseBuildConfig(),
|
||||||
@@ -306,8 +323,7 @@ export default defineConfig(
|
|||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
treeshake: {
|
treeshake: {
|
||||||
moduleSideEffects: false,
|
moduleSideEffects: false,
|
||||||
propertyReadSideEffects: false,
|
propertyReadSideEffects: false as const,
|
||||||
tryCatchDeoptimization: false,
|
|
||||||
unknownGlobalSideEffects: false
|
unknownGlobalSideEffects: false
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
|
|||||||
Reference in New Issue
Block a user