Skip to content

Commit

Permalink
Add ES modules build
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Feb 17, 2017
1 parent 191dd35 commit a85688e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -1 +1,7 @@
es
node_modules
umd
/*.js
!karma.conf.js
!tests.webpack.js
!webpack.config.js
2 changes: 1 addition & 1 deletion modules/.babelrc
@@ -1,6 +1,6 @@
{
"presets": [
[ "es2015", { "loose": true } ],
"../tools/es2015-preset",
"stage-1"
],
"plugins": [
Expand Down
13 changes: 5 additions & 8 deletions package.json
Expand Up @@ -7,14 +7,11 @@
"license": "MIT",
"scripts": {
"start": "webpack-dev-server -d --content-base ./ --history-api-fallback --inline modules/index.js",
"build-lib": "babel ./modules -d . --ignore '__tests__'",
"build-umd": "webpack modules/index.js umd/history.js",
"build-min": "webpack -p modules/index.js umd/history.min.js",
"build": "node ./scripts/build.js",
"release": "node ./scripts/release.js",
"prepublish": "node ./scripts/build.js",
"test": "npm run lint && karma start",
"lint": "eslint modules"
"build": "node ./tools/build.js",
"prepublish": "node ./tools/build.js",
"release": "node ./tools/release.js",
"lint": "eslint modules",
"test": "karma start --single-run"
},
"dependencies": {
"invariant": "^2.2.1",
Expand Down
25 changes: 0 additions & 25 deletions scripts/build.js

This file was deleted.

44 changes: 44 additions & 0 deletions tools/build.js
@@ -0,0 +1,44 @@
const fs = require('fs')
const execSync = require('child_process').execSync
const inInstall = require('in-publish').inInstall
const prettyBytes = require('pretty-bytes')
const gzipSize = require('gzip-size')

if (inInstall())
process.exit(0)

const exec = (command, extraEnv) =>
execSync(command, {
stdio: 'inherit',
env: Object.assign({}, process.env, extraEnv)
})

console.log('Building CommonJS modules ...')

exec('babel modules -d . --ignore __tests__', {
BABEL_ENV: 'cjs'
})

console.log('\nBuilding ES modules ...')

exec('babel modules -d es --ignore __tests__', {
BABEL_ENV: 'es'
})

console.log('\nBuilding history.js ...')

exec('webpack modules/index.js umd/history.js', {
NODE_ENV: 'production'
})

console.log('\nBuilding history.min.js ...')

exec('webpack -p modules/index.js umd/history.min.js', {
NODE_ENV: 'production'
})

const size = gzipSize.sync(
fs.readFileSync('umd/history.min.js')
)

console.log('\ngzipped, the UMD build is %s', prettyBytes(size))
12 changes: 12 additions & 0 deletions tools/es2015-preset.js
@@ -0,0 +1,12 @@
const buildPreset = require('babel-preset-es2015').buildPreset

const BABEL_ENV = process.env.BABEL_ENV

module.exports = {
presets: [
[ buildPreset, {
loose: true,
modules: BABEL_ENV === 'es' ? false : 'commonjs'
} ]
]
}
File renamed without changes.

0 comments on commit a85688e

Please sign in to comment.