Skip to content

Commit

Permalink
fix(plugin): 修复小程序插件运行及引入taro-ui等第三方组件库报错问题,close #6730
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jul 30, 2020
1 parent 2a897f0 commit 748986f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/taro-mini-runner/src/loaders/pitcher.ts
Expand Up @@ -34,7 +34,7 @@ const genRequest = (loaderRequest, loaders) => {
}

export function pitch () {
const { sourceDir, fileType } = getOptions(this)
const { sourceDir, fileType, isBuildPlugin } = getOptions(this)
const query = qs.parse(this.resourceQuery.slice(1))

let loaders = this.loaders
Expand All @@ -45,7 +45,8 @@ export function pitch () {
let fileLoaderRequest = `${require.resolve('file-loader')}?name=[path][name]${fileType.templ}`
if (NODE_MODULES_REG.test(this.resourcePath)) {
const baseContext = path.join(process.cwd(), NODE_MODULES)
fileLoaderRequest += `&context=${baseContext}&outputPath=npm`
const npmDir = isBuildPlugin ? 'plugin/npm' : 'npm'
fileLoaderRequest += `&context=${baseContext}&outputPath=${npmDir}`
} else {
fileLoaderRequest += `&context=${sourceDir}`
}
Expand Down
9 changes: 6 additions & 3 deletions packages/taro-mini-runner/src/plugins/MiniLoaderPlugin.ts
Expand Up @@ -9,7 +9,8 @@ const NS = 'TARO'

interface IOptions {
sourceDir: string,
fileType: IFileType
fileType: IFileType,
isBuildPlugin: boolean
}

export default class MiniLoaderPlugin {
Expand All @@ -21,7 +22,8 @@ export default class MiniLoaderPlugin {
apply (compiler) {
const {
sourceDir,
fileType
fileType,
isBuildPlugin
} = this.options
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
const normalModuleLoader = compilation.hooks.normalModuleLoader
Expand All @@ -40,7 +42,8 @@ export default class MiniLoaderPlugin {
},
options: {
sourceDir,
fileType
fileType,
isBuildPlugin
}
}
compiler.options.module.rules = [
Expand Down
6 changes: 4 additions & 2 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Expand Up @@ -358,7 +358,8 @@ export default class MiniPlugin {
new TaroNormalModulesPlugin().apply(compiler)
new MiniLoaderPlugin({
sourceDir: this.sourceDir,
fileType
fileType,
isBuildPlugin
}).apply(compiler)
}

Expand Down Expand Up @@ -1091,7 +1092,8 @@ export default class MiniPlugin {
getRelativePath (filePath) {
let relativePath
if (NODE_MODULES_REG.test(filePath)) {
relativePath = filePath.replace(this.options.nodeModulesPath, 'npm')
const npmDir = this.options.isBuildPlugin ? 'plugin/npm' : 'npm'
relativePath = filePath.replace(this.options.nodeModulesPath, npmDir)
} else {
relativePath = filePath.replace(this.sourceDir, '')
}
Expand Down

0 comments on commit 748986f

Please sign in to comment.