Skip to content

Commit

Permalink
fix(cli): 统一判断文件是否是页面的方式
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Aug 19, 2018
1 parent 52c428a commit a5fea58
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions packages/taro-cli/src/weapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,9 @@ function parseAst (type, ast, depComponents, sourceFilePath, filePath, npmSkip =
let value = source.value
const valueExtname = path.extname(value)
if (value.indexOf('.') === 0) {
let isPage = false
const pages = appConfig.pages || []
let importPath = path.resolve(path.dirname(sourceFilePath), value)
importPath = Util.resolveScriptPath(importPath)
const filePathWithoutExt = importPath.replace(path.extname(importPath), '')
pages.forEach(page => {
if (filePathWithoutExt === path.join(sourceDir, page)) {
isPage = true
}
})
if (isPage) {
if (isFileToBePage(importPath)) {
astPath.remove()
} else {
let isDepComponent = false
Expand Down Expand Up @@ -555,17 +547,9 @@ function parseAst (type, ast, depComponents, sourceFilePath, filePath, npmSkip =
let value = args[0].value
const valueExtname = path.extname(value)
if (value.indexOf('.') === 0) {
let isPage = false
const pages = appConfig.pages
let importPath = path.resolve(path.dirname(sourceFilePath), value)
importPath = Util.resolveScriptPath(importPath)
const filePathWithoutExt = importPath.replace(path.extname(importPath), '')
pages.forEach(page => {
if (filePathWithoutExt === path.join(sourceDir, page)) {
isPage = true
}
})
if (isPage) {
if (isFileToBePage(importPath)) {
if (astPath.parent.type === 'AssignmentExpression' || 'ExpressionStatement') {
astPath.parentPath.remove()
} else if (astPath.parent.type === 'VariableDeclarator') {
Expand Down Expand Up @@ -1628,15 +1612,8 @@ function watchFiles () {
await buildPages()
}
} else {
let isPage = isFileToBePage(filePath)
const pages = appConfig.pages || []
const filePathWithoutExt = filePath.replace(extname, '')
pages.forEach(page => {
if (filePathWithoutExt === path.join(sourceDir, page)) {
isPage = true
}
})
if (isPage) { // 编译页面
if (isFileToBePage(filePath)) { // 编译页面
filePath = filePathWithoutExt
filePath = filePath.replace(path.join(sourceDir) + path.sep, '')
filePath = filePath.split(path.sep).join('/')
Expand Down

0 comments on commit a5fea58

Please sign in to comment.