Skip to content

fix: normalize vite config resolution #24369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 26, 2022

Conversation

ZachJW34
Copy link
Contributor

@ZachJW34 ZachJW34 commented Oct 24, 2022

User facing changelog

vite.config.{js,ts} will no longer be sourced when component.devServer.viteConfig is provided in the project's Cypress config

Additional details

This change brings the vite-dev-server config resolution inline with webpack-dev-server which was deemed to be the proper resolution of the config. With this change, we will no longer source the project's Vite config if they have provided a viteConfig property in their Cypress component.devServer config.

The previous behavior was confusing when dealing with edge-cases. If a user happened to require their Vite Config in there Cypress config and returned the full config, we would still source their vite config which could potentially end up double merging and duplicating plugins.

Steps to test

See the Test code to reproduce in the original issue.

How has the user experience changed?

Screen.Recording.2022-10-24.at.3.52.43.PM.mov

NOTE: Before merging, during squash add BREAKING CHANGE to footer message

PR Tasks

TODO: Figure out what branch to target, this will be a breaking change but v11 branch already exists and we don't want those changes until v12.

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 24, 2022

Thanks for taking the time to open a PR!

@ZachJW34 ZachJW34 force-pushed the zachw/normalize-vite-webpack-config-resolve branch from e8a07a4 to cf3ca15 Compare October 24, 2022 19:55
@@ -21,19 +21,6 @@ export default defineConfig({
devServer: {
bundler: 'vite',
framework: 'vue',
viteConfig: {
optimizeDeps: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vite 3.0 made many improvements for handling unoptimized deps. The problem this was fixing was reloads that would occur mid-test when Vite was scanning deps. From my testing, this no longer happens and we can safely remove this list.

},
plugins: [
Cypress(config, vite),
CypressInspect(config),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A user can push this plugin in themselves, doesn't really make sense for us to support this, especially since it's use is not documented.

webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => {
if (removeList.includes(plugin.constructor.name)) {
/* eslint-disable no-console */
console.warn(`[@cypress/webpack-dev-server]: removing ${plugin.constructor.name} from configuration.`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We modify the webpack config pretty heavily but don't console log for every tweak we make. Removing this log so as to clean up the terminal output.

@@ -183,12 +146,5 @@ export async function makeWebpackConfig (

debug('Merged webpack config %o', mergedConfig)

if (process.env.WEBPACK_PERF_MEASURE) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have this documented, and it doesn't work for many Webpack 5 apps so it's getting removed.

}

const finalConfig = vite.mergeConfig(
resolvedOverrides,
makeCypressViteConfig(config, vite),
Copy link
Contributor Author

@ZachJW34 ZachJW34 Oct 24, 2022

Choose a reason for hiding this comment

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

This used to be swapped, but we don't want users overriding our base config. This makes it so our vite config takes precedence (same as how we handle Webpack config in webpack-dev-server).

@cypress
Copy link

cypress bot commented Oct 24, 2022

@ZachJW34 ZachJW34 changed the base branch from develop to release/11.0.0 October 24, 2022 20:57
@ZachJW34 ZachJW34 marked this pull request as ready for review October 24, 2022 20:59
Copy link
Contributor

@astone123 astone123 left a comment

Choose a reason for hiding this comment

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

I tested this and can confirm that if I provide a viteConfig property in my Cypress config that my vite.config.ts file is not merged into the resolved config 👍🏻

Copy link
Contributor

@rockindahizzy rockindahizzy left a comment

Choose a reason for hiding this comment

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

👍

@ZachJW34 ZachJW34 merged commit feba489 into release/11.0.0 Oct 26, 2022
@ZachJW34 ZachJW34 deleted the zachw/normalize-vite-webpack-config-resolve branch October 26, 2022 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Normalize DevServer Config Resolution
3 participants