forked from rei/rei-cedar-vue-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
68 lines (60 loc) · 1.62 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
import process from 'process';
import renameExtensions from '@betit/rollup-plugin-rename-extensions';
import plugins from './build/rollup-plugins';
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
// TODO: figure out config change needed in @rei/vunit
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,
},
];
if (env === 'prod' && babelEnv === 'esm') {
config.push(
{
input: 'src/index.js',
output: [
{
dir: 'dist/lib',
format: 'esm',
entryFileNames: '[name].js',
},
],
plugins: [
...plugins,
renameExtensions({
include: ['**/*.js', '**/*.jsx', '**/*.scss'],
mappings: {
'.js': '.mjs',
'.jsx': '.mjs',
'.scss': '.mjs',
},
}),
],
external: env === 'prod' ? externalFn : undefined,
preserveModules: true,
},
);
}
export default config;