Merge remote-tracking branch 'origin/master'

pull/884/head
YunaiV 2026-06-14 02:48:19 +08:00
commit 9b416c722c
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import {resolve} from 'path' import {dirname, relative, resolve} from 'path'
import type {ConfigEnv, UserConfig} from 'vite' import type {ConfigEnv, UserConfig} from 'vite'
import {loadEnv, normalizePath} from 'vite' import {loadEnv, normalizePath} from 'vite'
import {createVitePlugins} from './build/vite' import {createVitePlugins} from './build/vite'
@ -11,6 +11,12 @@ function pathResolve(dir: string) {
return resolve(root, '.', dir) return resolve(root, '.', dir)
} }
function getRelativeScssUsePath(filename: string, targetPath: string) {
const cleanFilename = filename.split('?')[0]
const relativePath = normalizePath(relative(dirname(cleanFilename), targetPath))
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`
}
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default ({command, mode}: ConfigEnv): UserConfig => { export default ({command, mode}: ConfigEnv): UserConfig => {
let env = {} as any let env = {} as any
@ -20,7 +26,7 @@ export default ({command, mode}: ConfigEnv): UserConfig => {
} else { } else {
env = loadEnv(mode, root) env = loadEnv(mode, root)
} }
const variablesScssPath = normalizePath(pathResolve('src/styles/variables.scss')) const variablesScssPath = pathResolve('src/styles/variables.scss')
return { return {
base: env.VITE_BASE_PATH, base: env.VITE_BASE_PATH,
root: root, root: root,
@ -58,7 +64,7 @@ export default ({command, mode}: ConfigEnv): UserConfig => {
) { ) {
return source return source
} }
return `@use "${variablesScssPath}" as *;\n${source}` return `@use "${getRelativeScssUsePath(filename, variablesScssPath)}" as *;\n${source}`
}, },
api: 'modern-compiler' api: 'modern-compiler'
} }