-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
75 lines (70 loc) · 1.73 KB
/
rollup.config.js
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
import { babel } from '@rollup/plugin-babel'
import virtual from '@rollup/plugin-virtual'
import replace from '@rollup/plugin-replace'
import path from 'path'
import glob from 'glob'
import { terser } from 'rollup-plugin-terser'
// We create a number of virtual entry points that export all modules
// from the respective directories.
const entryPoints = [
'./src/index.js',
'./src/array.js',
'./src/map.js',
'./src/object.js',
'./src/set.js',
'./src/text.js',
].map((i) => path.resolve(__dirname, i))
const plugins = [
// Create a virtual entry points for each subdirectory.
virtual(
entryPoints.reduce((obj, e) => {
obj[e] = createEntryPoint(e)
return obj
}, {})
),
babel({ babelHelpers: 'bundled' }),
]
function createEntryPoint(file) {
const basename = path.basename(file, '.js')
const directory = path.resolve(
__dirname,
'src',
basename === 'index' ? '' : basename
)
return glob
.sync(path.join(directory, '*.js'))
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.map((f) => `export { ${path.basename(f, '.js')} } from '${f}'`)
.join('\n')
}
if (process.env.MINIFY != null) {
plugins.push(
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true,
}),
terser({
compress: { passes: 2, module: true, unsafe: true },
})
)
}
export default {
input: entryPoints,
output: [
{
dir: './dist',
chunkFileNames: 'shared.js',
externalLiveBindings: false,
entryFileNames: '[name].js',
preferConst: true,
format: 'cjs',
},
{
dir: './dist',
chunkFileNames: 'shared.mjs',
entryFileNames: `[name].mjs`,
format: 'es',
},
],
plugins,
}