Skip to content

Conversation

@patak-dev
Copy link
Member

Closes #8464
Closes #9171
Closes #9549
Closes #13018
Closes #14106

Description

Starting from #8280, we added experimental support for build time deps optimization. An idea by Evan, that was originally proposed at #4921. The idea was sound, removing a big difference between dev and build (no @rollup/plugin-commonjs, same esbuild pipeline for dependencies in both cases) and hopefully speeding up processing on warm builds (once deps were cached).

In practice, the extra complexity of doing deps optimization at build time and added points of failures made this feature stay experimental until now, seeing little usage. We had issues with rollup not being able to correctly tree-shake dependendencies (that we probably could have solved eventually, but is a good example).

With Rollup 4 switching its parser to native, and Rolldown being worked on, both the performance and the dev-vs-build inconsistency story for this feature are no longer valid. If we want to focus on improving dev/build consistency, then using Rolldown for prebundling during dev and Rolldown as-is during build is a better bet moving forward. Rolldown may also implement caching in a way that is a lot more efficient during build than deps prebundling.

This PR removes the feature, and also removes optimizeDeps.disabled: 'build' | 'dev' | boolean with it. We now have optimizeDeps.noDiscovery. So the optimizer can be disabled by setting optimizeDeps.noDiscovery: true and leaving optimizeDeps.include empty.

The PR keeps SSR deps optimization during dev. In this case, ssr.optimizeDeps.noDiscovery is always true, and the user must manually add deps to optimize to ssr.optimizeDeps.include. When we added this feature, we made noExternal auto-populate ssr.optimizeDeps.include. This PR removes this heuristic, because it means we will need a new config option to disable the SSR dev optimizer and also forced exclude to work differently. Given that noExternal/external may also be reviewed later, it is better to keep include explicit. The user can easily share the array if they would like all noExternal deps to be optimized. @bluwy raised the question if it is justified to keep deps optimization during SSR dev. The complexity is fairly low and it is useful to workaround some issues, so for now, it is kept in this PR. It is still experimental, so we can review and remove it later on too if that is desired.

Related feedback discussions:


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev patak-dev added p2-nice-to-have Not breaking anything but nice to have (priority) feat: deps optimizer Esbuild Dependencies Optimization feat: build labels Nov 29, 2023
@patak-dev
Copy link
Member Author

patak-dev commented Nov 29, 2023

I don't know why the docs are failing in netlify, they are building correctly locally.
Edit: it is failing in other PRs too #15187

Comment on lines +7 to 10
test.runIf(!isBuild)('message from require-external-cjs', async () => {
await page.goto(url)
expect(await page.textContent('.require-external-cjs')).toMatch('foo')
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sapphi-red I had to skip this test during build. It seems it only works with deps optimization during build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think it's fine for now. To make this work, we'll need to convert import foo from 'foo' into import module from 'node:module'; const foo = module.createRequire(import.meta.url)('foo') in this case.

@dominikg
Copy link
Contributor

this could break vite-plugin-svelte, which checks optimizeDeps.disabled but doesn't know about optimizeDeps.noDiscovery. If i understand it correctly noDiscovery isn't the same as disabled. noDiscovery prevents the auto-scanner, but user config/plugins like v-p-s would still be able to add to optimizeDeps.include. whereas disabled=true would turn it off completely.

The documentation here https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-disabled only mentions that optimizing in build mode is experimental, not that optimizeDeps.disabled as a flag itself is.

So to not break, i suggest to keep the disabled option, but change it so that false/'dev' log a warning that they are no longer supported. and with 6.0 we can change it to disabled: boolean

@dominikg
Copy link
Contributor

/ecosystem-ci run vite-plugin-svelte

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 8d6f5ac: Open

suite result latest scheduled
vite-plugin-svelte failure success

@brc-dd
Copy link
Contributor

brc-dd commented Nov 30, 2023

Edit: fixed in tsx, install [email protected]

For docs, you can set NODE_VERSION to 20 in netlify.toml. Node v18.19 changed some stuff about loaders that's breaking tsx. Created an issue upstream - privatenumber/tsx#421

@patak-dev
Copy link
Member Author

/ecosystem-ci run

@patak-dev
Copy link
Member Author

5da3702 brings back optimizeDeps.disabled with compat support and a warning.

The documentation here vitejs.dev/config/dep-optimization-options.html#optimizedeps-disabled only mentions that optimizing in build mode is experimental, not that optimizeDeps.disabled as a flag itself is.

Just for reference, both the docs and the types have optimizeDeps.disabled flag as experimental.

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 5da3702: Open

suite result latest scheduled
analogjs success success
astro success success
histoire failure failure
ladle success success
laravel failure failure
marko success success
nuxt failure failure
nx success success
previewjs success success
qwik success success
rakkas success success
sveltekit failure failure
unocss success success
vike success success
vite-plugin-pwa success success
vite-plugin-react success success
vite-plugin-react-pages success success
vite-plugin-react-swc success success
vite-plugin-svelte success success
vite-plugin-vue success success
vite-setup-catalogue failure success
vitepress success success
vitest success success

@patak-dev

This comment was marked as outdated.

@vite-ecosystem-ci

This comment was marked as outdated.

@sapphi-red
Copy link
Member

/ecosystem-ci run vite-setup-catalogue

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 5da3702: Open

suite result latest scheduled
vite-setup-catalogue success success

@patak-dev patak-dev added this to the 5.1 milestone Nov 30, 2023
// When we use the Rollup CommonJS plugin instead of esbuild prebundling,
// the esbuild plugins won't apply to dependencies
test('esbuild-plugin', async () => {
test.runIf(isServe)('esbuild-plugin', async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate your work, but I have some feedback I'd like to share. There are some custom esbuild plugins in my app to handle special files in dependencies, as described in docs. If the pre-build feature is removed at build time, is there any other way to keep the custom esbuild plugin consistent in build mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to have the same custom handling implemented as a rollup plugin. It would be good if you link to the way you are using it for reference, but I think it would be hard to justify the complexity this PR is removing as it can be still make to work. And later on if we move to Rolldown instead of esbuild, then you will get the consistency back for dependency handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: build feat: deps optimizer Esbuild Dependencies Optimization p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

Archived in project

8 participants