Skip to content

Commit 568cad0

Browse files
committed
Add build scripts
1 parent 0b0e4da commit 568cad0

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
"es2015-loose",
4+
"stage-1",
5+
"react"
6+
],
7+
"plugins": [
8+
"babel-plugin-dev-expression"
9+
]
10+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
umd

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.babelrc
2+
.gitignore
3+
.npmignore
4+
modules
5+
node_modules
6+
scripts
7+
webpack.config.js

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,31 @@
44
"author": "Michael Jackson",
55
"license": "MIT",
66
"main": "index.js",
7+
"scripts": {
8+
"build": "node ./scripts/build.js",
9+
"build-cjs": "babel ./modules -d . --ignore '__tests__'",
10+
"build-umd": "webpack modules/index.js umd/react-broadcast.js",
11+
"build-min": "webpack -p modules/index.js umd/react-broadcast.min.js",
12+
"prepublish": "node ./scripts/build.js"
13+
},
714
"dependencies": {
815
"invariant": "^2.2.1"
916
},
1017
"peerDependencies": {
1118
"react": "15.x"
19+
},
20+
"devDependencies": {
21+
"babel-cli": "^6.16.0",
22+
"babel-core": "^6.16.0",
23+
"babel-loader": "^6.2.5",
24+
"babel-plugin-dev-expression": "^0.2.1",
25+
"babel-preset-es2015": "^6.16.0",
26+
"babel-preset-es2015-loose": "^8.0.0",
27+
"babel-preset-react": "^6.16.0",
28+
"babel-preset-stage-1": "^6.16.0",
29+
"gzip-size": "^3.0.0",
30+
"in-publish": "^2.0.0",
31+
"pretty-bytes": "^4.0.2",
32+
"webpack": "^1.13.2"
1233
}
1334
}

scripts/build.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const readFileSync = require('fs').readFileSync
2+
const execSync = require('child_process').execSync
3+
const inInstall = require('in-publish').inInstall
4+
const prettyBytes = require('pretty-bytes')
5+
const gzipSize = require('gzip-size')
6+
7+
if (inInstall())
8+
process.exit(0)
9+
10+
const exec = (command, env) =>
11+
execSync(command, { stdio: 'inherit', env })
12+
13+
const webpackEnv = Object.assign({}, process.env, {
14+
NODE_ENV: 'production'
15+
})
16+
17+
exec('npm run build-cjs')
18+
exec('npm run build-umd', webpackEnv)
19+
exec('npm run build-min', webpackEnv)
20+
21+
console.log(
22+
'\ngzipped, the UMD build is ' + prettyBytes(
23+
gzipSize.sync(readFileSync('umd/react-broadcast.min.js'))
24+
)
25+
)

webpack.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const webpack = require('webpack')
2+
3+
module.exports = {
4+
output: {
5+
library: 'ReactBroadcast',
6+
libraryTarget: 'umd'
7+
},
8+
9+
externals: {
10+
react: {
11+
root: 'React',
12+
commonjs2: 'react',
13+
commonjs: 'react',
14+
amd: 'react'
15+
}
16+
},
17+
18+
module: {
19+
loaders: [
20+
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' }
21+
]
22+
},
23+
24+
plugins: [
25+
new webpack.DefinePlugin({
26+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
27+
})
28+
]
29+
}

0 commit comments

Comments
 (0)