提交 75265cbd 编写于 作者: H hdx

feat(theme): 将 theme.json 编译到 config 中

上级 056ff23e
......@@ -26,6 +26,7 @@ export function uniAppPagesPlugin(): Plugin {
let launchPage = 'null'
let conditionUrl = ''
let uniIdRouter = 'new Map()'
let themeConfig = 'new Map()'
return {
name: 'uni:app-pages',
apply: 'build',
......@@ -42,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: {
......@@ -106,6 +108,9 @@ export function uniAppPagesPlugin(): Plugin {
uniIdRouter = stringifyMap(pagesJson.uniIdRouter)
}
launchPage = stringifyLaunchPage(pagesJson.pages[0])
// theme.json
themeConfig = readThemeJSONFileAsStringifyMap()
return {
code: `${imports.map((p) => `import './${p}.uvue'`).join('\n')}
export default 'pages.json'`,
......@@ -137,6 +142,7 @@ function defineAppConfig(){
__uniConfig.tabBar = __uniTabBar as Map<string, any> | null
__uniConfig.conditionUrl = '${conditionUrl}'
__uniConfig.uniIdRouter = ${uniIdRouter}
__uniConfig.themeConfig = ${themeConfig}
__uniConfig.ready = true
}
`
......@@ -158,3 +164,12 @@ function stringifyLaunchPage(launchPage: UniApp.PagesJsonPageOptions) {
function stringifyPageStyle(pageStyle: UniApp.PagesJsonPageStyle) {
return stringifyMap(pageStyle)
}
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(JSON.parse(content))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册