Skip to content

Commit

Permalink
feat(cli): 监听非 源码目录 (#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
1021683053 authored and luckyadam committed Nov 29, 2018
1 parent 205f784 commit 8c8e871
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/taro-cli/src/weapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const outputDir = path.join(appPath, outputDirName)
const entryFilePath = Util.resolveScriptPath(path.join(sourceDir, CONFIG.ENTRY))
const entryFileName = path.basename(entryFilePath)
const outputEntryFilePath = path.join(outputDir, entryFileName)
const watcherDirs = projectConfig.watcher || []

const pluginsConfig = projectConfig.plugins || {}
const weappConf = projectConfig.weapp || {}
Expand Down Expand Up @@ -1903,7 +1904,8 @@ function watchFiles () {
isBuildingScripts = {}
isBuildingStyles = {}
isCopyingFiles = {}
const watcher = chokidar.watch(path.join(sourceDir), {
const watcherPaths = [path.join(sourceDir)].concat(watcherDirs)
const watcher = chokidar.watch(watcherPaths, {
ignored: /(^|[/\\])\../,
persistent: true,
ignoreInitial: true
Expand Down Expand Up @@ -1997,7 +1999,13 @@ function watchFiles () {
let modifySource = outputWXSSPath.replace(appPath + path.sep, '')
modifySource = modifySource.split(path.sep).join('/')
Util.printLog(Util.pocessTypeEnum.MODIFY, '样式文件', modifySource)
outputWXSSPath = outputWXSSPath.replace(sourceDir, outputDir)
if( NODE_MODULES_REG.test(outputWXSSPath) ){
let sourceNodeModulesDir = path.join(appPath, NODE_MODULES)
let outputNodeModulesDir = path.join(outputDir, weappNpmConfig.name)
outputWXSSPath = outputWXSSPath.replace(sourceNodeModulesDir, outputNodeModulesDir)
}else{
outputWXSSPath = outputWXSSPath.replace(sourceDir, outputDir)
}
let modifyOutput = outputWXSSPath.replace(appPath + path.sep, '')
modifyOutput = modifyOutput.split(path.sep).join('/')
let isComponent = false
Expand All @@ -2021,7 +2029,13 @@ function watchFiles () {
let modifySource = outputWXSSPath.replace(appPath + path.sep, '')
modifySource = modifySource.split(path.sep).join('/')
Util.printLog(Util.pocessTypeEnum.MODIFY, '样式文件', modifySource)
outputWXSSPath = outputWXSSPath.replace(sourceDir, outputDir)
if( NODE_MODULES_REG.test(outputWXSSPath) ){
let sourceNodeModulesDir = path.join(appPath, NODE_MODULES)
let outputNodeModulesDir = path.join(outputDir, weappNpmConfig.name)
outputWXSSPath = outputWXSSPath.replace(sourceNodeModulesDir, outputNodeModulesDir)
}else{
outputWXSSPath = outputWXSSPath.replace(sourceDir, outputDir)
}
let modifyOutput = outputWXSSPath.replace(appPath + path.sep, '')
modifyOutput = modifyOutput.split(path.sep).join('/')
if (isWindows) {
Expand Down

0 comments on commit 8c8e871

Please sign in to comment.