Skip to content

Commit

Permalink
Simplified build setup a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jan 16, 2018
1 parent cfafab1 commit bb13f74
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 59 deletions.
4 changes: 3 additions & 1 deletion .babelrc.js
@@ -1,10 +1,12 @@
const { BABEL_ENV, NODE_ENV } = process.env;
const modules = BABEL_ENV === 'cjs' || NODE_ENV === 'test' ? 'commonjs' : false;
const loose = true;

module.exports = {
presets: [
['@babel/env', {
loose,
modules: false,
modules: modules,
exclude: ['transform-typeof-symbol'],
}],
],
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
node_modules
lib
es
dist/react-onclickoutside.es.js
dist/react-onclickoutside.cjs.js
2 changes: 1 addition & 1 deletion dist/react-onclickoutside.min.js

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

21 changes: 7 additions & 14 deletions package.json
Expand Up @@ -2,12 +2,10 @@
"name": "react-onclickoutside",
"version": "6.7.0",
"description": "An onClickOutside wrapper for React components",
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"main": "dist/react-onclickoutside.cjs.js",
"module": "dist/react-onclickoutside.es.js",
"jsnext:main": "dist/react-onclickoutside.es.js",
"files": [
"es",
"lib",
"dist"
],
"unpkg": "dist/react-onclickoutside.min.js",
Expand All @@ -31,16 +29,12 @@
"url": "https://github.com/Pomax/react-onclickoutside/issues"
},
"scripts": {
"clean": "rimraf es lib dist",
"clean": "rimraf dist",
"prebuild": "npm run clean",
"build": "run-p build:**",
"build:es": "cross-env BABEL_ENV=es rollup -c -i src/index.js -o es/index.js",
"build:cjs": "cross-env BABEL_ENV=cjs rollup -c -i src/index.js -o lib/index.js",
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c rollup.umd.config.js -i src/index.js -o dist/react-onclickoutside.js",
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c rollup.umd.config.js -i src/index.js -o dist/react-onclickoutside.min.js",
"build": "rollup -c",
"lint": "eslint src/*.js ./test",
"test": "run-s test:**",
"test:basic": "run-s lint build:cjs",
"test:basic": "run-s lint build",
"test:karma": "karma start test/karma.conf.js --single-run",
"test:nodom": "mocha test/no-dom-test.js",
"precommit": "npm test && lint-staged",
Expand All @@ -60,7 +54,6 @@
"babel-eslint": "^8.0.2",
"babel-loader": "8.0.0-beta.0",
"chai": "^4.1.2",
"cross-env": "^5.0.0",
"eslint": "^4.12.0",
"husky": "^0.14.3",
"karma": "^1.4.0",
Expand All @@ -79,7 +72,7 @@
"require-hijack": "^1.2.1",
"rimraf": "^2.6.2",
"rollup": "^0.52.0",
"rollup-plugin-babel": "^4.0.0-beta.0",
"rollup-plugin-babel": "4.0.0-beta.0",
"rollup-plugin-uglify": "^2.0.1",
"webpack": "^3.8.1"
},
Expand Down
68 changes: 56 additions & 12 deletions rollup.config.js
@@ -1,16 +1,60 @@
import babel from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify';
import pkg from './package.json';

var config = {
output: {
format: process.env.BABEL_ENV,
exports: 'named',
},
external: ['react', 'react-dom'],
plugins: [
babel({
exclude: 'node_modules/**',
}),
],
const mergeAll = objs => Object.assign({}, ...objs);

const commonPlugins = [
babel({
exclude: 'node_modules/**',
}),
];

const configBase = {
input: 'src/index.js',
external: Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {})),
plugins: commonPlugins,
};

export default config;
const devUmdConfig = mergeAll([
configBase,
{
output: {
file: pkg.unpkg.replace(/\.min\.js$/, '.js'),
format: 'umd',
name: 'onClickOutside',
exports: 'named',
},
globals: { react: 'React', 'react-dom': 'ReactDOM' },
external: Object.keys(pkg.peerDependencies || {}),
},
]);

const prodUmdConfig = mergeAll([
devUmdConfig,
{ output: mergeAll([devUmdConfig.output, { file: pkg.unpkg }]) },
{
plugins: devUmdConfig.plugins.concat(
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
})
),
},
]);

const webConfig = mergeAll([
configBase,
{
output: [
{ file: pkg.module, format: 'es' },
{ file: pkg.main, format: 'cjs', exports: 'named' }
],
},
]);

export default [devUmdConfig, prodUmdConfig, webConfig];
31 changes: 0 additions & 31 deletions rollup.umd.config.js

This file was deleted.

0 comments on commit bb13f74

Please sign in to comment.