Skip to content

Commit

Permalink
fix: import only md5 hash from crypto-js (#1607)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeetiss authored Dec 18, 2021
1 parent e7a93bc commit a592e99
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-pears-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-pdf/pdfkit': patch
---

replaced `crypto-js` with `crypto-js/md5` to reduce bundle size
44 changes: 23 additions & 21 deletions packages/pdfkit/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import pkg from './package.json';

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

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

const getCJS = override => Object.assign({}, cjs, override);
Expand All @@ -31,70 +31,72 @@ const babelConfig = ({ browser }) => ({
modules: false,
...(browser
? { targets: { browsers: 'last 2 versions' } }
: { targets: { node: '12' } }),
},
],
],
: { targets: { node: '12' } })
}
]
]
});

const configBase = {
input: 'src/index.js',
plugins: [nodeResolve(), json()],
external: Object.keys(pkg.dependencies),
external: Object.keys(pkg.dependencies).map(dep =>
dep === 'crypto-js' ? 'crypto-js/md5' : dep
),
onwarn: (warning, rollupWarn) => {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
rollupWarn(warning);
}
},
}
};

const serverConfig = Object.assign({}, configBase, {
output: [
getESM({ file: 'lib/pdfkit.es.js' }),
getCJS({ file: 'lib/pdfkit.cjs.js' }),
getCJS({ file: 'lib/pdfkit.cjs.js' })
],
plugins: configBase.plugins.concat(
babel(babelConfig({ browser: false })),
replace({
BROWSER: JSON.stringify(false),
}),
BROWSER: JSON.stringify(false)
})
),
external: configBase.external.concat(['fs']),
external: configBase.external.concat(['fs'])
});

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

const browserConfig = Object.assign({}, configBase, {
output: [
getESM({ file: 'lib/pdfkit.browser.es.js' }),
getCJS({ file: 'lib/pdfkit.browser.cjs.js' }),
getCJS({ file: 'lib/pdfkit.browser.cjs.js' })
],
plugins: configBase.plugins.concat(
babel(babelConfig({ browser: true })),
replace({
BROWSER: JSON.stringify(true),
BROWSER: JSON.stringify(true)
}),
ignore(['fs']),
),
ignore(['fs'])
)
});

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

export default [
serverConfig,
serverProdConfig,
browserConfig,
browserProdConfig,
browserProdConfig
];
2 changes: 1 addition & 1 deletion packages/pdfkit/src/mixins/attachments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import CryptoJS from 'crypto-js';
import CryptoJS from 'crypto-js/md5';

export default {
/**
Expand Down

0 comments on commit a592e99

Please sign in to comment.