46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
||
import { fileURLToPath } from 'node:url'
|
||
import vue from '@vitejs/plugin-vue'
|
||
import { defineConfig } from 'vite'
|
||
|
||
/**
|
||
* 组件 playground —— E2E(Playwright)与人工/ AI 手测共用的宿主页面。
|
||
*
|
||
* 只有两个用途:把组件跑在真实浏览器里、给每个可交互元素一个稳定的 data-testid。
|
||
* 不参与打包(files 只发布 dist),也不影响组件库构建。
|
||
*/
|
||
|
||
const configScssPath = fileURLToPath(new URL('../../tokens/src/scss/_config.scss', import.meta.url))
|
||
const configScss = readFileSync(configScssPath, 'utf-8')
|
||
|
||
function readScssDefault(name: string, fallback: string): string {
|
||
const match = configScss.match(new RegExp(`\\$${name}\\s*:\\s*['"]([^'"]+)['"]\\s*!default`))
|
||
return match ? match[1] : fallback
|
||
}
|
||
|
||
export default defineConfig({
|
||
root: fileURLToPath(new URL('.', import.meta.url)),
|
||
plugins: [vue()],
|
||
resolve: {
|
||
alias: [
|
||
{
|
||
find: /^@g3soft\/ui$/,
|
||
replacement: fileURLToPath(new URL('../src/index.ts', import.meta.url)),
|
||
},
|
||
{
|
||
find: /^@g3soft\/tokens$/,
|
||
replacement: fileURLToPath(new URL('../../tokens/dist/index.css', import.meta.url)),
|
||
},
|
||
{ find: /^vue$/, replacement: 'vue/dist/vue.esm-bundler.js' },
|
||
],
|
||
},
|
||
css: {
|
||
preprocessorOptions: { scss: { api: 'modern-compiler' } },
|
||
},
|
||
define: {
|
||
__G3_NAMESPACE__: JSON.stringify(readScssDefault('namespace', 'g3')),
|
||
__G3_STATE_PREFIX__: JSON.stringify(readScssDefault('state-prefix', 'is')),
|
||
},
|
||
server: { port: 5200, strictPort: true },
|
||
})
|