Skip to content

Commit

Permalink
Switch the build process to rollup.js
Browse files Browse the repository at this point in the history
Makes the minified UMD build 1.2kb smaller
  • Loading branch information
realityking committed Oct 4, 2020
1 parent 8f89a1c commit 8cb9bd7
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 943 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@
},
},
},
{
"files": "rollup.config.js",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module",
},
},
],
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,24 @@
"lint": "eslint .",
"test": "npm run tests-only",
"tests-only": "jest",
"umd": "NODE_ENV=development browserify index.js -t loose-envify --standalone PropTypes -o prop-types.js",
"umd-min": "NODE_ENV=production browserify index.js -t loose-envify -t uglifyify --standalone PropTypes -p bundle-collapser/plugin -o | uglifyjs --compress unused,dead_code -o prop-types.min.js",
"build": "yarn umd && yarn umd-min",
"build": "rollup -c",
"prepublish": "not-in-publish || yarn build"
},
"devDependencies": {
"babel-core": "6",
"babel-jest": "^19.0.0",
"babel-preset-react": "^6.24.1",
"browserify": "^16.5.0",
"bundle-collapser": "^1.3.0",
"eslint": "^6.3.0",
"in-publish": "^2.0.0",
"jest": "^19.0.2",
"loose-envify": "^1.4.0",
"react": "^15.5.4",
"uglifyify": "^5.0.2",
"uglifyjs": "^2.4.11"
"rollup": "^1.32.1",
"rollup-plugin-babel": "3",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^2.1.1",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.4"
},
"browserify": {
"transform": [
Expand Down
48 changes: 48 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import replace from 'rollup-plugin-replace';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import {uglify} from 'rollup-plugin-uglify';
import babel from 'rollup-plugin-babel';

function stripEnvVariables(env) {
return {
__DEV__: env === 'production' ? 'false' : 'true',
'process.env.NODE_ENV': `'${env}'`,
};
}

export default [
{
input: 'index.js',
output: {
file: 'prop-types.js',
format: 'umd',
name: 'PropTypes'
},
plugins: [
babel({
exclude: 'node_modules/**'
}),
replace(stripEnvVariables('development')),
nodeResolve(),
commonjs()
]
},
{
input: 'index.js',
output: {
file: 'prop-types.min.js',
format: 'umd',
name: 'PropTypes'
},
plugins: [
babel({
exclude: 'node_modules/**'
}),
replace(stripEnvVariables('production')),
nodeResolve(),
commonjs(),
uglify()
]
}
];

0 comments on commit 8cb9bd7

Please sign in to comment.