improve build script

This commit is contained in:
Philipp Kühn
2020-11-10 09:21:47 +01:00
parent 0181b70bc2
commit 7d121eb39a
43 changed files with 314 additions and 240 deletions

View File

@@ -8,16 +8,20 @@ import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import babel from '@rollup/plugin-babel'
import { terser } from 'rollup-plugin-terser'
import sizes from '@atomico/rollup-plugin-sizes'
async function getSortedPackages(scope, ignore) {
const packages = await getPackages(__dirname)
const filtered = filterPackages(packages, scope, ignore, false)
return batchPackages(filtered).reduce((arr, batch) => arr.concat(batch), [])
return batchPackages(filtered)
.filter(item => item.name !== '@tiptap/docs')
.reduce((arr, batch) => arr.concat(batch), [])
}
async function main(commandLineArgs) {
async function build(commandLineArgs) {
const config = []
// Support --scope and --ignore globs if passed in via commandline
const { scope, ignore } = minimist(process.argv.slice(2))
const packages = await getSortedPackages(scope, ignore)
@@ -27,20 +31,53 @@ async function main(commandLineArgs) {
delete commandLineArgs.ignore
packages.forEach(pkg => {
/* Absolute path to package directory */
const basePath = path.relative(__dirname, pkg.location)
/* Absolute path to input file */
const input = path.join(basePath, 'index.ts')
/* "main" field from package.json file. */
const { main } = pkg.toJSON()
/* Push build config for this package. */
const {
name,
main,
umd,
module,
unpkg,
} = pkg.toJSON()
const plugins = [
resolve(),
commonjs(),
typescript({
tsconfigOverride: {
compilerOptions: {
declaration: true,
},
},
}),
babel({
babelHelpers: 'bundled',
}),
sizes(),
]
config.push({
input,
output: [
{
name,
file: path.join(basePath, umd),
format: 'umd',
sourcemap: true,
},
{
name,
file: path.join(basePath, main),
format: 'cjs',
sourcemap: true,
exports: 'auto',
},
{
name,
file: path.join(basePath, module),
format: 'es',
sourcemap: true,
},
],
external: [
@@ -48,19 +85,27 @@ async function main(commandLineArgs) {
...Object.keys(pkg.devDependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
plugins: [
resolve(),
commonjs(),
typescript(),
babel({
babelHelpers: 'bundled',
}),
terser(),
],
plugins,
})
// config.push({
// input,
// output: [
// {
// name,
// file: path.join(basePath, unpkg),
// format: 'umd',
// sourcemap: true,
// },
// ],
// plugins: [
// ...plugins,
// terser(),
// ],
// })
})
return config
}
export default main
export default build