Skip to content

Instantly share code, notes, and snippets.

@patak-dev
Last active April 20, 2023 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patak-dev/0c2c1b445b02509c6398d50549ef8e75 to your computer and use it in GitHub Desktop.
Save patak-dev/0c2c1b445b02509c6398d50549ef8e75 to your computer and use it in GitHub Desktop.

Context

Currently

  • optimizeDeps.include is a list of entries to pre-add to the optimized list
  • optimizeDeps.exclude is a list of package names or entry names that will be excluded (works by checking both the id and the pkgId for each value)

#12414 proposes to add support for globs in optimizeDeps.include

Sheremet is looking to replace inline by optimizeDeps.include in Vitest.

Options

1. modify the meaning of optimizeDeps.include/exclude with a flag

  • a new option optimizeDeps.byDefault: false that would make include/exclude work like a regular createFilter over found dependencies
    • optimizeDeps.include supports globs
    • optimizeDeps.exclude supports globs

I don't think we should do this, as it is confusing that the semantics of include from "pre-add these deps" to "work as createFilter include".

2. Add a new optimizeDeps.autoDiscovery: false

Keep include/exclude as is, but only dependencies listed in optimizeDeps.include (and not excluded) would be optimized.

This option will also turn off the scanner (same effect as optimizeDeps.entries: []).

3. ignoreMissing: true

Same effect as 2., but having optimizeDeps.ignoreMissing: true to ignore dependencies when found while resolving. The user will need to turn off the scanner with entries: [] too. I prefer 2. because the scanner is conceptually an optimization, the option should affect both deps found by resolving or by the scanner to me.

4. Add a new optimizeDeps.filter

  • optimizeDeps.filter that could be a (id: string) => boolean (by default is () => true). We could also have { include, exclude } but it may be confusing with the other options. So Vitest could use filter to only optimize certain deps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment