-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrollup.config.js
More file actions
57 lines (54 loc) · 1.49 KB
/
rollup.config.js
File metadata and controls
57 lines (54 loc) · 1.49 KB
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
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import uglify from '@lopatnov/rollup-plugin-uglify';
import { createRequire } from 'module';
const pkg = createRequire(import.meta.url)('./package.json');
// Treat anything declared as a dependency or peerDependency as external —
// including subpath imports like `@babel/runtime-corejs3/helpers/extends` —
// since they belong to the consumer's resolution graph, not our bundle.
const externals = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
const externalRegex = new RegExp(
'^(' + externals.map((d) => d.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')).join('|') + ')(/|$)',
);
export default {
input: 'src/index.js',
external: (id) => externalRegex.test(id),
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true,
}),
commonjs({
include: ['node_modules/**'],
}),
babel({
babelHelpers: 'runtime',
babelrc: true,
}),
uglify({
compress: {
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
},
output: {
comments: false,
},
}),
],
output: {
file: 'dist/index.js',
format: 'cjs',
exports: 'named',
sourcemap: true,
},
};