Skip to content

Commit

Permalink
fix(mini-runner): 修复快应用打包报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Dec 31, 2019
1 parent 7477c76 commit ca7bdb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ export default class MiniPlugin {
template = `<style src='${relativeStylePath}'></style>\n` + template
}
if (scriptPath.indexOf(item) >= 0) {
let scriptContent = compilation.assets[item]._source.source()
const assetItem = compilation.assets[item]
let scriptContent = assetItem._source ? assetItem._source.source() : assetItem._value
scriptContent = `let exportRes;\n${scriptContent}\nexport default exportRes;`
hitScriptItem = item
template += `\n<script>${scriptContent}</script>`
Expand Down
22 changes: 14 additions & 8 deletions packages/taro-mini-runner/src/plugins/TaroLoadChunksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export default class TaroLoadChunksPlugin {
compilation.chunkTemplate.hooks.renderWithEntry.tap(PLUGIN_NAME, (modules, chunk) => {
if (chunk.entryModule) {
if (this.isBuildPlugin) {
const id = chunk.id
return addRequireToSource(id, modules, commonChunks)
} else if (chunk.entryModule.miniType === PARSE_AST_TYPE.ENTRY) {
return addRequireToSource(getIdOrName(chunk), modules, commonChunks)
}
if (chunk.entryModule.miniType === PARSE_AST_TYPE.ENTRY) {
compilation.hooks.afterOptimizeAssets.tap(PLUGIN_NAME, assets => {
const files = chunk.files
files.forEach(item => {
Expand All @@ -56,20 +56,26 @@ export default class TaroLoadChunksPlugin {
}
})
})
const name = chunk.name
return addRequireToSource(name, modules, commonChunks)
} else if ((this.buildAdapter === BUILD_TYPES.QUICKAPP) &&
return addRequireToSource(getIdOrName(chunk), modules, commonChunks)
}
if ((this.buildAdapter === BUILD_TYPES.QUICKAPP) &&
(chunk.entryModule.miniType === PARSE_AST_TYPE.PAGE ||
chunk.entryModule.miniType === PARSE_AST_TYPE.COMPONENT)) {
const id = chunk.id
return addRequireToSource(id, modules, commonChunks)
return addRequireToSource(getIdOrName(chunk), modules, commonChunks)
}
}
})
})
}
}

function getIdOrName (chunk) {
if (typeof chunk.id === 'string') {
return chunk.id
}
return chunk.name
}

function addRequireToSource (id, modules, commonChunks) {
const source = new ConcatSource()
commonChunks.forEach(chunkItem => {
Expand Down

0 comments on commit ca7bdb7

Please sign in to comment.