-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
68 lines (64 loc) · 1.78 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 {readFileSync} from 'fs';
import * as path from 'path';
import {babel} from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import {externals} from 'rollup-plugin-node-externals';
const pkg = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url).pathname),
);
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
function generateConfig({output, targets}) {
return {
input: './src/index.ts',
plugins: [
externals({deps: true, packagePath: './package.json'}),
nodeResolve({extensions}),
commonjs(),
babel({
rootMode: 'upward',
extensions,
exclude: 'node_modules/**',
babelHelpers: 'bundled',
// Options that may be present on the `babelConfig` object but
// we want to override
envName: 'production',
// @ts-expect-error targets is a valid babel option but @types/babel__core doesn't know that yet
targets,
}),
],
output,
};
}
/** @type {import('rollup').RollupOptions} */
export default [
generateConfig({
targets: 'extends @shopify/browserslist-config, node 12.20',
output: [
{
format: 'cjs',
dir: path.dirname(pkg.main),
preserveModules: true,
entryFileNames: '[name][assetExtname].js',
exports: 'named',
},
{
format: 'esm',
dir: path.dirname(pkg.module),
preserveModules: true,
entryFileNames: '[name][assetExtname].js',
},
],
}),
generateConfig({
targets: 'last 1 chrome versions',
output: [
{
format: 'esm',
dir: path.dirname(pkg.esnext),
preserveModules: true,
entryFileNames: '[name][assetExtname].esnext',
},
],
}),
];