forked from infctr/eslint-plugin-typescript-sort-keys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
45 lines (40 loc) · 1.16 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
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import assert from 'assert'
import fs from 'fs'
import path from 'path'
const minify = !!process.env.MINIFY
const config = JSON.parse(fs.readFileSync('./tsconfig.json', 'utf-8'))
assert(config)
const baseUrl = config.compilerOptions.baseUrl
const internalFolders = fs
.readdirSync(baseUrl, { withFileTypes: true })
.filter(dir => dir.isDirectory())
.map(dir => path.resolve(process.cwd(), baseUrl, dir.name))
const isExternal = id =>
!id.startsWith('.') &&
!id.startsWith('/') &&
!id.startsWith('\0') &&
!internalFolders.some(mapping => id.startsWith(mapping))
export default [
{
input: './src/index.ts',
external: isExternal,
output: [
{
dir: 'lib',
entryFileNames: '[name].cjs.js',
format: 'cjs',
},
{
dir: 'lib',
entryFileNames: '[name].mjs',
format: 'es',
},
],
plugins: [commonjs(), resolve(), typescript(), json(), minify && terser()],
},
]