Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mp\h5): 支持 output.clean 选项 #14069

Merged
merged 17 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
perf: 过滤收缩到 makeConfig 函数内
  • Loading branch information
bigmeow committed Jun 28, 2023
commit 3bab5ec8baba308ed1d6f1b0b46fbac3b769506f
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