From 53119b63d260ca7ff2a615ccef3e50049fa6b02b Mon Sep 17 00:00:00 2001 From: hdx Date: Tue, 28 May 2024 18:29:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(theme):=20=E6=92=A4=E5=9B=9E=E5=AF=B9=20uni?= =?UTF-8?q?.scss=20=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/android/pagesJson.ts | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/uni-app-uts/src/plugins/android/pagesJson.ts b/packages/uni-app-uts/src/plugins/android/pagesJson.ts index e47bf71645..728484dad7 100644 --- a/packages/uni-app-uts/src/plugins/android/pagesJson.ts +++ b/packages/uni-app-uts/src/plugins/android/pagesJson.ts @@ -2,7 +2,6 @@ import path from 'path' import fs from 'fs-extra' import { PAGES_JSON_UTS, - ThemeSassParser, createRollupError, genUTSClassName, normalizeUniAppXAppPagesJson, @@ -44,6 +43,7 @@ export function uniAppPagesPlugin(): Plugin { transform(code, id) { if (isPages(id)) { this.addWatchFile(path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')) + this.addWatchFile(path.resolve(process.env.UNI_INPUT_DIR, 'theme.json')) let pagesJson: UniApp.PagesJson = { pages: [], globalStyle: { @@ -110,7 +110,7 @@ export function uniAppPagesPlugin(): Plugin { launchPage = stringifyLaunchPage(pagesJson.pages[0]) // theme.json - themeConfig = readUniSassAsStringifyMap() + themeConfig = readThemeJSONFileAsStringifyMap() return { code: `${imports.map((p) => `import './${p}.uvue'`).join('\n')} export default 'pages.json'`, @@ -165,13 +165,22 @@ function stringifyPageStyle(pageStyle: UniApp.PagesJsonPageStyle) { return stringifyMap(pageStyle) } -function readUniSassAsStringifyMap() { - const uniScssPath = path.resolve(process.env.UNI_INPUT_DIR, 'uni.scss') - let result = {} - if (fs.existsSync(uniScssPath)) { - const content = fs.readFileSync(uniScssPath, 'utf8') - const parser = new ThemeSassParser() - result = parser.parse(content) +// function readUniSassAsStringifyMap() { +// const uniScssPath = path.resolve(process.env.UNI_INPUT_DIR, 'uni.scss') +// let result = {} +// if (fs.existsSync(uniScssPath)) { +// const content = fs.readFileSync(uniScssPath, 'utf8') +// const parser = new ThemeSassParser() +// result = parser.parse(content) +// } +// return stringifyMap(result) +// } + +function readThemeJSONFileAsStringifyMap() { + const themeJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'theme.json') + let content = '{}' + if (fs.existsSync(themeJsonPath)) { + content = fs.readFileSync(themeJsonPath, 'utf8') } - return stringifyMap(result) + return stringifyMap(JSON.parse(content)) } -- GitLab