提交 a6f7b5a7 编写于 作者: D DCloud_LXH

feat(mp): copy theme.json use themeLocation

上级 79938ccf
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))
}
}
}
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
}
}
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册