tiptap/rollup.config.js

110 lines
2.8 KiB
JavaScript
Raw Normal View History

import sizes from '@atomico/rollup-plugin-sizes'
import batchPackages from '@lerna/batch-packages'
import { filterPackages } from '@lerna/filter-packages'
import { getPackages } from '@lerna/project'
import babel from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import fs from 'fs'
2020-11-07 06:55:30 +08:00
import minimist from 'minimist'
import path from 'path'
import autoExternal from 'rollup-plugin-auto-external'
2020-11-12 04:00:53 +08:00
import sourcemaps from 'rollup-plugin-sourcemaps'
2020-11-07 06:55:30 +08:00
import typescript from 'rollup-plugin-typescript2'
async function getSortedPackages(scope, ignore) {
const packages = await getPackages(__dirname)
const filtered = filterPackages(packages, scope, ignore, false)
2020-11-10 16:21:47 +08:00
return batchPackages(filtered)
2021-09-20 15:44:38 +08:00
.filter(item => item.name !== '@tiptap/demos')
2020-11-10 16:21:47 +08:00
.reduce((arr, batch) => arr.concat(batch), [])
2020-11-07 06:55:30 +08:00
}
2020-11-10 16:21:47 +08:00
async function build(commandLineArgs) {
2020-11-07 06:55:30 +08:00
const config = []
2020-11-10 16:21:47 +08:00
2020-11-07 06:55:30 +08:00
// Support --scope and --ignore globs if passed in via commandline
2021-05-06 03:00:53 +08:00
const { scope, ignore } = minimist(process.argv.slice(2))
2020-11-07 06:55:30 +08:00
const packages = await getSortedPackages(scope, ignore)
// prevent rollup warning
2020-11-10 22:16:38 +08:00
delete commandLineArgs.ci
2020-11-07 06:55:30 +08:00
delete commandLineArgs.scope
delete commandLineArgs.ignore
packages.forEach(pkg => {
const basePath = path.relative(__dirname, pkg.location)
2020-11-10 23:29:31 +08:00
const input = path.join(basePath, 'src/index.ts')
2020-11-10 16:21:47 +08:00
const {
name,
main,
umd,
module,
} = pkg.toJSON()
2020-11-11 17:00:13 +08:00
const basePlugins = [
2020-11-12 04:00:53 +08:00
sourcemaps(),
2020-11-10 16:21:47 +08:00
resolve(),
commonjs(),
babel({
babelHelpers: 'bundled',
2020-11-12 04:00:53 +08:00
exclude: 'node_modules/**',
2020-11-10 16:21:47 +08:00
}),
sizes(),
]
2020-11-07 06:55:30 +08:00
config.push({
2020-11-17 16:45:42 +08:00
// perf: true,
2020-11-07 06:55:30 +08:00
input,
output: [
{
2020-11-10 16:21:47 +08:00
name,
file: path.join(basePath, umd),
format: 'umd',
sourcemap: true,
},
{
name,
2020-11-07 06:55:30 +08:00
file: path.join(basePath, main),
format: 'cjs',
2020-11-10 16:21:47 +08:00
sourcemap: true,
exports: 'auto',
},
{
name,
file: path.join(basePath, module),
format: 'es',
sourcemap: true,
2020-11-07 06:55:30 +08:00
},
],
2020-11-11 07:10:14 +08:00
plugins: [
2020-11-12 04:00:53 +08:00
autoExternal({
packagePath: path.join(basePath, 'package.json'),
}),
2020-11-11 17:00:13 +08:00
...basePlugins,
2020-11-11 07:10:14 +08:00
typescript({
tsconfig: fs.existsSync(`${basePath}/tsconfig.json`)
? `${basePath}/tsconfig.json`
: 'tsconfig.json',
2020-11-11 07:10:14 +08:00
tsconfigOverride: {
compilerOptions: {
declaration: true,
paths: {
2020-11-16 22:56:32 +08:00
'@tiptap/*': ['packages/*/src'],
2020-11-11 07:10:14 +08:00
},
},
include: fs.existsSync(`${basePath}/tsconfig.json`)
? []
: null,
2020-11-11 07:10:14 +08:00
},
}),
],
2020-11-07 06:55:30 +08:00
})
})
return config
}
2020-11-10 16:21:47 +08:00
export default build