-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
New example request: @cypress/webpack-preprocessor
using exact same webpack config Cypress uses
#25998
Comments
@karlhorky I'm not sure I understand the use case for exposing internal webpack configs used for bundling up Cypress itself. Only portions of Cypress are bundled with Webpack (some areas use Vite), and the internal bundler configs are very specific and optimized for our codebase. The Webpack configs you referenced above are either specific to bundling up internal segments of Cypress (the runner package) or are used in Cypress Component Testing and are already extensible in that context using the The "default" webpack config used for loading spec files from a Cypress project is already exposed by const webpackPreprocessor = require('@cypress/webpack-preprocessor')
const options = webpackPreprocessor.defaultOptions
//...adjust default config
on('file:preprocessor', webpackPreprocessor(options)) |
This is not what I'm talking about - I'm talking about exposing the webpack configuration that Cypress uses to bundle user test code.
This is not true - the default webpack configuration of Cypress allows for TypeScript out of the box (and other features, I believe), whereas There is |
@karlhorky Have you looked at the const webpackPreprocessor = require('@cypress/webpack-batteries-included-preprocessor')
const options = webpackPreprocessor.getFullWebpackOptions(
"...path to project to find tsconfig file",
require.resolve("typescript")
) Might be worth adding a blurb to the README assuming that meets your needs |
That seems almost ok - but as I mentioned in my comment above, the |
I agree we should update to webpack 5 by default, but it's not trivial - it will likely be a breaking change. It's not possible to just slot in webpack 5 with the existing defaults, since those defaults assume webpack 4. What you can do is what I did here: https://github.com/lmiller1990/cypress-test-tiny/pull/1/files
const preprocessor = require('@cypress/webpack-preprocessor')
module.exports = {
e2e: {
setupNodeEvents(on, config) {
on('file:preprocessor', preprocessor())
},
},
} Now it will use the local webpack (so, v5, if you installed that). You will need to handle your own webpack config now, though - eg, adding whatever loaders you want, etc. The defaults are here. You could just copy-paste the ones you want from the batteries included one. |
@cypress/webpack-preprocessor
using exact same webpack config Cypress uses@cypress/webpack-preprocessor
using exact same webpack config Cypress uses
Yes, I'm aware of that. The point of this issue is to make an example + docs of an easy way to replicate the exact same configuration that Cypress uses for user test code internally - an example + docs which work out of the box. Additionally this example + documentation should be:
I would propose that this new example should be in the Not sure whether Cypress internally uses |
Sure thing. Are you interested in making a PR by any chance? We could
If you want to make a PR, that'd be great. If not, it will need to wait for someone else to work on. To answer your question about the batteries included preprocessor, it's the default, we require it here if you don't provide one. On CI, we run the latest commit against some real world apps, like https://github.com/cypress-io/cypress-realworld-app, which uses TS, React, etc - so if that passes, we know the batteries included preprocessor is doing it's job. |
Current behavior
It's hard to find the correct way to extend the webpack configuration which Cypress already uses (to keep the features that Cypress already has, such as TypeScript compilation).
It's even hard to find the Cypress webpack configuration, with multiple locations including fragments of webpack configuration:
cypress/npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts
Lines 71 to 122 in e674f43
cypress/packages/runner/webpack.config.ts
Lines 7 to 119 in e674f43
cypress/packages/web-config/webpack.config.base.ts
Lines 113 to 286 in e674f43
Desired behavior
It would be great to have a new example project with the exact same webpack configuration as is used inside Cypress for bundling user test code, similar to the 4 existing examples in the
system-tests/projects
folder:This example project should have the
cypress.config.js
file with thesetupNodeEvents
method configured, similar to the other examples above.Additionally, this example + documentation should be:
This way, it's easy to extend the existing webpack config used by Cypress by copying and pasting this example config and then adding your own configuration.
Test code to reproduce
The point of this issue is that it is difficult to find working code. There are many examples of outdated or non-working code throughout the issues in this repository and other locations.
Cypress Version
12.6.0
Node version
18.14.1
Operating System
macOS Ventura 13.2.1 (22D68)
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: