Skip to content

Commit

Permalink
feat(vite-plugin): add the disableOptimizeDeps option
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Oct 28, 2022
1 parent eac250c commit 89148a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-foxes-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suid/vite-plugin": minor
---

Add the `disableOptimizeDeps` option
1 change: 1 addition & 0 deletions packages/vite-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"],
Expand All @@ -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 (
Expand Down

0 comments on commit 89148a6

Please sign in to comment.