This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-cli/target/_rollup.config.js
2020-03-31 15:30:11 +08:00

87 lines
2.8 KiB
JavaScript

import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import bundles from './build/index'
import fs from 'fs'
import path from 'path'
//import babel from 'rollup-plugin-babel';
import json from '@rollup/plugin-json'
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 {
input: `build/${bundle}.js`,
output: {
format: "cjs",
file: `bundle/${bundle}.js`,
sourcemap: true,
},
plugins: [
resolve({ mainFields: ["jsnext"] }),
commonjs(),
json(),
],
external: ['reflect-metadata', 'doric'],
onwarn: function (warning) {
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
console.warn(warning.message);
}
}
})
// If need ES5 support enable following configs
// .concat(
// allFiles
// .map(e => e.replace('.ts', ''))
// .map(bundle => {
// return {
// input: `build/${bundle}.js`,
// output: {
// format: "cjs",
// file: `bundle/${bundle}.es5.js`,
// sourcemap: true,
// },
// plugins: [
// resolve({ mainFields: ["jsnext"] }),
// commonjs(),
// buble({
// transforms: { dangerousForOf: true }
// }),
// ],
// external: ['reflect-metadata', 'doric'],
// onwarn: function (warning) {
// if (warning.code === 'THIS_IS_UNDEFINED') { return; }
// console.warn(warning.message);
// }
// }
// }))