Skip to content

Commit

Permalink
perf: 过滤收缩到 makeConfig 函数内
Browse files Browse the repository at this point in the history
  • Loading branch information
bigmeow committed Jun 28, 2023
1 parent 5fc99df commit 3bab5ec
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/taro-mini-runner/src/webpack/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ interface IRule {
}

export const makeConfig = async (buildConfig: IBuildConfig) => {
// 过滤原因:webpack4 不支持 output.clean 选项, 且 packages/taro-service/src/platform-plugin-base/web.ts 中实现了 output.clean
if (buildConfig.output && 'clean' in buildConfig.output) {
delete buildConfig.output.clean
}
const sassLoaderOption = await getSassLoaderOption(buildConfig)
return {
...buildConfig,
Expand Down
2 changes: 2 additions & 0 deletions packages/taro-service/src/platform-plugin-base/mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export abstract class TaroPlatformBase<T extends TConfig = TConfig> extends Taro

private setupImpl () {
const { output } = this.config
// webpack5 原生支持 output.clean 选项,但是 webpack4 不支持, 为统一行为,这里做一下兼容
// (在 packages/taro-mini-runner/src/webpack/chain.ts 和 packages/taro-webpack-runner/src/utils/chain.ts 的 makeConfig 中对 clean 选项做了过滤)
// 仅 output.clean 为 false 时不清空输出目录
// eslint-disable-next-line eqeqeq
if (output == undefined || output.clean == undefined || output.clean === true) {
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-service/src/platform-plugin-base/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export abstract class TaroPlatformWeb<T extends TConfig = TConfig> extends TaroP

private setupWebApp () {
const { output } = this.config
// H5 中 webpack5 原生支持 output.clean 选项,但是 webpack4 不支持, 为统一行为,这里做一下兼容(在packages/taro-mini-runner/src/index.ts 中对 clean 选项做了过滤)
// webpack5 原生支持 output.clean 选项,但是 webpack4 不支持, 为统一行为,这里做一下兼容
// (在 packages/taro-mini-runner/src/webpack/chain.ts 和 packages/taro-webpack-runner/src/utils/chain.ts 的 makeConfig 中对 clean 选项做了过滤)
// eslint-disable-next-line eqeqeq
if (output == undefined || output.clean == undefined || output.clean === true) {
this.emptyOutputDir()
Expand Down
4 changes: 0 additions & 4 deletions packages/taro-webpack-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ const buildDev = async (appPath: string, config: BuildConfig, appHelper: AppHelp
}

export default async (appPath: string, config: BuildConfig): Promise<void> => {
// 过滤原因:webpack4 不支持 output.clean 选项, 且 packages/taro-service/src/platform-plugin-base/web.ts 中实现了 output.clean
if (config.output && 'clean' in config.output) {
delete config.output.clean
}
const newConfig: BuildConfig = await makeConfig(config)
const app = new AppHelper(newConfig.entry, {
sourceDir: path.join(appPath, config.sourceRoot || SOURCE_DIR),
Expand Down
4 changes: 4 additions & 0 deletions packages/taro-webpack-runner/src/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import type { ICopyOptions, IPostcssOption, PostcssOption } from '@tarojs/taro/t
import type { BuildConfig, Option } from './types'

export const makeConfig = async (buildConfig: BuildConfig) => {
// 过滤原因:webpack4 不支持 output.clean 选项, 且 packages/taro-service/src/platform-plugin-base/web.ts 中实现了 output.clean
if (buildConfig.output && 'clean' in buildConfig.output) {
delete buildConfig.output.clean
}
const sassLoaderOption = await getSassLoaderOption(buildConfig)
return {
...buildConfig,
Expand Down

0 comments on commit 3bab5ec

Please sign in to comment.