Skip to content

Commit

Permalink
feat: build render package as ES module (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura authored Jun 4, 2022
1 parent 70c3c9f commit 810f459
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-mangos-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-pdf/render': patch
---

feat: build render package as ES module
7 changes: 4 additions & 3 deletions packages/render/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
"description": "A render engine for Node and the browser",
"author": "Diego Muracciole <diegomuracciole@gmail.com>",
"homepage": "https://github.com/diegomura/react-pdf#readme",
"main": "lib/index.js",
"main": "lib/index.cjs.js",
"module": "lib/index.es.js",
"repository": {
"type": "git",
"url": "https://github.com/diegomura/react-pdf.git",
"directory": "packages/render"
},
"scripts": {
"test": "jest",
"build": "rimraf ./lib && babel src --out-dir lib",
"watch": "rimraf ./lib && babel src --out-dir lib --watch"
"build": "rimraf ./lib && rollup -c",
"watch": "rimraf ./lib && rollup -c -w"
},
"dependencies": {
"@babel/runtime": "^7.16.4",
Expand Down
47 changes: 47 additions & 0 deletions packages/render/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json from '@rollup/plugin-json';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';

import pkg from './package.json';

const cjs = {
exports: 'named',
format: 'cjs',
};

const esm = {
format: 'es',
};

const getCJS = override => Object.assign({}, cjs, override);
const getESM = override => Object.assign({}, esm, override);

const configBase = {
input: 'src/index.js',
external: Object.keys(pkg.dependencies),
plugins: [
json(),
babel({
babelrc: true,
babelHelpers: 'runtime',
exclude: 'node_modules/**',
}),
],
};

const config = Object.assign({}, configBase, {
output: [
getESM({ file: 'lib/index.es.js' }),
getCJS({ file: 'lib/index.cjs.js' }),
],
});

const prodConfig = Object.assign({}, configBase, {
output: [
getESM({ file: 'lib/index.es.min.js' }),
getCJS({ file: 'lib/index.cjs.min.js' }),
],
plugins: configBase.plugins.concat(terser()),
});

export default [config, prodConfig];

0 comments on commit 810f459

Please sign in to comment.