forked from rei/rei-cedar-vue-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
63 lines (55 loc) · 1.64 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
import process from 'process';
import plugins from './build/rollup-plugins';
import defaults from './build/rollup-defaults';
import packageJson from './package.json';
const env = process.env.NODE_ENV;
const babelEnv = process.env.BABEL_ENV;
const { dependencies = {}, peerDependencies = {} } = packageJson;
let externals = Object.keys({
...dependencies,
...peerDependencies,
});
if (babelEnv === 'cjs') {
// don't externalize ES modules in CJS build,
// these libraries may not have CJS exports and tools like @rei/vunit
// may throw an error when trying to consume their ESM output
externals = externals.filter((x) => x !== 'lodash-es' && x !== 'clsx' && x !== '@rei/cdr-tokens');
}
const externalFn = (id) => externals.some((dep) => dep === id || id.startsWith(`${dep}/`));
const ext = babelEnv === 'cjs' ? 'js' : 'mjs';
const config = [
{
input: 'src/main.js',
output: [
{
file: `dist/cedar.${ext}`,
format: babelEnv,
assetFileNames: "[name].[ext]"
},
],
plugins,
external: env === 'prod' ? externalFn : undefined,
...defaults,
},
];
if (env === 'prod' && babelEnv === 'esm') {
config.push(
{
input: 'src/index.js',
output: [
{
dir: 'dist/lib',
format: 'esm',
entryFileNames: '[name].mjs',
},
],
plugins: [
...plugins,
],
external: env === 'prod' ? externalFn : undefined,
preserveModules: true, // preserveModules is necessary for tree shaking to work as it compiles each file in cedar separately rather than building one large file
...defaults,
},
);
}
export default config;