diff --git a/.changeset/gentle-foxes-grow.md b/.changeset/gentle-foxes-grow.md new file mode 100644 index 000000000..d63eaf247 --- /dev/null +++ b/.changeset/gentle-foxes-grow.md @@ -0,0 +1,5 @@ +--- +"@suid/vite-plugin": minor +--- + +Add the `disableOptimizeDeps` option diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index 60a915b0e..af50a0f78 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -9,6 +9,7 @@ import { Wifi } from "@suid/material-icons"; // input import Wifi from "@suid/material-icons/Wifi"; // output ``` +- Sets the vite config required by `solid-start/vite` and `vite-plugin-solid`. ## Installation diff --git a/packages/vite-plugin/src/index.ts b/packages/vite-plugin/src/index.ts index 2124e40fb..cb4e8c756 100644 --- a/packages/vite-plugin/src/index.ts +++ b/packages/vite-plugin/src/index.ts @@ -9,6 +9,10 @@ const traverse: typeof $traverse = ($traverse as any).default; const generate: typeof $generate = ($generate as any).default; type SuidPluginOptions = { + /** + * @default ["@suid/base", "@suid/codemod", "@suid/css", "@suid/icons-material", "@suid/material", "@suid/styled-engine", "@suid/system", "@suid/types", "@suid/utils"] + */ + disableOptimizeDeps?: string[]; optimizeImports?: { /** * @default true @@ -23,6 +27,17 @@ type SuidPluginOptions = { }; const defaultOptions: SuidPluginOptions = { + disableOptimizeDeps: [ + "@suid/base", + "@suid/codemod", + "@suid/css", + "@suid/icons-material", + "@suid/material", + "@suid/styled-engine", + "@suid/system", + "@suid/types", + "@suid/utils", + ], optimizeImports: { enabled: true, paths: ["@suid/icons-material"], @@ -48,6 +63,24 @@ export default function suidPlugin(inOptions: SuidPluginOptions = {}): Plugin { }; return { name: "suid", + config: (config) => { + const solidDeps = options.disableOptimizeDeps || []; + return { + optimizeDeps: { + exclude: [...(config.optimizeDeps?.exclude || []), ...solidDeps], + }, + ssr: { + ...config.ssr, + noExternal: [ + ...(Array.isArray(config.ssr?.noExternal) + ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + config.ssr!.noExternal + : []), + ...solidDeps, + ], + }, + }; + }, transform(code) { const transformIconImportsOptions = options.optimizeImports || {}; if (