Skip to content

Commit

Permalink
fix(loader): 修复 px transform 传入参数 loader 未接受问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Oct 18, 2022
1 parent d25bb4a commit 793090c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
3 changes: 1 addition & 2 deletions packages/taro-webpack-runner/src/config/dev.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ export default function (appPath: string, config: Partial<BuildConfig>, appConfi
outputDir,
routerConfig: router,
useHtmlComponents,
designWidth,
deviceRatio
pxTransformConfig: pxtransformOption?.config || {}
})

if (enableExtract) {
Expand Down
3 changes: 1 addition & 2 deletions packages/taro-webpack-runner/src/config/prod.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ export default function (appPath: string, config: Partial<BuildConfig>, appConfi
outputDir,
routerConfig: router,
useHtmlComponents,
designWidth,
deviceRatio
pxTransformConfig: pxtransformOption?.config || {}
})

if (enableExtract) {
Expand Down
23 changes: 14 additions & 9 deletions packages/taro-webpack-runner/src/plugins/MainPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ interface IMainPluginOptions {
framework: FRAMEWORK_MAP
frameworkExts: string[]
useHtmlComponents: boolean
deviceRatio: any
designWidth: number
pxTransformConfig: {
baseFontSize: number
deviceRatio: any
designWidth: number
minRootSize: number
}
loaderMeta?: Record<string, string>
}

Expand All @@ -42,8 +46,12 @@ export default class MainPlugin {
framework: FRAMEWORK_MAP.NERV,
frameworkExts: SCRIPT_EXT,
useHtmlComponents: false,
deviceRatio: {},
designWidth: 750
pxTransformConfig: {
baseFontSize: 20,
deviceRatio: {},
designWidth: 750,
minRootSize: 20
}
})
this.sourceDir = this.options.sourceDir
this.outputDir = this.options.outputDir
Expand Down Expand Up @@ -75,7 +83,7 @@ export default class MainPlugin {

compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
compilation.hooks.normalModuleLoader.tap(PLUGIN_NAME, (_loaderContext, module: any) => {
const { framework, entryFileName, sourceDir, designWidth, deviceRatio, loaderMeta, routerConfig } = this.options
const { framework, entryFileName, sourceDir, pxTransformConfig, loaderMeta, routerConfig } = this.options
const { dir, name } = path.parse(module.resource)
const suffixRgx = /\.(boot|config)/
if (!suffixRgx.test(name)) return
Expand All @@ -98,10 +106,7 @@ export default class MainPlugin {
framework,
loaderMeta,
pages: this.pagesConfigList,
pxTransformConfig: {
designWidth,
deviceRatio
},
pxTransformConfig,
sourceDir,
useHtmlComponents: this.options.useHtmlComponents
}
Expand Down
23 changes: 14 additions & 9 deletions packages/taro-webpack5-runner/src/plugins/H5Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ interface IH5PluginOptions {
framework: FRAMEWORK_MAP
frameworkExts: string[]
useHtmlComponents: boolean
deviceRatio: any
designWidth: number
pxTransformConfig: {
baseFontSize: number
deviceRatio: any
designWidth: number
minRootSize: number
}
prebundle?: boolean
loaderMeta?: Record<string, string>
}
Expand All @@ -40,8 +44,12 @@ export default class H5Plugin {
framework: FRAMEWORK_MAP.NERV,
frameworkExts: SCRIPT_EXT,
useHtmlComponents: false,
deviceRatio: {},
designWidth: 750,
pxTransformConfig: {
baseFontSize: 20,
deviceRatio: {},
designWidth: 750,
minRootSize: 20
},
prebundle: false
})
}
Expand Down Expand Up @@ -73,7 +81,7 @@ export default class H5Plugin {

compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
webpack.NormalModule.getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (_loaderContext: LoaderContext<any>, module: webpack.NormalModule) => {
const { framework, entryFileName, appPath, sourceDir, designWidth, deviceRatio, loaderMeta, prebundle, routerConfig } = this.options
const { framework, entryFileName, appPath, sourceDir, pxTransformConfig, loaderMeta, prebundle, routerConfig } = this.options
const { dir, name } = path.parse(module.resource)
const suffixRgx = /\.(boot|config)/
if (!suffixRgx.test(name)) return
Expand Down Expand Up @@ -103,10 +111,7 @@ export default class H5Plugin {
framework,
loaderMeta,
pages: this.inst.pagesConfigList,
pxTransformConfig: {
designWidth,
deviceRatio
},
pxTransformConfig,
sourceDir,
useHtmlComponents: this.options.useHtmlComponents
},
Expand Down
8 changes: 3 additions & 5 deletions packages/taro-webpack5-runner/src/webpack/H5WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ export class H5WebpackPlugin {
const {
entryFileName = 'app',
router = {},
useHtmlComponents = false,
designWidth = 750,
deviceRatio
useHtmlComponents = false
} = config
const pxTransformConfig = this.pxtransformOption?.config || {}
const prebundleOptions = this.combination.getPrebundleOptions()
const options = {
appPath,
Expand All @@ -133,8 +132,7 @@ export class H5WebpackPlugin {
entryFileName,
routerConfig: router,
useHtmlComponents,
designWidth,
deviceRatio,
pxTransformConfig,
prebundle: prebundleOptions.enable
}

Expand Down

0 comments on commit 793090c

Please sign in to comment.