Skip to content

Commit 6df72c3

Browse files
carlobeltramediegomura
authored andcommitted
Add node polyfills for unicode-properties package in the browser
1 parent 92f9c02 commit 6df72c3

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@react-pdf/unicode-properties",
3+
"version": "2.6.0",
4+
"license": "MIT",
5+
"description": "Provides fast access to unicode character properties",
6+
"author": "Devon Govett <devongovett@gmail.com>",
7+
"main": "lib/unicode-properties.cjs.js",
8+
"module": "lib/unicode-properties.es.js",
9+
"browser": {
10+
"lib/unicode-properties.cjs.js": "lib/unicode-properties.browser.cjs.js",
11+
"lib/unicode-properties.es.js": "lib/unicode-properties.browser.es.js"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/diegomura/react-pdf.git",
16+
"directory": "packages/unicode-properties"
17+
},
18+
"scripts": {
19+
"test": "jest",
20+
"build": "node generate.js && rollup -c",
21+
"watch": "node generate.js && rollup -c -w"
22+
},
23+
"dependencies": {
24+
"unicode-trie": "^0.3.0"
25+
},
26+
"devDependencies": {
27+
"codepoints": "^1.2.0"
28+
},
29+
"files": [
30+
"lib"
31+
]
32+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import json from '@rollup/plugin-json';
2+
import babel from '@rollup/plugin-babel';
3+
import nodePolyfills from 'rollup-plugin-polyfill-node';
4+
import pkg from './package.json';
5+
6+
const cjs = {
7+
exports: 'named',
8+
format: 'cjs',
9+
};
10+
11+
const esm = {
12+
format: 'es',
13+
};
14+
15+
const getCJS = override => Object.assign({}, cjs, override);
16+
const getESM = override => Object.assign({}, esm, override);
17+
18+
const input = 'index.js';
19+
20+
const babelConfig = ({ browser }) => ({
21+
babelrc: false,
22+
babelHelpers: 'runtime',
23+
exclude: 'node_modules/**',
24+
presets: [
25+
[
26+
'@babel/preset-env',
27+
{
28+
loose: true,
29+
modules: false,
30+
targets: { node: '12', browsers: 'last 2 versions' },
31+
},
32+
],
33+
],
34+
plugins: [['@babel/plugin-transform-runtime', { version: '^7.16.4' }]],
35+
});
36+
37+
const getExternal = () => [
38+
...(Object.keys(pkg.dependencies)),
39+
];
40+
41+
const getPlugins = ({ browser }) => [
42+
json(),
43+
babel(babelConfig({ browser })),
44+
...(browser ? [ nodePolyfills({ include: [ /unicode-properties\/index\.js/, /polyfill/ ] }) ] : []),
45+
];
46+
47+
const serverConfig = {
48+
input,
49+
output: [
50+
getESM({ file: 'lib/unicode-properties.es.js' }),
51+
getCJS({ file: 'lib/unicode-properties.cjs.js' }),
52+
],
53+
external: getExternal(),
54+
plugins: getPlugins({ browser: false }),
55+
};
56+
57+
const browserConfig = {
58+
input,
59+
output: [
60+
getESM({ file: 'lib/unicode-properties.browser.es.js' }),
61+
getCJS({ file: 'lib/unicode-properties.browser.cjs.js' }),
62+
],
63+
external: getExternal(),
64+
plugins: getPlugins({ browser: true }),
65+
};
66+
67+
export default [serverConfig, browserConfig];

0 commit comments

Comments
 (0)