Skip to content

Commit

Permalink
Add support for commonjs + umd + es using babel and rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Bouius committed May 26, 2017
1 parent ff9d5d9 commit e5b82a0
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 23 deletions.
19 changes: 15 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
{
"presets": [
"es2015",
["es2015", { "modules": false }],
"react"
],
"plugins": [
"transform-runtime",
"transform-class-properties",
"babel-plugin-transform-object-rest-spread"
]
"transform-object-rest-spread"
],
"env": {
"commonjs": {
"plugins": [
["transform-es2015-modules-commonjs", { "loose": true }]
]
},
"rollup": {
"plugins": [
"external-helpers"
]
}
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
es
lib
dist
node_modules
*.log
1 change: 0 additions & 1 deletion index.js

This file was deleted.

29 changes: 21 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "react-themed",
"description": "A simple theme provider and composition utility for react applications.",
"version": "3.0.0",
"main": "index.js",
"main": "./lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"license": "MIT",
"homepage": "https://github.com/aribouius/react-themed",
"repository": {
Expand All @@ -13,19 +15,26 @@
"url": "https://github.com/aribouius/react-themed/issues"
},
"scripts": {
"clean": "rm -rf lib",
"build": "babel -d lib src",
"build:watch": "yarn run build -- --watch",
"test": "mocha --compilers js:babel-core/register --recursive",
"clean": "rm -rf lib && rm -rf es && rm -rf dist",
"build": "yarn run build:es && yarn run build:commonjs && yarn run build:umd && yarn run build:umd:min",
"build:es": "BABEL_ENV=es babel -d es src",
"build:commonjs": "BABEL_ENV=commonjs babel -d lib src",
"build:umd": "BABEL_ENV=rollup NODE_ENV=development rollup -c -o dist/react-themed.js",
"build:umd:min": "BABEL_ENV=rollup NODE_ENV=production rollup -c -o dist/react-themed.min.js",
"build:watch": "yarn run build:es -- --watch",
"test": "BABEL_ENV=commonjs mocha --compilers js:babel-core/register --recursive",
"test:watch": "yarn run test -- --watch",
"lint": "eslint src",
"lint:fix": "yarn run lint -- --fix"
"lint:fix": "yarn run lint -- --fix",
"prepublish": "npm run clean && npm run build"
},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-core": "^6.24.0",
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.0",
Expand All @@ -43,10 +52,14 @@
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.4.2",
"react-test-renderer": "^15.5.4",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^2.0.1",
"sinon": "^2.1.0"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"hoist-non-react-statics": "^1.2.0",
"prop-types": "^15.5.8"
},
Expand Down
38 changes: 38 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import babel from 'rollup-plugin-babel'
import uglify from 'rollup-plugin-uglify'
import commonjs from 'rollup-plugin-commonjs'
import nodeResolve from 'rollup-plugin-node-resolve'

const env = process.env.NODE_ENV

const config = {
entry: 'src/index.js',
moduleName: 'ReactThemed',
format: 'umd',
external: [
'react',
],
globals: {
'react': 'React',
},
plugins: [
nodeResolve(),
babel({ exclude: '**/node_modules/**' }),
commonjs(),
],
}

if (env === 'production') {
config.plugins.push(
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false
}
})
)
}

export default config
119 changes: 109 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ acorn@^3.0.4:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^4.0.4:
acorn@^4.0.1, acorn@^4.0.4:
version "4.0.13"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"

Expand Down Expand Up @@ -189,7 +189,7 @@ babel-code-frame@^6.16.0, babel-code-frame@^6.22.0:
esutils "^2.0.2"
js-tokens "^3.0.0"

babel-core@^6.24.0, babel-core@^6.24.1:
babel-core@6, babel-core@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.24.1.tgz#8c428564dce1e1f41fb337ec34f4c3b022b5ad83"
dependencies:
Expand Down Expand Up @@ -330,6 +330,12 @@ babel-plugin-check-es2015-constants@^6.22.0:
dependencies:
babel-runtime "^6.22.0"

babel-plugin-external-helpers@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-external-helpers/-/babel-plugin-external-helpers-6.22.0.tgz#2285f48b02bd5dede85175caf8c62e86adccefa1"
dependencies:
babel-runtime "^6.22.0"

babel-plugin-syntax-class-properties@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz#d7eb23b79a317f8543962c505b827c7d6cac27de"
Expand Down Expand Up @@ -377,7 +383,7 @@ babel-plugin-transform-es2015-block-scoping@^6.24.1:
babel-types "^6.24.1"
lodash "^4.2.0"

babel-plugin-transform-es2015-classes@^6.24.1:
babel-plugin-transform-es2015-classes@^6.24.1, babel-plugin-transform-es2015-classes@^6.9.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.24.1.tgz#5a4c58a50c9c9461e564b4b2a3bfabc97a2584db"
dependencies:
Expand Down Expand Up @@ -650,7 +656,7 @@ babel-register@^6.24.1:
mkdirp "^0.5.1"
source-map-support "^0.4.2"

babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.23.0:
babel-runtime@^6.18.0, babel-runtime@^6.22.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b"
dependencies:
Expand Down Expand Up @@ -739,6 +745,12 @@ braces@^1.8.2:
preserve "^0.2.0"
repeat-element "^1.1.2"

