From 007120369ae9c2872edf807e65aa5f5905cc5f16 Mon Sep 17 00:00:00 2001 From: JP Date: Sun, 8 Oct 2017 15:59:12 +0100 Subject: [PATCH] update Rollup config --- .babelrc | 14 + .prettierrc | 5 + LICENSE | 2 +- package.json | 79 +- rollup.config.js | 76 +- src/Actions.js | 6 +- src/Checkbox.js | 24 +- src/Column.js | 4 +- src/Container.js | 4 +- src/Control.js | 10 +- src/Fieldset.js | 6 +- src/Form.js | 4 +- src/Grid.js | 4 +- src/Input.js | 8 +- src/Label.js | 4 +- src/Legend.js | 6 +- src/RadioButton.js | 14 +- src/Select.js | 17 +- src/Textarea.js | 8 +- src/index.js | 18 +- yarn.lock | 1726 ++++++++++++++++---------------------------- 21 files changed, 791 insertions(+), 1248 deletions(-) create mode 100644 .babelrc create mode 100644 .prettierrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..bdd0888 --- /dev/null +++ b/.babelrc @@ -0,0 +1,14 @@ +{ + "presets": [ + [ + "env", + { + "targets": { + "browsers": ["last 2 versions", "ie >= 9"] + }, + "modules": false + } + ], + "react" + ] +} diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..de27ac5 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "parser": "flow", + "semi": false, + "singleQuote": true +} diff --git a/LICENSE b/LICENSE index 6ae4bf9..3ea476e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016 TryKickoff +Copyright (c) 2017 TryKickoff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index beeef5b..5e62213 100644 --- a/package.json +++ b/package.json @@ -1,62 +1,53 @@ { "name": "@kickoff/react-components", - "version": "1.0.4", + "version": "1.0.5", "description": "React components for easy use of the Kickoff framework", - "main": "dist/kickoff-react-components.js", - "module": "dist/kickoff-react-components.mjs", - "jsnext:main": "dist/kickoff-react-components.mjs", + "main": "dist/cjs/kickoff-react-components", + "module": "dist/esm/kickoff-react-components", + "browser": "dist/umd/kickoff-react-components", + "dependencies": { + "react": "^16.0.0" + }, + "devDependencies": { + "babel-core": "^6.26.0", + "babel-plugin-external-helpers": "^6.22.0", + "babel-preset-env": "^1.6.0", + "babel-preset-react": "^6.24.1", + "cross-env": "^5.0.5", + "husky": "^0.14.3", + "lint-staged": "^4.2.3", + "prettier": "^1.7.3", + "rimraf": "^2.6.2", + "rollup": "^0.50.0", + "rollup-plugin-babel": "^3.0.2", + "rollup-plugin-commonjs": "^8.0.2", + "rollup-plugin-filesize": "^1.4.2", + "rollup-plugin-gzip": "^1.3.0", + "rollup-plugin-node-resolve": "^3.0.0", + "rollup-plugin-uglify": "^2.0.1", + "uglify-es": "^3.1.3" + }, "scripts": { - "prebuild": "rimraf dist", - "build": "rollup -c", - "watch": "rollup -c -w", - "lint": "standard | snazzy", - "lint:fix": "standard --fix", - "test": "echo \"Error: no test specified\" && exit 1" + "build": "rimraf dist && cross-env NODE_ENV=development rollup -c", + "build:prod": "rimraf dist && cross-env NODE_ENV=production rollup -c", + "watch": "rimraf dist && cross-env NODE_ENV=development rollup -c -w", + "lint": "prettier --write \"src/**/*.js\"", + "test": "echo \"Error: no test specified\" && exit 1", + "precommit": "lint-staged" }, "repository": { "type": "git", "url": "git+https://github.com/TryKickoff/react-components.git" }, - "keywords": [ - "⚽", - "kickoff", - "react" - ], + "keywords": ["⚽", "kickoff", "react"], "author": "JP Driver", "license": "MIT", "bugs": { "url": "https://github.com/TryKickoff/react-components/issues" }, "homepage": "https://github.com/TryKickoff/react-components#readme", - "files": [ - "src", - "dist" - ], - "devDependencies": { - "babel-eslint": "^7.1.1", - "babel-preset-es2015-rollup": "^3.0.0", - "babel-preset-react": "^6.24.1", - "lint-staged": "^4.0.2", - "rimraf": "^2.6.1", - "rollup": "^0.45.2", - "rollup-plugin-babel": "^2.7.1", - "rollup-plugin-uglify": "^2.0.1", - "rollup-watch": "^4.3.1", - "snazzy": "^7.0.0", - "standard": "^10.0.2", - "uglify-es": "^3.0.27" - }, - "dependencies": { - "react": "^15.6.1" - }, - "standard": { - "parser": "babel-eslint", - "ignore": [ - "dist", - "node_modules" - ] - }, + "files": ["dist"], "lint-staged": { - "*.js": "standard --fix" + "*.{js,css}": ["prettier --write", "git add"] } } diff --git a/rollup.config.js b/rollup.config.js index 71acb12..0fbad99 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,35 +1,53 @@ +import resolve from 'rollup-plugin-node-resolve' +import commonjs from 'rollup-plugin-commonjs' import babel from 'rollup-plugin-babel' import uglify from 'rollup-plugin-uglify' import { minify } from 'uglify-es' +import gzip from 'rollup-plugin-gzip' +import filesize from 'rollup-plugin-filesize' +import pkg from './package.json' -let pkg = require('./package.json') -let external = Object.keys(pkg.dependencies) +const NODE_ENV = process.env.NODE_ENV +const isProductionBuild = NODE_ENV === 'production' +const jsFile = `.${NODE_ENV}.js` -export default { - entry: 'src/index.js', - plugins: [ - babel({ - babelrc: false, - exclude: 'node_modules', - presets: [ 'es2015-rollup', 'react' ] - }), - uglify({}, minify) - ], - external: external, - globals: { - 'react': 'React' - }, - targets: [ - { - dest: pkg.main, - format: 'umd', - moduleName: 'KickoffReactComponents', - sourceMap: true +const plugins = [ + babel({ + exclude: ['node_modules/**'], + plugins: ['external-helpers'] + }), + isProductionBuild && uglify({}, minify), + isProductionBuild && gzip(), + filesize() +] + +export default [ + // browser-friendly UMD build + { + input: 'src/index.js', + external: Object.keys(pkg.dependencies), + globals: { + react: 'React' }, - { - dest: pkg.module, - format: 'es', - sourceMap: true - } - ] -} + name: 'KickoffReactComponents', + output: { file: pkg.browser + jsFile, format: 'umd' }, + sourcemap: isProductionBuild, + plugins: [resolve(), commonjs(), ...plugins] + }, + + // CommonJS (for Node) and ES module (for bundlers) build. + // (We could have three entries in the configuration array + // instead of two, but it's quicker to generate multiple + // builds from a single configuration where possible, using + // the `output` option which can specify `file` and `format`) + { + input: 'src/index.js', + external: Object.keys(pkg.dependencies), + output: [ + { file: pkg.main + jsFile, format: 'cjs' }, + { file: pkg.module + jsFile, format: 'es' } + ], + sourcemap: isProductionBuild, + plugins: plugins + } +] diff --git a/src/Actions.js b/src/Actions.js index 2c7e5a9..4367a62 100644 --- a/src/Actions.js +++ b/src/Actions.js @@ -1,7 +1,7 @@ import React from 'react' -const Actions = ({ children }) =>
- {children} -
+const Actions = ({ children }) => ( +
{children}
+) export default Actions diff --git a/src/Checkbox.js b/src/Checkbox.js index 0b781cc..766747f 100644 --- a/src/Checkbox.js +++ b/src/Checkbox.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' class Checkbox extends Component { - constructor (props) { + constructor(props) { super(props) this.state = { checked: props.checked || false @@ -10,21 +10,29 @@ class Checkbox extends Component { this.onChange = this.onChange.bind(this) } - onChange () { + onChange() { const checked = !this.state.checked this.setState({ checked }) } - render () { + render() { let className = 'control-indicator control-indicator--checkbox' if (this.props.tickbox) { className = 'control-indicator control-indicator--tickbox' } - return + return ( + + ) } } diff --git a/src/Column.js b/src/Column.js index 9c9127f..00b1663 100644 --- a/src/Column.js +++ b/src/Column.js @@ -11,9 +11,7 @@ const Column = ({ centered, children, mid, span }) => { if (centered) { className += ' g-col--centered' } - return
- {children} -
+ return
{children}
} export default Column diff --git a/src/Container.js b/src/Container.js index 76f596e..73a9330 100644 --- a/src/Container.js +++ b/src/Container.js @@ -9,9 +9,7 @@ const Container = ({ children, full, narrow, wide }) => { } else if (wide) { className += ' l.container--wide' } - return
- {children} -
+ return
{children}
} export default Container diff --git a/src/Control.js b/src/Control.js index a4e8e0c..fcf7054 100644 --- a/src/Control.js +++ b/src/Control.js @@ -11,10 +11,12 @@ const Control = ({ children, error, label, success, warning }) => { } else if (warning) { className += ' has-warning' } - return
- {label && } - {children} -
+ return ( +
+ {label && } + {children} +
+ ) } export default Control diff --git a/src/Fieldset.js b/src/Fieldset.js index 0ed2ac9..6e6f18e 100644 --- a/src/Fieldset.js +++ b/src/Fieldset.js @@ -1,7 +1,7 @@ import React from 'react' -const Fieldset = ({ children }) =>
- {children} -
+const Fieldset = ({ children }) => ( +
{children}
+) export default Fieldset diff --git a/src/Form.js b/src/Form.js index c277c29..3d22a9b 100644 --- a/src/Form.js +++ b/src/Form.js @@ -5,9 +5,7 @@ const Form = ({ children, horizontal }) => { if (horizontal) { className += ' form--horizontal' } - return
- {children} -
+ return
{children}
} export default Form diff --git a/src/Grid.js b/src/Grid.js index fcd265e..daae52b 100644 --- a/src/Grid.js +++ b/src/Grid.js @@ -12,9 +12,7 @@ const Grid = ({ children, gutter, scaled, stack }) => { } else if (stack) { className += ' g--stack' } - return
- {children} -
+ return
{children}
} export default Grid diff --git a/src/Input.js b/src/Input.js index 2ee01cc..de31016 100644 --- a/src/Input.js +++ b/src/Input.js @@ -1,7 +1,9 @@ import React from 'react' -const Input = (props) =>
- -
+const Input = props => ( +
+ +
+) export default Input diff --git a/src/Label.js b/src/Label.js index 4208145..b74b9ee 100644 --- a/src/Label.js +++ b/src/Label.js @@ -1,7 +1,5 @@ import React from 'react' -const Label = ({ children }) =>
- {children} -
+const Label = ({ children }) =>
{children}
export default Label diff --git a/src/Legend.js b/src/Legend.js index 8f17a95..4c14212 100644 --- a/src/Legend.js +++ b/src/Legend.js @@ -1,7 +1,7 @@ import React from 'react' -const Legend = ({ children }) =>
- {children} -
+const Legend = ({ children }) => ( +
{children}
+) export default Legend diff --git a/src/RadioButton.js b/src/RadioButton.js index d06dbb6..eaf7acb 100644 --- a/src/RadioButton.js +++ b/src/RadioButton.js @@ -1,12 +1,14 @@ import React, { Component } from 'react' class RadioButton extends Component { - render () { - return + render() { + return ( + + ) } } diff --git a/src/Select.js b/src/Select.js index 96c6b32..48a1545 100644 --- a/src/Select.js +++ b/src/Select.js @@ -1,9 +1,16 @@ import React from 'react' -const Select = ({ children, defaultValue, disabled, onChange }) =>
- -
+const Select = ({ children, defaultValue, disabled, onChange }) => ( +
+ +
+) export default Select diff --git a/src/Textarea.js b/src/Textarea.js index 76e8e4d..99c5ca4 100644 --- a/src/Textarea.js +++ b/src/Textarea.js @@ -1,7 +1,9 @@ import React from 'react' -const Textarea = (props) =>
-