forked from commercetools/ui-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
106 lines (99 loc) · 2.82 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import fs from 'fs';
import path from 'path';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import babel from 'rollup-plugin-babel';
import cleanup from 'rollup-plugin-cleanup';
import replace from 'rollup-plugin-replace';
import readPkgUp from 'read-pkg-up';
const { packageJson: pkg } = readPkgUp.sync({
cwd: fs.realpathSync(process.cwd()),
});
// we don't want to bundle any external dependencies.
// therefore, here we add any "react-in" imports, so that
// we don't get unresolved depenency errors from rollup
// we also add the @emotion deps as they are already included in
// @emotion/core and @emotion/styled
const ignoredExternals = [
// reachInImports
'react-select/async-creatable',
'react-select/async',
'react-select/creatable',
'dom-helpers/scrollbarSize',
// lodash reachIns
'lodash/omit',
'lodash/isNil',
'lodash/has',
'lodash/has',
'lodash/pick',
'lodash/flatMap',
'lodash/sortBy',
'lodash/isEqual',
'lodash/uniq',
'lodash/memoize',
'lodash/uniqueId',
// others
'@emotion/css',
'@emotion/styled-base',
];
// NOTE: the order of the plugins is important!
const rollupPlugins = [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
'process.env.npm_package_version': JSON.stringify(
process.env.npm_package_version
),
}),
// See also https://medium.com/@kelin2025/so-you-wanna-use-es6-modules-714f48b3a953
// Transpile sources using our custom babel preset.
babel({
exclude: path.join(__dirname, '/node_modules/**'),
runtimeHelpers: true,
rootMode: 'upward',
}),
// To convert CJS modules to ES6
commonjs({
include: path.join(__dirname, '/node_modules/**'),
}),
// To convert JSON files to ES6
json(),
// To remove comments, trim trailing spaces, compact empty lines,
// and normalize line endings
cleanup(),
].filter(Boolean);
const deps = Object.keys(pkg.dependencies || {});
const peerDeps = Object.keys(pkg.peerDependencies || {});
const defaultExternal = deps.concat(peerDeps).concat(ignoredExternals);
const createConfig = (cliArgs) => {
return {
input: cliArgs.input,
external: defaultExternal,
treeshake: { moduleSideEffects: false },
onwarn(warning, warn) {
// skip certain warnings
if (
warning.code === 'UNUSED_EXTERNAL_IMPORT' &&
(warning.source === 'react' || warning.source === '@emotion/core')
)
return;
// always throw when unresolved import
if (warning.code === 'UNRESOLVED_IMPORT') {
throw new Error(warning.message);
}
// Use default for everything else
warn(warning);
},
output: [
{
file: pkg.main,
format: 'cjs',
},
{
file: pkg.module,
format: 'esm',
},
],
plugins: rollupPlugins,
};
};
export default createConfig;