Skip to content

Commit

Permalink
fix(cli): 小程序编译 node_modules 中静态文件需要 copy,close #3135
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed May 24, 2019
1 parent 76d832c commit 3f847bb
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions packages/taro-cli/src/util/resolve_npm_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
REG_TYPESCRIPT,
BUILD_TYPES,
REG_STYLE,
REG_SCRIPTS
REG_SCRIPTS,
REG_FONT,
REG_IMAGE,
REG_MEDIA,
REG_JSON
} from './constants'

import defaultUglifyConfig from '../config/uglify'
Expand Down Expand Up @@ -91,21 +95,19 @@ export function resolveNpmFilesPath ({
files: []
}
resolvedCache[pkgName].files.push(res)
if (REG_SCRIPTS.test(res)) {
recursiveRequire({
filePath: res,
files: resolvedCache[pkgName].files,
isProduction,
npmConfig,
buildAdapter,
rootNpm,
npmOutputDir: npmOutputDir,
compileInclude,
env,
uglify,
babelConfig
})
}
recursiveRequire({
filePath: res,
files: resolvedCache[pkgName].files,
isProduction,
npmConfig,
buildAdapter,
rootNpm,
npmOutputDir: npmOutputDir,
compileInclude,
env,
uglify,
babelConfig
})
}
return resolvedCache[pkgName]
}
Expand Down Expand Up @@ -271,6 +273,14 @@ async function recursiveRequire ({
if (REG_STYLE.test(path.basename(filePath))) {
return
}
if (REG_FONT.test(filePath) || REG_IMAGE.test(filePath) || REG_MEDIA.test(filePath) || REG_JSON.test(filePath)) {
fs.ensureDirSync(path.dirname(outputNpmPath))
fs.writeFileSync(outputNpmPath, fileContent)
let modifyOutput = outputNpmPath.replace(path.dirname(rootNpm) + path.sep, '')
modifyOutput = modifyOutput.split(path.sep).join('/')
printLog(processTypeEnum.COPY, 'NPM文件', modifyOutput)
return
}
fileContent = npmCodeHack(filePath, fileContent, buildAdapter)
try {
const constantsReplaceList = Object.assign({
Expand Down

0 comments on commit 3f847bb

Please sign in to comment.