Skip to content

Commit

Permalink
fix(cli): 小程序端编译抽取npm包文件bug修复
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jun 9, 2018
1 parent 375f2dd commit 1ce8223
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/taro-cli/src/util/resolve_npm_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,22 @@ function recursiveRequire (filePath, files, isProduction) {
const relativeRequirePath = promoteRelativePath(path.relative(filePath, res.main))
return `require('${relativeRequirePath}')`
}
requirePath = path.resolve(path.dirname(filePath), requirePath)
if (!path.extname(requirePath)) {
requirePath += '.js'
let realRequirePath = path.resolve(path.dirname(filePath), requirePath)
let tempPathWithJS = `${realRequirePath}.js`
let tempPathWithIndexJS = `${realRequirePath}${path.sep}index.js`
if (!path.extname(realRequirePath)) {
if (fs.existsSync(tempPathWithJS)) {
realRequirePath = tempPathWithJS
} else if (fs.existsSync(tempPathWithIndexJS)) {
realRequirePath = tempPathWithIndexJS
requirePath += '/index.js'
}
}
if (files.indexOf(requirePath) < 0) {
files.push(requirePath)
if (files.indexOf(realRequirePath) < 0) {
files.push(realRequirePath)
recursiveRequire(realRequirePath, files, isProduction)
}
recursiveRequire(requirePath, files, isProduction)
return m
return `require('${requirePath}')`
})
const outputNpmPath = filePath.replace('node_modules', path.join(OUTPUT_DIR, NPM_DIR))
if (!copyedFiles[outputNpmPath]) {
Expand Down

0 comments on commit 1ce8223

Please sign in to comment.