Skip to content

Commit

Permalink
fix(prebundle): 支持根据 define 参数去除不必要的依赖 fix #12385
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 20, 2022
1 parent 2e5ce13 commit 1a48b93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/taro-webpack5-prebundle/src/prebundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default class BasePrebundle<T extends IPrebundleConfig = IPrebundleConfig

await scanImports({
appPath: this.appPath,
chain: this.chain,
customEsbuildConfig: this.customEsbuildConfig,
entries,
include,
Expand Down
8 changes: 8 additions & 0 deletions packages/taro-webpack5-prebundle/src/prebundle/scanImports.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import esbuild, { Loader } from 'esbuild'
import fs from 'fs'
import path from 'path'
import Chain from 'webpack-chain'

import {
externalModule,
getDefines,
getResolve,
isExclude,
isOptimizeIncluded,
Expand All @@ -26,6 +28,7 @@ import {

interface ScanImportsConfig {
appPath: string
chain: Chain
entries: string[]
include: string[]
exclude: string[]
Expand All @@ -34,6 +37,7 @@ interface ScanImportsConfig {

export async function scanImports ({
appPath,
chain,
entries,
include = [],
exclude = [],
Expand All @@ -55,6 +59,10 @@ deps: CollectedDeps = new Map()
format: 'esm',
loader: defaultEsbuildLoader,
write: false,
define: {
...getDefines(chain),
define: 'false'
},
plugins: [
scanImportsPlugin,
...customPlugins
Expand Down

0 comments on commit 1a48b93

Please sign in to comment.