From 0783fb1800b54ed8ca99885f314d3057abc6fcb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 8 Dec 2017 22:24:23 +0100 Subject: [PATCH] Added module entry point --- .babelrc | 15 ++------------- .babelrc.js | 27 +++++++++++++++++++++++++++ .gitignore | 1 + package.json | 28 +++++++++++++++++++++++----- yarn.lock | 13 ++++++++++++- 5 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 .babelrc.js diff --git a/.babelrc b/.babelrc index 22bde19..04d04f8 100644 --- a/.babelrc +++ b/.babelrc @@ -1,16 +1,5 @@ { "presets": [ - [ - "env", - { - "loose": true, - "targets": { - "browsers": ["last 2 versions", "ie >= 9"] - } - } - ], - "react", - "flow" - ], - "plugins": ["transform-class-properties", "add-module-exports"] + "./.babelrc.js" + ] } diff --git a/.babelrc.js b/.babelrc.js new file mode 100644 index 0000000..3abdefc --- /dev/null +++ b/.babelrc.js @@ -0,0 +1,27 @@ +const { BABEL_ENV, NODE_ENV } = process.env + +const modules = BABEL_ENV === 'cjs' || NODE_ENV === 'test' ? 'commonjs' : false + +const plugins = ['transform-class-properties'] + +if (modules === 'commonjs') { + plugins.push('add-module-exports') +} + +module.exports = { + presets: [ + [ + 'env', + { + loose: true, + modules, + targets: { + browsers: ['last 2 versions', 'ie >= 9'] + } + } + ], + 'react', + 'flow', + ], + plugins, +} diff --git a/.gitignore b/.gitignore index 18399c1..a76d3fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules *.log lib +es coverage .DS_Store examples/*/bundle.js diff --git a/package.json b/package.json index 1dae9dc..0af7177 100644 --- a/package.json +++ b/package.json @@ -3,16 +3,28 @@ "version": "0.1.2", "description": "Polyfill for the proposed React context API", "main": "lib/index.js", + "module": "es/index.js", "repository": "https://github.com/thejameskyle/create-react-context", "author": "James Kyle ", "license": "MIT", - "keywords": ["react", "context", "contextTypes", "polyfill", "ponyfill"], - "files": ["lib"], + "keywords": [ + "react", + "context", + "contextTypes", + "polyfill", + "ponyfill" + ], + "files": [ + "lib", + "es" + ], "scripts": { "test": "jest", "flow": "flow", "format": "prettier --write '**/*.{js,md,json,js.flow,d.ts}'", - "build": "babel src -d lib --copy-files --ignore __tests__", + "build": "npm run build:es && npm run build:cjs", + "build:es": "cross-env BABEL_ENV=es babel src -d es --copy-files --ignore __tests__", + "build:cjs": "cross-env BABEL_ENV=cjs babel src -d lib --copy-files --ignore __tests__", "prepublish": "yarn build", "commit": "lint-staged" }, @@ -27,6 +39,7 @@ "babel-preset-env": "^1.6.1", "babel-preset-flow": "^6.23.0", "babel-preset-react": "^6.24.1", + "cross-env": "^5.1.1", "enzyme": "^3.2.0", "enzyme-adapter-react-16": "^1.1.0", "enzyme-to-json": "^3.2.2", @@ -41,10 +54,15 @@ "react-dom": "^16.2.0" }, "lint-staged": { - "*.{js,md,json,js.flow,d.ts}": ["prettier --write", "git add"] + "*.{js,md,json,js.flow,d.ts}": [ + "prettier --write", + "git add" + ] }, "jest": { - "snapshotSerializers": ["enzyme-to-json/serializer"] + "snapshotSerializers": [ + "enzyme-to-json/serializer" + ] }, "dependencies": { "mitt": "^1.1.3" diff --git a/yarn.lock b/yarn.lock index 6910634..c344e53 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1047,7 +1047,14 @@ cosmiconfig@^3.1.0: parse-json "^3.0.0" require-from-string "^2.0.1" -cross-spawn@^5.0.1: +cross-env@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.1.1.tgz#b6d8ab97f304c0f71dae7277b75fe424c08dfa74" + dependencies: + cross-spawn "^5.1.0" + is-windows "^1.0.0" + +cross-spawn@^5.0.1, cross-spawn@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" dependencies: @@ -1956,6 +1963,10 @@ is-utf8@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" +is-windows@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.1.tgz#310db70f742d259a16a369202b51af84233310d9" + isarray@1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"