mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-09 18:18:50 -05:00
Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com> Co-authored-by: ElevateBart <ledouxb@gmail.com> Co-authored-by: Barthélémy Ledoux <bart@cypress.io>
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
// @ts-check
|
|
/// <reference types="next" />
|
|
const debug = require('debug')('@cypress/react')
|
|
const loadConfig = require('next/dist/next-server/server/config').default
|
|
const getNextJsBaseWebpackConfig = require('next/dist/build/webpack-config').default
|
|
|
|
async function getNextWebpackConfig (config) {
|
|
const nextConfig = await loadConfig('development', config.projectRoot)
|
|
const nextWebpackConfig = await getNextJsBaseWebpackConfig(
|
|
config.projectRoot,
|
|
{
|
|
buildId: `@cypress/react-${Math.random().toString()}`,
|
|
config: nextConfig,
|
|
dev: true,
|
|
isServer: false,
|
|
pagesDir: config.projectRoot,
|
|
entrypoints: {},
|
|
rewrites: { fallback: [], afterFiles: [], beforeFiles: [] },
|
|
},
|
|
)
|
|
|
|
debug('resolved next.js webpack config %o', nextWebpackConfig)
|
|
|
|
return nextWebpackConfig
|
|
}
|
|
|
|
let webpackConfigCache = null
|
|
|
|
/** Resolving next.js webpack and all config with plugin takes long, so cache the webpack configuration */
|
|
module.exports = async function findNextWebpackConfig (config) {
|
|
// ⛔️ ⛔️ Comment this `if` for debugging
|
|
if (webpackConfigCache !== null) {
|
|
return webpackConfigCache
|
|
}
|
|
|
|
webpackConfigCache = await getNextWebpackConfig(config)
|
|
debug('created and cached webpack preprocessor based on next.config.js', webpackConfigCache)
|
|
|
|
return webpackConfigCache
|
|
}
|