Skip to content

Commit

Permalink
Simplify rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Feb 11, 2019
1 parent 6285520 commit 9c397f8
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions rollup.config.js
Expand Up @@ -4,44 +4,45 @@ import commonjs from 'rollup-plugin-commonjs';
import {uglify} from 'rollup-plugin-uglify';
import babel from 'rollup-plugin-babel';

function createConfig(file, opts = {}) {
const options = Object.assign({
production: false,
uglify: false
}, opts);
function stripEnvVariables(env) {
return {
__DEV__: env === 'production' ? 'false' : 'true',
'process.env.NODE_ENV': `'${env}'`,
};
}

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

if (options.uglify) {
config.plugins.push(uglify())
},
{
input: 'index.js',
output: {
file: 'prop-types.min.js',
format: 'umd',
name: 'PropTypes'
},
plugins: [
babel({
exclude: 'node_modules/**'
}),
replace(stripEnvVariables('production')),
nodeResolve(),
commonjs(),
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 9c397f8

Please sign in to comment.