Skip to content

Commit b7f0c33

Browse files
committed
New build system for 2.0
1 parent 36d94f3 commit b7f0c33

File tree

9 files changed

+298
-417
lines changed

9 files changed

+298
-417
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
es
21
node_modules
2+
3+
cjs
4+
esm
35
umd
4-
/*.js
5-
!webpack.config.js

modules/.babelrc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
{
22
"presets": [
3-
"../tools/es2015-preset",
3+
[ "es2015", { "loose": true } ],
44
"stage-1",
55
"react"
6-
],
7-
"env": {
8-
"production": {
9-
"plugins": [
10-
"transform-react-remove-prop-types"
11-
]
12-
}
13-
}
6+
]
147
}

package.json

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
"repository": "ReactTraining/react-media",
66
"license": "MIT",
77
"author": "Michael Jackson",
8-
"files": ["Media.js", "es", "index.js", "umd"],
8+
"files": [
9+
"cjs",
10+
"esm",
11+
"umd"
12+
],
13+
"main": "cjs/react-media.js",
14+
"module": "esm/react-media.js",
15+
"unpkg": "umd/react-media.js",
916
"scripts": {
10-
"build": "node ./tools/build.js",
17+
"build": "node ./scripts/build.js",
1118
"clean": "git clean -fdX .",
12-
"prepublishOnly": "node ./tools/build.js",
13-
"release": "node ./tools/release.js",
19+
"prepublishOnly": "node ./scripts/build.js",
20+
"release": "node ./scripts/release.js",
1421
"lint": "eslint modules",
1522
"test": "jest"
1623
},
@@ -24,8 +31,9 @@
2431
"devDependencies": {
2532
"babel-cli": "^6.11.4",
2633
"babel-eslint": "^7.0.0",
27-
"babel-loader": "^6.2.4",
28-
"babel-plugin-transform-react-remove-prop-types": "^0.3.2",
34+
"babel-plugin-dev-expression": "^0.2.1",
35+
"babel-plugin-external-helpers": "^6.22.0",
36+
"babel-plugin-transform-react-remove-prop-types": "^0.4.12",
2937
"babel-preset-es2015": "^6.14.0",
3038
"babel-preset-react": "^6.11.1",
3139
"babel-preset-stage-1": "^6.5.0",
@@ -35,13 +43,26 @@
3543
"eslint-plugin-react": "^6.0.0",
3644
"gzip-size": "^3.0.0",
3745
"jest": "^20.0.4",
46+
"pascal-case": "^2.0.1",
3847
"pretty-bytes": "^4.0.2",
3948
"react": "^15.4.1 || ^0.14.7",
4049
"react-dom": "^15.3.0 || ^0.14.7",
4150
"readline-sync": "^1.4.4",
42-
"webpack": "^1.13.1"
51+
"rollup": "^0.53.4",
52+
"rollup-plugin-babel": "^3.0.3",
53+
"rollup-plugin-commonjs": "^8.2.6",
54+
"rollup-plugin-node-resolve": "^3.0.2",
55+
"rollup-plugin-replace": "^2.0.0",
56+
"rollup-plugin-uglify": "^2.0.1"
4357
},
44-
"keywords": ["react", "media", "media query", "query", "css", "responsive"],
58+
"keywords": [
59+
"react",
60+
"media",
61+
"media query",
62+
"query",
63+
"css",
64+
"responsive"
65+
],
4566
"prettier": {
4667
"printWidth": 100,
4768
"semi": false

scripts/build.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const fs = require("fs")
2+
const path = require("path")
3+
const execSync = require("child_process").execSync
4+
const prettyBytes = require("pretty-bytes")
5+
const pascalCase = require("pascal-case")
6+
const gzipSize = require("gzip-size")
7+
8+
process.chdir(path.resolve(__dirname, ".."))
9+
10+
const exec = (command, extraEnv) =>
11+
execSync(command, {
12+
stdio: "inherit",
13+
env: Object.assign({}, process.env, extraEnv)
14+
})
15+
16+
const packageName = require("../package").name
17+
18+
console.log("\nBuilding ES modules...")
19+
20+
exec(`rollup -c scripts/config.js -f es -o esm/${packageName}.js`)
21+
22+
console.log("\nBuilding CommonJS modules...")
23+
24+
exec(`rollup -c scripts/config.js -f cjs -o cjs/${packageName}.js`)
25+
26+
console.log("\nBuilding UMD modules...")
27+
28+
const varName = pascalCase(packageName)
29+
30+
exec(`rollup -c scripts/config.js -f umd -n ${varName} -o umd/${packageName}.js`, {
31+
BUILD_ENV: "development"
32+
})
33+
34+
exec(`rollup -c scripts/config.js -f umd -n ${varName} -o umd/${packageName}.min.js`, {
35+
BUILD_ENV: "production"
36+
})
37+
38+
console.log(
39+
"\nThe minified, gzipped UMD build is %s",
40+
prettyBytes(gzipSize.sync(fs.readFileSync(`umd/${packageName}.min.js`)))
41+
)

scripts/config.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const babel = require("rollup-plugin-babel")
2+
const commonjs = require("rollup-plugin-commonjs")
3+
const replace = require("rollup-plugin-replace")
4+
const resolve = require("rollup-plugin-node-resolve")
5+
const uglify = require("rollup-plugin-uglify")
6+
7+
const getPlugins = env => {
8+
const plugins = [resolve()]
9+
10+
if (env) {
11+
plugins.push(
12+
replace({
13+
"process.env.NODE_ENV": JSON.stringify(env)
14+
})
15+
)
16+
}
17+
18+
plugins.push(
19+
babel({
20+
exclude: "node_modules/**",
21+
babelrc: false,
22+
presets: [["es2015", { loose: true, modules: false }], "stage-1", "react"],
23+
plugins: ["external-helpers"].concat(
24+
env === "production" ? ["dev-expression", "transform-react-remove-prop-types"] : []
25+
)
26+
}),
27+
commonjs({
28+
include: /node_modules/
29+
})
30+
)
31+
32+
if (env === "production") {
33+
plugins.push(uglify())
34+
}
35+
36+
return plugins
37+
}
38+
39+
const config = {
40+
input: "modules/index.js",
41+
output: {
42+
globals: {
43+
react: "React"
44+
}
45+
},
46+
external: ["react"],
47+
plugins: getPlugins(process.env.BUILD_ENV)
48+
}
49+
50+
module.exports = config
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
const resolvePath = require('path').resolve
2-
const readFileSync = require('fs').readFileSync
3-
const execSync = require('child_process').execSync
4-
const prompt = require('readline-sync').question
1+
const fs = require("fs")
2+
const path = require("path")
3+
const execSync = require("child_process").execSync
4+
const prompt = require("readline-sync").question
55

6-
const exec = (command) =>
7-
execSync(command, { stdio: 'inherit' })
6+
process.chdir(path.resolve(__dirname, ".."))
87

9-
const getPackageVersion = () =>
10-
JSON.parse(readFileSync(resolvePath(__dirname, '../package.json'))).version
8+
const exec = command => execSync(command, { stdio: "inherit" })
119

12-
if (process.cwd() !== resolvePath(__dirname, '..')) {
13-
console.error('The release script must be run from the repo root')
14-
process.exit(1)
15-
}
10+
const getPackageVersion = () =>
11+
JSON.parse(fs.readFileSync(path.resolve(__dirname, "../package.json"))).version
1612

1713
// Get the next version, which may be specified as a semver
1814
// version number or anything `npm version` recognizes. This
1915
// is a "pre-release" if nextVersion is premajor, preminor,
2016
// prepatch, or prerelease
2117
const nextVersion = prompt(`Next version (current version is ${getPackageVersion()})? `)
22-
const isPrerelease = nextVersion.substr(0, 3) === 'pre' || nextVersion.indexOf('-') !== -1
18+
const isPrerelease = nextVersion.substr(0, 3) === "pre" || nextVersion.indexOf("-") !== -1
2319

2420
// 1) Make sure the tests pass
25-
exec('npm test')
21+
exec("npm test")
2622

2723
// 2) Increment the package version in package.json
2824
// 3) Create a new commit
@@ -31,7 +27,7 @@ exec(`npm version ${nextVersion} -m "Version %s"`)
3127

3228
// 5) Publish to npm. Use the "next" tag for pre-releases,
3329
// "latest" for all others
34-
exec(`npm publish --tag ${isPrerelease ? 'next' : 'latest'}`)
30+
exec(`npm publish --tag ${isPrerelease ? "next" : "latest"}`)
3531

3632
// 6) Push the v* tag to GitHub
3733
exec(`git push -f origin v${getPackageVersion()}`)

tools/build.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

tools/es2015-preset.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)