Skip to content

Commit

Permalink
refactor(bundle): remove d3-color via rollup alias
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Dec 16, 2021
1 parent efbdd70 commit 639aa1e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -45,6 +45,7 @@
"@babel/preset-env": "^7.16.4",
"@babel/preset-react": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@rollup/plugin-alias": "^3.1.8",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
Expand Down
4 changes: 4 additions & 0 deletions rollup.config.js
Expand Up @@ -4,6 +4,7 @@ import babel from '@rollup/plugin-babel';
import postcss from 'rollup-plugin-postcss';
import bundleSize from 'rollup-plugin-bundle-size';
import replace from '@rollup/plugin-replace';
import alias from '@rollup/plugin-alias';
import svgr from '@svgr/rollup';
import typescript from 'rollup-plugin-typescript2';
import { DEFAULT_EXTENSIONS as DEFAULT_BABEL_EXTENSIONS } from '@babel/core';
Expand Down Expand Up @@ -38,6 +39,9 @@ export const baseConfig = ({ mainFile = pkg.main, moduleFile = pkg.module, injec
},
],
plugins: [
alias({
entries: [{ find: 'd3-color', replacement: __dirname + '/src/d3-color-alias' }],
}),
replace({
__ENV__: JSON.stringify(processEnv),
__REACT_FLOW_VERSION__: JSON.stringify(pkg.version),
Expand Down
10 changes: 10 additions & 0 deletions src/d3-color-alias.js
@@ -0,0 +1,10 @@
// this helps us to reduce bundle size by ~10kb. d3-color is not used but can't be treeshaked in this case.

const obj = {};
export const rgb = {};
export const color = {};
export const hsl = {};
export const lab = {};
export const hcl = {};
export const cubehelix = {};
export default obj;

0 comments on commit 639aa1e

Please sign in to comment.