From b27cb480bca24c0bff732370d6c2bfce4f894caa Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 5 Feb 2016 20:29:33 +0000 Subject: [PATCH] Add ES Modules build --- .babelrc | 12 +++++++++--- .gitignore | 1 + .travis.yml | 2 +- package.json | 24 +++++++++++++----------- prepublish.js | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.babelrc b/.babelrc index 3846ee396f..bb15be885b 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,5 @@ { - plugins: [ + "plugins": [ ["transform-es2015-template-literals", { "loose": true }], "transform-es2015-literals", "transform-es2015-function-name", @@ -17,7 +17,13 @@ "transform-es2015-parameters", ["transform-es2015-destructuring", { "loose": true }], "transform-es2015-block-scoping", - ["transform-es2015-modules-commonjs", { "loose": true }], "transform-object-rest-spread" - ] + ], + "env": { + "commonjs": { + "plugins": [ + ["transform-es2015-modules-commonjs", { "loose": true }] + ] + } + } } diff --git a/.gitignore b/.gitignore index 0aac31d53c..48a5a336d1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ node_modules dist lib +es coverage _book diff --git a/.travis.yml b/.travis.yml index 769077350b..6754346b8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ node_js: - "4" - "5" script: - - npm run check:lib + - npm run check:src - npm run build - npm run check:examples branches: diff --git a/package.json b/package.json index edadb6eaed..022f2fd29b 100644 --- a/package.json +++ b/package.json @@ -3,27 +3,29 @@ "version": "3.2.1", "description": "Predictable state container for JavaScript apps", "main": "lib/index.js", - "jsnext:main": "src/index.js", + "jsnext:main": "es/index.js", "files": [ "dist", "lib", + "es", "src" ], "scripts": { "clean": "rimraf lib dist coverage", "lint": "eslint src test examples", - "test": "mocha --compilers js:babel-register --recursive", + "test": "cross-env BABEL_ENV=commonjs mocha --compilers js:babel-register --recursive", "test:watch": "npm test -- --watch", - "test:cov": "babel-node $(npm bin)/isparta cover $(npm bin)/_mocha -- --recursive", - "test:examples": "babel-node examples/testAll.js", - "check:lib": "npm run lint && npm run test", + "test:cov": "cross-env BABEL_ENV=commonjs babel-node $(npm bin)/isparta cover $(npm bin)/_mocha -- --recursive", + "test:examples": "cross-env BABEL_ENV=commonjs babel-node examples/testAll.js", + "check:src": "npm run lint && npm run test", "check:examples": "npm run build:examples && npm run test:examples", - "build:lib": "babel src --out-dir lib", - "build:umd": "cross-env NODE_ENV=development webpack src/index.js dist/redux.js", - "build:umd:min": "cross-env NODE_ENV=production webpack src/index.js dist/redux.min.js", - "build:examples": "babel-node examples/buildAll.js", - "build": "npm run build:lib && npm run build:umd && npm run build:umd:min && node ./prepublish", - "prepublish": "npm run clean && npm run check:lib && npm run build", + "build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib", + "build:es": "cross-env BABEL_ENV=es babel src --out-dir es", + "build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack src/index.js dist/redux.js", + "build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack src/index.js dist/redux.min.js", + "build:examples": "cross-env BABEL_ENV=commonjs babel-node examples/buildAll.js", + "build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min && node ./prepublish", + "prepublish": "npm run clean && npm run check:src && npm run build", "docs:clean": "rimraf _book", "docs:prepare": "gitbook install", "docs:build": "npm run docs:prepare && gitbook build -g rackt/redux", diff --git a/prepublish.js b/prepublish.js index c614e538e7..f4639cf400 100644 --- a/prepublish.js +++ b/prepublish.js @@ -2,7 +2,7 @@ var glob = require('glob') var fs = require('fs') var es3ify = require('es3ify') -glob('./@(lib|dist)/**/*.js', function (err, files) { +glob('./@(lib|dist|es)/**/*.js', function (err, files) { if (err) { throw err }