-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
73 lines (67 loc) · 1.72 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
import fastGlob from 'fast-glob';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import path from 'path';
// Globs of JS entry points.
const entryPoints = fastGlob.sync(['js/es6/*.js']);
// Plugins are largely shared.
const basePlugins = env => {
const plugins = [
resolve(),
commonjs({
include: /node_modules/,
}),
// Weird node/esm issue..should be just be babel({...}).
babel.babel({
// Pass environment name to reference babel.config.js setup.
envName: env,
exclude: /core-js/,
babelHelpers: 'bundled',
}),
];
// Usually only minify for production.
// Extra terser options for module code.
if (env === 'module') {
plugins.push(terser({
ecma: 12,
keep_classnames: true,
}));
}
else {
plugins.push(terser());
}
return plugins;
};
// Config for esm files with chunks.
const moduleConfig = {
input: entryPoints,
output: {
dir: 'js/module',
format: 'esm',
chunkFileNames: 'chunks/[name]-[hash].js',
},
plugins: basePlugins('module'),
};
// Config for iife (nomodule) files.
const nomoduleConfig = file => ({
input: file,
output: {
dir: 'js/nomodule',
format: 'iife',
name: path.parse(file).name,
},
preserveEntrySignatures: false,
plugins: basePlugins('nomodule'),
});
// Build all configs.
const configs = [moduleConfig];
// Only build nomodule files for production to speed up dev.
if (process.env.NODE_ENV === 'production') {
// Each entryPoint needs it's own config.
entryPoints.forEach(file => {
configs.push(nomoduleConfig(file));
})
}
export default configs;