Skip to content

Commit

Permalink
Merge branch 'next' into refactor/template
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj authored Aug 18, 2020
2 parents 33ef25a + 8ad326a commit 9e31054
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default class TaroMiniPlugin {
prerenderPages: Set<string>
dependencies = new Map<string, TaroSingleEntryDependency>()
loadChunksPlugin: TaroLoadChunksPlugin
themeLocation: string

constructor (options = {} as ITaroMiniPluginOptions) {
this.options = Object.assign({
Expand Down Expand Up @@ -308,6 +309,7 @@ export default class TaroMiniPlugin {
this.appConfig = this.getAppConfig()
this.getPages()
this.getPagesConfig()
this.getDarkMode()
this.getConfigFiles(compiler)
this.addEntries()
}
Expand Down Expand Up @@ -541,6 +543,17 @@ export default class TaroMiniPlugin {
}
}

/**
* 收集 dark mode 配置中的文件
*/
getDarkMode () {
const themeLocation = this.appConfig.themeLocation
const darkMode = this.appConfig.darkmode
if (darkMode && themeLocation && typeof themeLocation === 'string') {
this.themeLocation = themeLocation
}
}

/**
* 搜集 tabbar icon 图标路径
* 收集自定义 tabbar 组件
Expand Down Expand Up @@ -641,6 +654,9 @@ export default class TaroMiniPlugin {
})
this.generateTabBarFiles(compilation)
this.injectCommonStyles(compilation)
if (this.themeLocation) {
this.generateDarkModeFile(compilation)
}
if (typeof modifyBuildAssets === 'function') {
await modifyBuildAssets(compilation.assets)
}
Expand Down Expand Up @@ -726,6 +742,22 @@ export default class TaroMiniPlugin {
return filePath + targetExtname
}

/**
* 输出 themeLocation 文件
* @param compilation
*/
generateDarkModeFile (compilation: webpack.compilation.Compilation) {
const themeLocationPath = path.resolve(this.options.sourceDir, this.themeLocation)
if (fs.existsSync(themeLocationPath)) {
const themeLocationStat = fs.statSync(themeLocationPath)
const themeLocationSource = fs.readFileSync(themeLocationPath)
compilation.assets[this.themeLocation] = {
size: () => themeLocationStat.size,
source: () => themeLocationSource
}
}
}

/**
* 输出 tabbar icons 文件
*/
Expand Down
10 changes: 10 additions & 0 deletions packages/taro/types/taro.config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ declare namespace Taro {
* @since 2.8.0
*/
style?: 'v2'
/**
* 配置 darkmode 为 true,即表示当前小程序已适配 DarkMode
* @since 2.11.0
*/
darkmode?: boolean
/**
* 指定 darkmode 变量配置文件 theme.json 路径
* @since 2.11.0
*/
themeLocation?: string
}

interface Config extends PageConfig, AppConfig {
Expand Down

0 comments on commit 9e31054

Please sign in to comment.