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 2.4kb smaller
  • Loading branch information
realityking committed Feb 11, 2018
1 parent 422a6a0 commit 847ec8c
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 894 deletions.
14 changes: 6 additions & 8 deletions package.json
Expand Up @@ -31,21 +31,19 @@
},
"scripts": {
"test": "jest",
"umd": "NODE_ENV=development browserify index.js -t envify --standalone PropTypes -o prop-types.js",
"umd-min": "NODE_ENV=production browserify index.js -t 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": "yarn build"
},
"devDependencies": {
"babel-jest": "^19.0.0",
"babel-preset-react": "^6.24.1",
"browserify": "^14.3.0",
"bundle-collapser": "^1.2.1",
"envify": "^4.0.0",
"jest": "^19.0.2",
"react": "^15.5.1",
"uglifyify": "^3.0.4",
"uglifyjs": "^2.4.10"
"rollup": "^0.50.1",
"rollup-plugin-commonjs": "^8.3.0",
"rollup-plugin-node-resolve": "^3.0.2",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^3.0.0"
},
"browserify": {
"transform": [
Expand Down
43 changes: 43 additions & 0 deletions rollup.config.js
@@ -0,0 +1,43 @@
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';

function createConfig(file, opts = {}) {
const options = Object.assign({
production: false,
uglify: false
}, opts);

const config = {
input: 'index.js',
output: {
file: file,
format: 'umd',
name: 'PropTypes'
},
plugins: [
replace(stripEnvVariables(options.production)),
nodeResolve(),
commonjs()
]
};

if (options.uglify) {
config.plugins.push(uglify())
}

return config;
}

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

export default [
createConfig('prop-types.js'),
createConfig('prop-types.min.js', {uglify: true, production: true})
];

0 comments on commit 847ec8c

Please sign in to comment.