-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
rollup.config.mjs
102 lines (95 loc) · 2.76 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { createRequire } from 'node:module'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import url from '@rollup/plugin-url'
import license from 'rollup-plugin-license'
import postcss from 'rollup-plugin-postcss'
import { pug } from './scripts/rollup-pug.mjs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const require = createRequire(import.meta.url)
const { dependencies, name, version } = require('./package.json')
const external = (id) =>
Object.keys(dependencies).some(
(dep) => dep === id || id.startsWith(`${dep}/`)
)
const compact = !process.env.ROLLUP_WATCH
const plugins = (opts = {}) => [
json({ preferConst: true }),
alias({
entries: [{ find: 'jszip', replacement: 'jszip/dist/jszip.min.js' }],
}),
nodeResolve({
browser: !!opts.browser,
preferBuiltins: !opts.browser,
exportConditions: opts.browser ? [] : ['node'],
}),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'),
}),
commonjs(),
typescript({ noEmitOnError: false }),
postcss({ inject: false }),
pug(),
url({
sourceDir: path.join(__dirname, 'lib'),
limit: 30720,
}),
compact &&
terser({
keep_classnames: /^CLIError$/,
format: { comments: opts.license ? /^!!/ : 'some' },
ecma: 2019,
compress: { passes: 2 },
}),
opts.license &&
license({
thirdParty: {
output: path.join(__dirname, opts.license),
},
}),
]
const browser = (opts = {}) => ({
external,
plugins: plugins({ ...opts, browser: true }),
})
const cli = { external, plugins: plugins() }
export default [
{
...browser({ license: 'lib/bespoke.js.LICENSE.txt' }),
input: 'src/templates/bespoke.js',
output: {
compact,
file: 'lib/bespoke.js',
format: 'iife',
banner: `/*!! License: https://unpkg.com/${name}@${version}/lib/bespoke.js.LICENSE.txt */\n`,
},
},
{
...browser(),
input: 'src/templates/watch.js',
output: { compact, file: 'lib/watch.js', format: 'iife' },
},
{
...browser(),
input: 'src/server/server-index.js',
output: { compact, file: 'lib/server/server-index.js', format: 'iife' },
},
{
...cli,
input: [
'src/index.ts', // Node.js entrypoint
'src/marp-cli.ts', // CLI entrypoint
'src/patch.ts', // CLI patch
'src/prepare.ts', // CLI preparation
],
output: { compact, dir: 'lib', exports: 'named', format: 'cjs' },
},
]