提交 a6f7b5a7 编写于 作者: D DCloud_LXH

feat(mp): copy theme.json use themeLocation

上级 79938ccf
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const { parseJson } = require('./json')
const { const {
getJson getJson
...@@ -15,8 +16,8 @@ function parseThemeByJsonStr (jsonStr, keys, theme) { ...@@ -15,8 +16,8 @@ function parseThemeByJsonStr (jsonStr, keys, theme) {
return jsonStr return jsonStr
} }
function hasTheme (themeLocation = '') { function hasTheme (themeLocation = 'theme.json') {
const themeJsonPath = path.join(process.env.UNI_INPUT_DIR, themeLocation || 'theme.json') const themeJsonPath = path.join(process.env.UNI_INPUT_DIR, themeLocation)
return fs.existsSync(themeJsonPath) return fs.existsSync(themeJsonPath)
} }
...@@ -32,7 +33,7 @@ module.exports = { ...@@ -32,7 +33,7 @@ module.exports = {
hasTheme, hasTheme,
initTheme (manifestJson = {}) { initTheme (manifestJson = {}) {
const platform = process.env.UNI_PLATFORM const platform = process.env.UNI_PLATFORM
const themeLocation = (manifestJson[platform] || {}).themeLocation const themeLocation = (manifestJson[platform] || {}).themeLocation || 'theme.json'
if (!hasTheme(themeLocation)) { if (!hasTheme(themeLocation)) {
return return
} }
...@@ -40,7 +41,7 @@ module.exports = { ...@@ -40,7 +41,7 @@ module.exports = {
return return
} }
try { try {
themeConfig = getJson(themeLocation || 'theme.json', true) themeConfig = getJson(themeLocation, true)
global.uniPlugin.defaultTheme = themeConfig.light global.uniPlugin.defaultTheme = themeConfig.light
} catch (e) { } catch (e) {
console.error(e) console.error(e)
...@@ -59,5 +60,13 @@ module.exports = { ...@@ -59,5 +60,13 @@ module.exports = {
return parseThemeByJsonStr(json, keys, theme) return parseThemeByJsonStr(json, keys, theme)
} }
return JSON.parse(parseThemeByJsonStr(JSON.stringify(json), keys, theme)) return JSON.parse(parseThemeByJsonStr(JSON.stringify(json), keys, theme))
},
copyMiniProgramThemeJson (platformOptions, vueOptions) {
platformOptions.themeLocation || (platformOptions.themeLocation = 'theme.json')
return {
from: path.resolve(process.env.UNI_INPUT_DIR, platformOptions.themeLocation),
to: path.resolve(process.env.UNI_OUTPUT_DIR, platformOptions.themeLocation),
transform: content => JSON.stringify(parseJson(content.toString(), true))
}
} }
} }
const { copyMiniProgramThemeJson } = require('@dcloudio/uni-cli-shared/lib/theme')
module.exports = { module.exports = {
options: { options: {
cssVars: { cssVars: {
...@@ -16,10 +18,13 @@ module.exports = { ...@@ -16,10 +18,13 @@ module.exports = {
darkmode: true darkmode: true
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = ['ttcomponents', 'theme.json'] const copyOptions = ['ttcomponents']
global.uniModules.forEach(module => { global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/ttcomponents') copyOptions.push('uni_modules/' + module + '/ttcomponents')
}) })
copyOptions.push(copyMiniProgramThemeJson(platformOptions, vueOptions))
return copyOptions return copyOptions
} }
} }
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json') const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json')
const { copyMiniProgramThemeJson } = require('@dcloudio/uni-cli-shared/lib/theme')
const COMPONENTS_DIR_NAME = 'wxcomponents' const COMPONENTS_DIR_NAME = 'wxcomponents'
...@@ -26,7 +27,6 @@ module.exports = { ...@@ -26,7 +27,6 @@ module.exports = {
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0])
const copyOptions = [ const copyOptions = [
'theme.json',
'sitemap.json', 'sitemap.json',
'ext.json', 'ext.json',
'custom-tab-bar', 'custom-tab-bar',
...@@ -41,6 +41,8 @@ module.exports = { ...@@ -41,6 +41,8 @@ module.exports = {
}) })
} }
copyOptions.push(copyMiniProgramThemeJson(platformOptions, vueOptions))
const workers = platformOptions.workers const workers = platformOptions.workers
workers && copyOptions.push(workers) workers && copyOptions.push(workers)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册