tiptap/rollup.config.js

143 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-11-07 06:55:30 +08:00
import path from 'path'
import minimist from 'minimist'
import { getPackages } from '@lerna/project'
import filterPackages from '@lerna/filter-packages'
import batchPackages from '@lerna/batch-packages'
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'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
2020-11-10 19:43:09 +08:00
import vuePlugin from 'rollup-plugin-vue'
2020-11-07 06:55:30 +08:00
import babel from '@rollup/plugin-babel'
import { terser } from 'rollup-plugin-terser'
2020-11-10 16:21:47 +08:00
import sizes from '@atomico/rollup-plugin-sizes'
2020-11-12 04:00:53 +08:00
import autoExternal from 'rollup-plugin-auto-external'
2020-11-07 06:55:30 +08:00
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)
.filter(item => item.name !== '@tiptap/docs')
.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
2020-11-10 22:16:38 +08:00
const { scope, ignore, ci } = 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,
unpkg,
} = 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(),
2020-11-10 19:43:09 +08:00
vuePlugin(),
2020-11-10 16:21:47 +08:00
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({
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: null,
},
}),
],
2020-11-07 06:55:30 +08:00
})
2020-11-10 16:21:47 +08:00
2020-11-10 22:16:38 +08:00
if (!ci) {
config.push({
input,
output: [
{
name,
file: path.join(basePath, unpkg),
format: 'umd',
sourcemap: true,
globals: {
2020-11-11 21:15:32 +08:00
'@tiptap/core': '@tiptap/core',
2020-11-10 22:16:38 +08:00
vue: 'Vue',
},
2020-11-10 19:43:09 +08:00
},
2020-11-10 22:16:38 +08:00
],
external: [
2020-11-11 21:15:32 +08:00
'@tiptap/core',
2020-11-10 22:16:38 +08:00
'vue',
],
plugins: [
2020-11-11 17:00:13 +08:00
...basePlugins,
2020-11-11 07:10:14 +08:00
typescript({
tsconfigOverride: {
compilerOptions: {
paths: {
2020-11-16 22:56:32 +08:00
'@tiptap/*': ['packages/*/src'],
2020-11-11 07:10:14 +08:00
},
},
},
}),
2020-11-10 22:16:38 +08:00
terser(),
],
})
}
2020-11-07 06:55:30 +08:00
})
return config
}
2020-11-10 16:21:47 +08:00
export default build