Skip to content
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

refactor(playground): move to ESM module and add type check for config #12131

Merged
merged 6 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions playground/alias/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const path = require('node:path')
import path from 'node:path'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
resolve: {
alias: [
{ find: 'fs', replacement: path.resolve(__dirname, 'test.js') },
Expand Down Expand Up @@ -39,4 +37,4 @@ module.exports = {
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: true,
},
}
})
4 changes: 2 additions & 2 deletions playground/assets-sanitize/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { defineConfig } = require('vite')
import { defineConfig } from 'vite'

module.exports = defineConfig({
export default defineConfig({
build: {
//speed up build
minify: false,
Expand Down
2 changes: 1 addition & 1 deletion playground/assets/__tests__/relative-base/vite.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../vite.config-relative-base')
export { default } from '../../vite.config-relative-base'
2 changes: 1 addition & 1 deletion playground/assets/__tests__/runtime-base/vite.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../vite.config-runtime-base')
export { default } from '../../vite.config-runtime-base'
12 changes: 5 additions & 7 deletions playground/assets/vite.config-relative-base.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/**
* @type {import('vite').UserConfig}
*/
import { defineConfig } from 'vite'
import baseConfig from './vite.config.js'

const baseConfig = require('./vite.config.js')
module.exports = {
export default defineConfig({
...baseConfig,
base: './', // relative base to make dist portable
build: {
...baseConfig.build,
outDir: 'dist/relative-base',
watch: false,
watch: null,
minify: false,
assetsInlineLimit: 0,
rollupOptions: {
Expand All @@ -23,4 +21,4 @@ module.exports = {
testConfig: {
baseRoute: '/relative-base/',
},
}
})
14 changes: 5 additions & 9 deletions playground/assets/vite.config-runtime-base.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
const path = require('node:path')
import { defineConfig } from 'vite'
import baseConfig from './vite.config.js'

const dynamicBaseAssetsCode = `
globalThis.__toAssetUrl = url => '/' + url
globalThis.__publicBase = '/'
`

const baseConfig = require('./vite.config.js')

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
...baseConfig,
base: './', // overwrite the original base: '/foo/'
build: {
...baseConfig.build,
outDir: 'dist',
watch: false,
watch: null,
minify: false,
assetsInlineLimit: 0,
rollupOptions: {
Expand Down Expand Up @@ -61,4 +57,4 @@ module.exports = {
}
},
},
}
})
12 changes: 6 additions & 6 deletions playground/assets/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('node:path')
import path from 'node:path'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
/** @type {import('vite').UserConfig} */
// @ts-expect-error typecast
export default defineConfig({
base: '/foo',
publicDir: 'static',
resolve: {
Expand All @@ -18,4 +18,4 @@ module.exports = {
manifest: true,
watch: {},
},
}
})
13 changes: 5 additions & 8 deletions playground/backend-integration/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('node:path')
const glob = require('fast-glob')
const normalizePath = require('vite').normalizePath
import path from 'node:path'
import glob from 'fast-glob'
import { defineConfig, normalizePath } from 'vite'

/**
* @returns {import('vite').Plugin}
Expand Down Expand Up @@ -40,10 +40,7 @@ function BackendIntegrationExample() {
}
}

/**
* @returns {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
base: '/dev/',
plugins: [BackendIntegrationExample()],
}
})
4 changes: 2 additions & 2 deletions playground/cli/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { defineConfig } = require('vite')
import { defineConfig } from 'vite'

module.exports = defineConfig({
export default defineConfig({
server: {
host: 'localhost',
headers: {
Expand Down
7 changes: 4 additions & 3 deletions playground/css-codesplit-cjs/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { resolve } = require('node:path')
import { resolve } from 'node:path'
import { defineConfig } from 'vite'

module.exports = {
export default defineConfig({
build: {
outDir: './dist',
manifest: true,
Expand All @@ -17,4 +18,4 @@ module.exports = {
},
},
},
}
})
7 changes: 4 additions & 3 deletions playground/css-codesplit/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { resolve } = require('node:path')
import { resolve } from 'node:path'
import { defineConfig } from 'vite'

module.exports = {
export default defineConfig({
build: {
manifest: true,
rollupOptions: {
Expand All @@ -18,4 +19,4 @@ module.exports = {
},
},
},
}
})
10 changes: 4 additions & 6 deletions playground/css-sourcemap/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const MagicString = require('magic-string')
import { defineConfig } from 'vite'
import MagicString from 'magic-string'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
resolve: {
alias: {
'@': __dirname,
Expand Down Expand Up @@ -58,4 +56,4 @@ module.exports = {
},
},
],
}
})
12 changes: 5 additions & 7 deletions playground/css/vite.config-relative-base.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/**
* @type {import('vite').UserConfig}
*/
import { defineConfig } from 'vite'
import baseConfig from './vite.config.js'

const baseConfig = require('./vite.config.js')
module.exports = {
export default defineConfig({
...baseConfig,
base: './', // relative base to make dist portable
build: {
...baseConfig.build,
outDir: 'dist/relative-base',
watch: false,
watch: null,
minify: false,
assetsInlineLimit: 0,
rollupOptions: {
Expand All @@ -23,4 +21,4 @@ module.exports = {
testConfig: {
baseRoute: '/relative-base/',
},
}
})
14 changes: 8 additions & 6 deletions playground/css/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const path = require('node:path')
import path from 'node:path'
import { defineConfig } from 'vite'

// trigger scss bug: https://github.com/sass/dart-sass/issues/710
// make sure Vite handles safely
// @ts-expect-error refer to https://github.com/vitejs/vite/pull/11079
globalThis.window = {}
// @ts-expect-error refer to https://github.com/vitejs/vite/pull/11079
globalThis.location = new URL('http://localhost/')

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
/** @type {import('vite').UserConfig} */
// @ts-expect-error typecast
export default defineConfig({
build: {
cssTarget: 'chrome61',
},
Expand Down Expand Up @@ -69,4 +71,4 @@ module.exports = {
},
},
},
}
})
8 changes: 6 additions & 2 deletions playground/define/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
import { defineConfig } from 'vite'

/** @type {import('vite').UserConfig} */
// @ts-expect-error typecast
export default defineConfig({
define: {
__EXP__: 'false',
__STRING__: '"hello"',
Expand All @@ -22,4 +26,4 @@ module.exports = {
__VAR_NAME__: false,
__STRINGIFIED_OBJ__: JSON.stringify({ foo: true }),
},
}
})
8 changes: 4 additions & 4 deletions playground/dynamic-import/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('node:fs')
const path = require('node:path')
const vite = require('vite')
import fs from 'node:fs'
import path from 'node:path'
import vite from 'vite'

module.exports = vite.defineConfig({
export default vite.defineConfig({
plugins: [
{
name: 'copy',
Expand Down
4 changes: 2 additions & 2 deletions playground/env-nested/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { defineConfig } = require('vite')
import { defineConfig } from 'vite'

module.exports = defineConfig({
export default defineConfig({
envDir: './envs',
})
4 changes: 2 additions & 2 deletions playground/env/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { defineConfig } = require('vite')
import { defineConfig } from 'vite'

process.env.EXPAND = 'expand'

module.exports = defineConfig({
export default defineConfig({
base: '/env/',
envPrefix: ['VITE_', 'CUSTOM_PREFIX_'],
build: {
Expand Down
6 changes: 4 additions & 2 deletions playground/extensions/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
import { defineConfig } from 'vite'

export default defineConfig({
resolve: {
alias: [{ find: 'vue', replacement: 'vue/dist/vue.esm-bundler.js' }],
extensions: ['.js'],
},
}
})
10 changes: 4 additions & 6 deletions playground/fs-serve/root/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const path = require('node:path')
import path from 'node:path'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
build: {
rollupOptions: {
input: {
Expand Down Expand Up @@ -31,4 +29,4 @@ module.exports = {
define: {
ROOT: JSON.stringify(path.dirname(__dirname).replace(/\\/g, '/')),
},
}
})
2 changes: 2 additions & 0 deletions playground/hmr/optional-chaining/parent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { foo } from './child'

import.meta.hot?.accept('./child', ({ foo }) => {
Expand Down
10 changes: 4 additions & 6 deletions playground/html/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { resolve } = require('node:path')
import { resolve } from 'node:path'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
base: './',
build: {
rollupOptions: {
Expand Down Expand Up @@ -189,4 +187,4 @@ ${
},
},
],
}
})
9 changes: 4 additions & 5 deletions playground/js-sourcemap/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* @type {import('vite').UserConfig}
*/
module.exports = {
import { defineConfig } from 'vite'

export default defineConfig({
build: {
sourcemap: true,
},
}
})
7 changes: 4 additions & 3 deletions playground/legacy/vite.config-custom-filename.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const legacy = require('@vitejs/plugin-legacy').default
import { defineConfig } from 'vite'
import legacy from '@vitejs/plugin-legacy'

module.exports = {
export default defineConfig({
plugins: [legacy({ modernPolyfills: true })],
build: {
manifest: true,
Expand All @@ -12,4 +13,4 @@ module.exports = {
},
},
},
}
})
2 changes: 1 addition & 1 deletion playground/legacy/vite.config-multiple-output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import legacy from '@vitejs/plugin-legacy'
import { defineConfig } from 'vite'
import legacy from '@vitejs/plugin-legacy'

export default defineConfig({
plugins: [legacy({ modernPolyfills: true })],
Expand Down
Loading