mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
test: fix playground config variants (#13725)
This commit is contained in:
parent
df492face0
commit
8f109a67bd
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-relative-base'
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-runtime-base'
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-url-base'
|
@ -1,2 +0,0 @@
|
||||
import config from '../../vite.config-no-css-minify'
|
||||
export default config
|
@ -1,2 +0,0 @@
|
||||
import config from '../../vite.config-same-file-name'
|
||||
export default config
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-preload-disabled'
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-resolve-deps'
|
@ -4,6 +4,7 @@ import os from 'node:os'
|
||||
import fs from 'fs-extra'
|
||||
import { chromium } from 'playwright-chromium'
|
||||
import type {
|
||||
ConfigEnv,
|
||||
InlineConfig,
|
||||
Logger,
|
||||
PluginOption,
|
||||
@ -197,27 +198,31 @@ beforeAll(async (s) => {
|
||||
}
|
||||
})
|
||||
|
||||
function loadConfigFromDir(dir: string) {
|
||||
return loadConfigFromFile(
|
||||
{
|
||||
command: isBuild ? 'build' : 'serve',
|
||||
mode: isBuild ? 'production' : 'development',
|
||||
},
|
||||
undefined,
|
||||
dir,
|
||||
)
|
||||
}
|
||||
|
||||
export async function startDefaultServe(): Promise<void> {
|
||||
let config: UserConfig | null = null
|
||||
// config file near the *.spec.ts
|
||||
const res = await loadConfigFromDir(dirname(testPath))
|
||||
|
||||
const configEnv: ConfigEnv = {
|
||||
command: isBuild ? 'build' : 'serve',
|
||||
mode: isBuild ? 'production' : 'development',
|
||||
}
|
||||
|
||||
// config file named by convention as the *.spec.ts folder
|
||||
const variantName = path.basename(dirname(testPath))
|
||||
if (variantName !== '__tests__') {
|
||||
const configVariantPath = path.resolve(
|
||||
rootDir,
|
||||
`vite.config-${variantName}.js`,
|
||||
)
|
||||
if (fs.existsSync(configVariantPath)) {
|
||||
const res = await loadConfigFromFile(configEnv, configVariantPath)
|
||||
if (res) {
|
||||
config = res.config
|
||||
}
|
||||
}
|
||||
}
|
||||
// config file from test root dir
|
||||
if (!config) {
|
||||
const res = await loadConfigFromDir(rootDir)
|
||||
const res = await loadConfigFromFile(configEnv, undefined, rootDir)
|
||||
if (res) {
|
||||
config = res.config
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-es'
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-iife'
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-relative-base-iife'
|
@ -1 +0,0 @@
|
||||
export { default } from '../../vite.config-relative-base'
|
@ -1,2 +0,0 @@
|
||||
import sourcemap from '../../vite.config-sourcemap'
|
||||
export default sourcemap('hidden')
|
@ -1,2 +0,0 @@
|
||||
import sourcemap from '../../vite.config-sourcemap'
|
||||
export default sourcemap('inline')
|
@ -1,2 +0,0 @@
|
||||
import sourcemap from '../../vite.config-sourcemap'
|
||||
export default sourcemap(true)
|
2
playground/worker/vite.config-sourcemap-hidden.js
Normal file
2
playground/worker/vite.config-sourcemap-hidden.js
Normal file
@ -0,0 +1,2 @@
|
||||
import sourcemap from './worker-sourcemap-config.js'
|
||||
export default sourcemap('hidden')
|
2
playground/worker/vite.config-sourcemap-inline.js
Normal file
2
playground/worker/vite.config-sourcemap-inline.js
Normal file
@ -0,0 +1,2 @@
|
||||
import sourcemap from './worker-sourcemap-config.js'
|
||||
export default sourcemap('inline')
|
@ -1,50 +1,2 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import workerPluginTestPlugin from './worker-plugin-test-plugin'
|
||||
|
||||
/** @param {boolean | 'inline' | 'hidden' | 'sourcemap'} sourcemap */
|
||||
export default (sourcemap) => {
|
||||
sourcemap =
|
||||
/** @type {'inline' | 'hidden' | 'sourcemap'} */ (
|
||||
process.env.WORKER_MODE
|
||||
) || sourcemap
|
||||
|
||||
if (sourcemap === 'sourcemap') {
|
||||
sourcemap = true
|
||||
}
|
||||
|
||||
const typeName =
|
||||
typeof sourcemap === 'boolean' ? 'sourcemap' : 'sourcemap-' + sourcemap
|
||||
|
||||
return defineConfig({
|
||||
base: `/iife-${typeName}/`,
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': __dirname,
|
||||
},
|
||||
},
|
||||
worker: {
|
||||
format: 'iife',
|
||||
plugins: [workerPluginTestPlugin()],
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: 'assets/[name]-worker_asset[hash].[ext]',
|
||||
chunkFileNames: 'assets/[name]-worker_chunk[hash].js',
|
||||
entryFileNames: 'assets/[name]-worker_entry[hash].js',
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: `dist/iife-${typeName}/`,
|
||||
sourcemap: sourcemap,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: 'assets/[name]-[hash].[ext]',
|
||||
chunkFileNames: 'assets/[name]-[hash].js',
|
||||
entryFileNames: 'assets/[name]-[hash].js',
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [workerPluginTestPlugin()],
|
||||
cacheDir: `node_modules/.vite-sourcemap-${typeName}`,
|
||||
})
|
||||
}
|
||||
import sourcemap from './worker-sourcemap-config.js'
|
||||
export default sourcemap(true)
|
||||
|
50
playground/worker/worker-sourcemap-config.js
Normal file
50
playground/worker/worker-sourcemap-config.js
Normal file
@ -0,0 +1,50 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import workerPluginTestPlugin from './worker-plugin-test-plugin'
|
||||
|
||||
/** @param {boolean | 'inline' | 'hidden' | 'sourcemap'} sourcemap */
|
||||
export default (sourcemap) => {
|
||||
sourcemap =
|
||||
/** @type {'inline' | 'hidden' | 'sourcemap'} */ (
|
||||
process.env.WORKER_MODE
|
||||
) || sourcemap
|
||||
|
||||
if (sourcemap === 'sourcemap') {
|
||||
sourcemap = true
|
||||
}
|
||||
|
||||
const typeName =
|
||||
typeof sourcemap === 'boolean' ? 'sourcemap' : 'sourcemap-' + sourcemap
|
||||
|
||||
return defineConfig({
|
||||
base: `/iife-${typeName}/`,
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': __dirname,
|
||||
},
|
||||
},
|
||||
worker: {
|
||||
format: 'iife',
|
||||
plugins: [workerPluginTestPlugin()],
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: 'assets/[name]-worker_asset[hash].[ext]',
|
||||
chunkFileNames: 'assets/[name]-worker_chunk[hash].js',
|
||||
entryFileNames: 'assets/[name]-worker_entry[hash].js',
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: `dist/iife-${typeName}/`,
|
||||
sourcemap: sourcemap,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: 'assets/[name]-[hash].[ext]',
|
||||
chunkFileNames: 'assets/[name]-[hash].js',
|
||||
entryFileNames: 'assets/[name]-[hash].js',
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [workerPluginTestPlugin()],
|
||||
cacheDir: `node_modules/.vite-sourcemap-${typeName}`,
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user