diff --git a/packages/uni-cli-shared/lib/theme.js b/packages/uni-cli-shared/lib/theme.js index 2f478396634253722fa2b3a8bf329101dbd9ea11..efa1f21e2d9bf483d531d90e4b41817d5d8b2bd8 100644 --- a/packages/uni-cli-shared/lib/theme.js +++ b/packages/uni-cli-shared/lib/theme.js @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') +const { parseJson } = require('./json') const { getJson @@ -15,8 +16,8 @@ function parseThemeByJsonStr (jsonStr, keys, theme) { return jsonStr } -function hasTheme (themeLocation = '') { - const themeJsonPath = path.join(process.env.UNI_INPUT_DIR, themeLocation || 'theme.json') +function hasTheme (themeLocation = 'theme.json') { + const themeJsonPath = path.join(process.env.UNI_INPUT_DIR, themeLocation) return fs.existsSync(themeJsonPath) } @@ -32,7 +33,7 @@ module.exports = { hasTheme, initTheme (manifestJson = {}) { const platform = process.env.UNI_PLATFORM - const themeLocation = (manifestJson[platform] || {}).themeLocation + const themeLocation = (manifestJson[platform] || {}).themeLocation || 'theme.json' if (!hasTheme(themeLocation)) { return } @@ -40,7 +41,7 @@ module.exports = { return } try { - themeConfig = getJson(themeLocation || 'theme.json', true) + themeConfig = getJson(themeLocation, true) global.uniPlugin.defaultTheme = themeConfig.light } catch (e) { console.error(e) @@ -59,5 +60,13 @@ module.exports = { return parseThemeByJsonStr(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)) + } } } diff --git a/packages/uni-mp-lark/lib/uni.config.js b/packages/uni-mp-lark/lib/uni.config.js index 2fb37e7331874ec970ea0fb55a6af85ccde0586f..0b7a8a41ec8a7ef542906c43aba05f63310fa940 100644 --- a/packages/uni-mp-lark/lib/uni.config.js +++ b/packages/uni-mp-lark/lib/uni.config.js @@ -1,3 +1,5 @@ +const { copyMiniProgramThemeJson } = require('@dcloudio/uni-cli-shared/lib/theme') + module.exports = { options: { cssVars: { @@ -16,10 +18,13 @@ module.exports = { darkmode: true }, copyWebpackOptions (platformOptions, vueOptions) { - const copyOptions = ['ttcomponents', 'theme.json'] + const copyOptions = ['ttcomponents'] global.uniModules.forEach(module => { copyOptions.push('uni_modules/' + module + '/ttcomponents') }) + + copyOptions.push(copyMiniProgramThemeJson(platformOptions, vueOptions)) + return copyOptions } } diff --git a/packages/uni-mp-weixin/lib/uni.config.js b/packages/uni-mp-weixin/lib/uni.config.js index 3c5b09c64225d241aaa619414a24e49824dc3470..33822d970ba0772196e703e5f7e36b98eb1a7a80 100644 --- a/packages/uni-mp-weixin/lib/uni.config.js +++ b/packages/uni-mp-weixin/lib/uni.config.js @@ -1,6 +1,7 @@ const fs = require('fs') const path = require('path') const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json') +const { copyMiniProgramThemeJson } = require('@dcloudio/uni-cli-shared/lib/theme') const COMPONENTS_DIR_NAME = 'wxcomponents' @@ -26,7 +27,6 @@ module.exports = { copyWebpackOptions (platformOptions, vueOptions) { const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const copyOptions = [ - 'theme.json', 'sitemap.json', 'ext.json', 'custom-tab-bar', @@ -41,6 +41,8 @@ module.exports = { }) } + copyOptions.push(copyMiniProgramThemeJson(platformOptions, vueOptions)) + const workers = platformOptions.workers workers && copyOptions.push(workers)