update rollup config

This commit is contained in:
pengfei.zhou 2019-12-18 15:29:01 +08:00
parent 883fac4f36
commit 130f15b6b0

View File

@ -1,8 +1,43 @@
import resolve from 'rollup-plugin-node-resolve' import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs' import commonjs from 'rollup-plugin-commonjs'
import bundles from './build/index' import bundles from './build/index'
import fs from 'fs'
import path from 'path'
export default bundles.map(bundle => { function readDirs(dirPath, files) {
if (fs.statSync(dirPath).isDirectory()) {
fs.readdirSync(dirPath).forEach(e => {
readDirs(path.join(dirPath, e), files)
})
} else {
for (let bundle of bundles) {
if (dirPath.match(new RegExp(`^${bundle}`))) {
files.push(dirPath)
}
}
}
}
const dirs = fs.readdirSync('.')
.filter(e => {
for (let bundle of bundles) {
if (bundle.match(new RegExp(`^${e}/`))) {
return true
}
}
return false
})
const allFiles = []
dirs.forEach(e => {
readDirs(e, allFiles)
})
export default allFiles
.map(e => e.replace('.ts', ''))
.map(bundle => {
return { return {
input: `build/${bundle}.js`, input: `build/${bundle}.js`,
output: { output: {
@ -11,9 +46,13 @@ export default bundles.map(bundle => {
sourcemap: true, sourcemap: true,
}, },
plugins: [ plugins: [
resolve({ jsnext: true, main: true }), resolve({ mainFields: ["jsnext"] }),
commonjs() commonjs()
], ],
external: ['reflect-metadata', 'doric'], external: ['reflect-metadata', 'doric'],
onwarn: function (warning) {
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
console.warn(warning.message);
}
} }
}) })