Skip to content

Commit edd5a46

Browse files
feat: compatibility with modern web bundlers and browsers (diegomura#1891)
Co-authored-by: diegomura <[email protected]>
1 parent 35e69bb commit edd5a46

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
"description": "React-pdf helper functions",
66
"author": "Diego Muracciole <[email protected]>",
77
"homepage": "https://github.com/diegomura/react-pdf#readme",
8-
"main": "lib/index.js",
8+
"main": "lib/index.cjs.js",
9+
"module": "lib/index.es.js",
910
"repository": {
1011
"type": "git",
1112
"url": "https://github.com/diegomura/react-pdf.git",
1213
"directory": "packages/fns"
1314
},
1415
"scripts": {
1516
"test": "jest",
16-
"build": "rimraf ./lib && babel src --out-dir lib",
17-
"watch": "rimraf ./lib && babel src --out-dir lib --watch"
17+
"build": "rimraf ./lib && rollup -c",
18+
"watch": "rimraf ./lib && rollup -c -w"
1819
},
1920
"files": [
2021
"lib"

rollup.config.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import babel from '@rollup/plugin-babel';
2+
import pkg from './package.json';
3+
4+
const cjs = {
5+
exports: 'named',
6+
format: 'cjs',
7+
};
8+
9+
const esm = {
10+
format: 'es',
11+
};
12+
13+
const getCJS = override => Object.assign({}, cjs, override);
14+
const getESM = override => Object.assign({}, esm, override);
15+
16+
const input = 'src/index.js';
17+
18+
const getExternal = () => [/@babel\/runtime/];
19+
20+
const getPlugins = () => [
21+
babel({
22+
babelrc: true,
23+
babelHelpers: 'runtime',
24+
exclude: 'node_modules/**',
25+
}),
26+
];
27+
28+
const config = {
29+
input,
30+
output: [
31+
getESM({ file: 'lib/index.es.js' }),
32+
getCJS({ file: 'lib/index.cjs.js' }),
33+
],
34+
external: getExternal(),
35+
plugins: getPlugins(),
36+
};
37+
38+
export default config;

0 commit comments

Comments
 (0)