move extendPackage

This commit is contained in:
fxy060608 2018-11-19 17:02:03 +08:00
parent 24f3dc0cac
commit ac88d22997

View File

@ -5,33 +5,9 @@ const isBinary = require('isbinaryfile')
const stripJsonComments = require('strip-json-comments')
async function generate(dir, files, base = '') {
const glob = require('glob')
glob.sync('**/*', {
cwd: dir,
nodir: true
}).forEach(rawPath => {
const sourcePath = path.resolve(dir, rawPath)
if (isBinary.sync(sourcePath)) {
files[path.join(base, rawPath)] = fs.readFileSync(sourcePath) // return buffer
} else {
const content = fs.readFileSync(sourcePath, 'utf-8')
if (sourcePath.indexOf('manifest.json') !== -1 || sourcePath.indexOf('pages.json') !== -1) {
files[path.join(base, rawPath)] = JSON.stringify(JSON.parse(stripJsonComments(content)), null, 2)
} else {
files[path.join(base, rawPath)] = content
}
}
})
}
module.exports = (api, options, rootOptions) => {
api.render(async function(files) {
api.extendPackage(pkg => {
delete pkg.postcss
delete pkg.browserslist
@ -52,6 +28,8 @@ module.exports = (api, options, rootOptions) => {
}
})
api.render(async function(files) {
Object.keys(files).forEach(name => {
delete files[name]
})