diff --git a/src/index.ts b/src/index.ts index c775300..2cf3ea2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ import path from 'path' import Debug from 'debug' import { build, InlineConfig } from 'vite' import type { RollupOutput, RollupWatcher, WatcherOptions } from 'rollup' -import { getConfig, resolveConfig } from './resolveConfig' type FileObject = Cypress.FileObject type CypressPreprocessor = (file: FileObject) => string | Promise @@ -25,12 +24,6 @@ const cache: Record = {} function vitePreprocessor(userConfigPath?: string): CypressPreprocessor { debug('User config path: %s', userConfigPath) - if (userConfigPath) { - resolveConfig(userConfigPath).then((config) => { - debug('Resolved user config:', config) - }) - } - return async (file) => { const { outputPath, filePath, shouldWatch } = file debug('Preprocessing file %s', filePath) @@ -67,10 +60,10 @@ function vitePreprocessor(userConfigPath?: string): CypressPreprocessor { }, } - const buildConfig = getConfig(defaultConfig) - debug('Build config for file %s:', filePath, buildConfig) - - const watcher = await build(buildConfig) + const watcher = await build({ + configFile: userConfigPath, + ...defaultConfig, + }) if (shouldWatch && isWatcher(watcher)) { watcher.on('event', (event) => { diff --git a/src/resolveConfig.ts b/src/resolveConfig.ts deleted file mode 100644 index b8a4851..0000000 --- a/src/resolveConfig.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { - loadConfigFromFile, - UserConfig, - mergeConfig, - InlineConfig, - ConfigEnv, -} from 'vite' - -let resolvedUserConfig: UserConfig | undefined = undefined - -const configEnv: ConfigEnv = { command: 'build', mode: 'development' } - -export function resolveConfig(userConfigPath: string) { - return loadConfigFromFile(configEnv, userConfigPath).then((result) => { - resolvedUserConfig = result?.config - return resolvedUserConfig - }) -} - -export function getConfig(defaultConfig: InlineConfig) { - if (resolvedUserConfig) { - return mergeConfig(resolvedUserConfig, defaultConfig) - } - - return defaultConfig -}