Skip to content

Commit

Permalink
fix(plugin): 修复在插件中无法调用 taro api 的问题,close #9457 (#9490)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam authored Jun 10, 2021
1 parent 54964ae commit ba27972
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/taro-loader/src/independentPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ export default function (this: webpack.loader.LoaderContext) {
const componentPath = isNeedRawLoader
? `${raw}!${this.resourcePath}`
: this.request.split('!').slice(1).join('!')
const runtimePath = Array.isArray(options.runtimePath) ? options.runtimePath : [options.runtimePath]
const setReconciler = runtimePath.reduce((res, item) => {
return res + `import '${item}'\n`
}, '')
const prerender = `
if (typeof PRERENDER !== 'undefined') {
global._prerender = inst
}`
return `import { createPageConfig, ${creator}, window } from '@tarojs/runtime'
return `${setReconciler}
import { createPageConfig, ${creator}, window } from '@tarojs/runtime'
import component from ${stringify(componentPath)}
${importFrameworkStatement}
var config = ${configString};
Expand Down
7 changes: 6 additions & 1 deletion packages/taro-loader/src/native-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ export default function (this: webpack.loader.LoaderContext) {
const componentPath = isNeedRawLoader
? `${raw}!${this.resourcePath}`
: this.request.split('!').slice(thisLoaderIndex + 1).join('!')
const runtimePath = Array.isArray(options.runtimePath) ? options.runtimePath : [options.runtimePath]
const setReconciler = runtimePath.reduce((res, item) => {
return res + `import '${item}'\n`
}, '')
const prerender = `
if (typeof PRERENDER !== 'undefined') {
global._prerender = inst
}`

return `import { createNativeComponentConfig } from '@tarojs/runtime'
return `${setReconciler}
import { createNativeComponentConfig } from '@tarojs/runtime'
import component from ${stringify(componentPath)}
${importFrameworkStatement}
var config = ${configString};
Expand Down
6 changes: 4 additions & 2 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ export default class TaroMiniPlugin {
name: module.name,
prerender: this.prerenderPages.has(module.name),
config: this.filesConfig,
appConfig: this.appConfig
appConfig: this.appConfig,
runtimePath: this.options.runtimePath
}
})
}
Expand All @@ -294,7 +295,8 @@ export default class TaroMiniPlugin {
options: {
framework,
name: module.name,
prerender: this.prerenderPages.has(module.name)
prerender: this.prerenderPages.has(module.name),
runtimePath: this.options.runtimePath
}
})
}
Expand Down

0 comments on commit ba27972

Please sign in to comment.