-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathrollup.config.js
More file actions
58 lines (56 loc) · 1.5 KB
/
rollup.config.js
File metadata and controls
58 lines (56 loc) · 1.5 KB
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
import { readFileSync, writeFileSync, chmodSync } from 'node:fs'
import replace from '@rollup/plugin-replace'
// import terser from '@rollup/plugin-terser'
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'))
export default {
input: {
index: 'src/index.js',
cli: 'src/cli.js'
},
output: [
{
dir: 'dist/cjs',
preserveModules: true,
// file: pkg.main,
format: 'cjs'
},
{
dir: 'dist/esm',
preserveModules: true,
// file: pkg.module,
format: 'es' // the preferred format
},
// {
// file: pkg.browser,
// format: 'iife',
// name: pkg.globalName // the global which can be used in a browser
// }
],
external: [
...Object.keys(pkg.dependencies || {})
],
plugins: [
replace({
__packageName__: pkg.name,
__packageVersion__: pkg.version,
__v_packageVersion__: `v${pkg.version}`,
preventAssignment: true
}),
// terser(), // minifies generated bundles
{
name: 'post-build-steps',
writeBundle () {
// Make CLI files executable
try { chmodSync('dist/esm/cli.js', 0o755) } catch {}
try { chmodSync('dist/cjs/cli.js', 0o755) } catch {}
// Write CJS package.json with name, version, and type
const cjsPkg = {
name: pkg.name,
version: pkg.version,
type: 'commonjs'
}
writeFileSync('dist/cjs/package.json', JSON.stringify(cjsPkg, null, 2) + '\n')
}
}
]
}