Files
cypress/npm/react/plugins/next/findNextWebpackConfig.js
Dmitriy Kovalenko 254eb47d91 fix(component-testing): Fix webpack-dev-server deps validation crash (#15708)
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>
2021-04-02 10:12:57 -05:00

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
}