browser-resolve@^1.11.0:
version "1.11.2"
resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.2.tgz#8ff09b0a2c421718a1051c260b32e48f442938ce"
dependencies:
resolve "1.1.7"

[email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f"
Expand All @@ -747,7 +759,7 @@ buffer-shims@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51"

builtin-modules@^1.0.0, builtin-modules@^1.1.1:
builtin-modules@^1.0.0, builtin-modules@^1.1.0, builtin-modules@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"

Expand Down Expand Up @@ -847,7 +859,7 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
dependencies:
delayed-stream "~1.0.0"

[email protected], commander@^2.8.1:
[email protected], commander@^2.8.1, commander@~2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
dependencies:
Expand Down Expand Up @@ -1299,6 +1311,14 @@ estraverse@~4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.1.1.tgz#f6caca728933a850ef90661d0e17982ba47111a2"

estree-walker@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.2.1.tgz#bdafe8095383d8414d5dc2ecf4c9173b6db9412e"

estree-walker@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.3.1.tgz#e6b1a51cf7292524e7237c312e5fe6660c1ce1aa"

esutils@^2.0.0, esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
Expand Down Expand Up @@ -1780,6 +1800,10 @@ is-glob@^2.0.0, is-glob@^2.0.1:
dependencies:
is-extglob "^1.0.0"

is-module@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591"

is-my-json-valid@^2.10.0:
version "2.16.0"
resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz#f079dd9bfdae65ee2038aae8acbc86ab109e3693"
Expand Down Expand Up @@ -2118,7 +2142,13 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
dependencies:
js-tokens "^3.0.0"

micromatch@^2.1.5:
magic-string@^0.19.0:
version "0.19.1"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.19.1.tgz#14d768013caf2ec8fdea16a49af82fc377e75201"
dependencies:
vlq "^0.2.1"

micromatch@^2.1.5, micromatch@^2.3.11:
version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
dependencies:
Expand Down Expand Up @@ -2696,7 +2726,11 @@ resolve-from@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"

resolve@^1.1.6:
[email protected]:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

resolve@^1.1.6, resolve@^1.1.7:
version "1.3.3"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.3.tgz#655907c3469a8680dc2de3a275a8fdd69691f0e5"
dependencies:
Expand All @@ -2715,6 +2749,60 @@ rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.6.1:
dependencies:
glob "^7.0.5"

rollup-plugin-babel@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-2.7.1.tgz#16528197b0f938a1536f44683c7a93d573182f57"
dependencies:
babel-core "6"
babel-plugin-transform-es2015-classes "^6.9.0"
object-assign "^4.1.0"
rollup-pluginutils "^1.5.0"

rollup-plugin-commonjs@^8.0.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-8.0.2.tgz#98b1589bfe32a6c0f67790b60c0b499972afed89"
dependencies:
acorn "^4.0.1"
estree-walker "^0.3.0"
magic-string "^0.19.0"
resolve "^1.1.7"
rollup-pluginutils "^2.0.1"

rollup-plugin-node-resolve@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.0.0.tgz#8b897c4c3030d5001277b0514b25d2ca09683ee0"
dependencies:
browser-resolve "^1.11.0"
builtin-modules "^1.1.0"
is-module "^1.0.0"
resolve "^1.1.6"

rollup-plugin-uglify@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-2.0.1.tgz#67b37ad1efdafbd83af4c36b40c189ee4866c969"
dependencies:
uglify-js "^3.0.9"

rollup-pluginutils@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408"
dependencies:
estree-walker "^0.2.1"
minimatch "^3.0.2"

rollup-pluginutils@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.0.1.tgz#7ec95b3573f6543a46a6461bd9a7c544525d0fc0"
dependencies:
estree-walker "^0.3.0"
micromatch "^2.3.11"

rollup@^0.41.6:
version "0.41.6"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.41.6.tgz#e0d05497877a398c104d816d2733a718a7a94e2a"
dependencies:
source-map-support "^0.4.0"

run-async@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-0.1.0.tgz#c8ad4a5e110661e402a7d21b530e009f25f8e389"
Expand Down Expand Up @@ -2792,13 +2880,13 @@ [email protected]:
dependencies:
hoek "2.x.x"

source-map-support@^0.4.2:
source-map-support@^0.4.0, source-map-support@^0.4.2:
version "0.4.15"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.15.tgz#03202df65c06d2bd8c7ec2362a193056fef8d3b1"
dependencies:
source-map "^0.5.6"

source-map@^0.5.0, source-map@^0.5.6:
source-map@^0.5.0, source-map@^0.5.6, source-map@~0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

Expand Down Expand Up @@ -2996,6 +3084,13 @@ ua-parser-js@^0.7.9:
version "0.7.12"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"

uglify-js@^3.0.9:
version "3.0.11"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.0.11.tgz#81f594b9a24dad76e39da92f8f06e5b3bc8c2e11"
dependencies:
commander "~2.9.0"
source-map "~0.5.1"

uid-number@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
Expand Down Expand Up @@ -3041,6 +3136,10 @@ [email protected]:
dependencies:
extsprintf "1.0.2"

vlq@^0.2.1:
version "0.2.2"
resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.2.tgz#e316d5257b40b86bb43cb8d5fea5d7f54d6b0ca1"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
Expand Down

0 comments on commit e5b82a0

Please sign in to comment.