Skip to content

Commit d45a16a

Browse files
committed
Update build setup and a few modules
1 parent 7f54ed3 commit d45a16a

File tree

7 files changed

+1446
-78
lines changed

7 files changed

+1446
-78
lines changed

package.json

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,69 @@
11
{
22
"name": "react-scroll-trigger",
33
"version": "0.1.0",
4+
"license": "MIT",
45
"description": "React component tied to scroll events with callbacks for enter, exit and progress while scrolling through the viewport.",
5-
"keywords": [
6-
"react",
7-
"react-component",
8-
"scroll",
9-
"trigger"
6+
"repository": "ryanhefner/react-scroll-trigger",
7+
"author": "Ryan Hefner <[email protected]> (https://www.ryanhefner.com)",
8+
"files": [
9+
"index.js",
10+
"es",
11+
"umd"
1012
],
13+
"directories": {
14+
"lib": "/src"
15+
},
1116
"main": "index.js",
17+
"module": "es/index.js",
18+
"jsnext:main": "src/index.js",
1219
"scripts": {
13-
"compile": "babel -d ./ src/",
14-
"prepublish": "npm run compile",
20+
"clean": "rm -f index.js && rm -rf es && rm -rf umd",
21+
"prebuild": "npm run clean",
22+
"build": "node ./tools/build.js",
23+
"watch": "babel ./src -d . --ignore __tests__ --watch",
24+
"prepare": "npm run build",
25+
"prepublishOnly": "node ./tools/build.js",
26+
"push-release": "git push origin master && git push --tags",
1527
"test": "echo \"Error: no test specified\" && exit 1"
1628
},
17-
"repository": "[email protected]:ryanhefner/react-scroll-trigger.git",
18-
"author": "Ryan Hefner <[email protected]> (https://www.ryanhefner.com)",
19-
"license": "MIT",
20-
"devDependencies": {
21-
"babel-cli": "^6.24.1",
22-
"babel-plugin-transform-object-rest-spread": "^6.23.0",
23-
"babel-preset-latest": "^6.24.1",
24-
"babel-preset-react": "^6.24.1"
29+
"peerDependencies": {
30+
"react": ">=15"
2531
},
2632
"dependencies": {
2733
"clean-react-props": "^0.1.0",
28-
"lodash": "^4.17.4",
34+
"lodash.throttle": "^4.1.1",
2935
"prop-types": "^15.5.10",
30-
"react": "^15.6.1",
3136
"react-dom": "^15.6.1"
32-
}
37+
},
38+
"devDependencies": {
39+
"babel-cli": "^6.24.1",
40+
"babel-plugin-dev-expression": "^0.2.1",
41+
"babel-plugin-external-helpers": "^6.22.0",
42+
"babel-plugin-transform-object-rest-spread": "^6.23.0",
43+
"babel-plugin-transform-react-remove-prop-types": "^0.4.6",
44+
"babel-preset-latest": "^6.24.1",
45+
"babel-preset-react": "^6.24.1",
46+
"gzip-size": "^3.0.0",
47+
"jest": "^20.0.4",
48+
"pretty-bytes": "^4.0.2",
49+
"react": "^15.6.1",
50+
"rollup": "^0.45.2",
51+
"rollup-plugin-babel": "^2.7.1",
52+
"rollup-plugin-commonjs": "^8.0.2",
53+
"rollup-plugin-json": "^2.3.0",
54+
"rollup-plugin-node-resolve": "^3.0.0",
55+
"rollup-plugin-uglify": "^2.0.1",
56+
"rollup-watch": "^4.3.1"
57+
},
58+
"browserify": {
59+
"transform": [
60+
"loose-envify"
61+
]
62+
},
63+
"keywords": [
64+
"react",
65+
"react-component",
66+
"scroll",
67+
"trigger"
68+
]
3369
}

rollup.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import babel from 'rollup-plugin-babel';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import json from 'rollup-plugin-json';
4+
import resolve from 'rollup-plugin-node-resolve';
5+
import uglify from 'rollup-plugin-uglify';
6+
import pkg from './package.json';
7+
8+
const config = {
9+
entry: 'src/index.js',
10+
format: 'umd',
11+
moduleName: 'react-scroll-trigger',
12+
plugins: [
13+
babel({
14+
exclude: 'node_modules/**',
15+
}),
16+
resolve(),
17+
commonjs({
18+
include: /node_modules/,
19+
}),
20+
json(),
21+
],
22+
external: [
23+
'react',
24+
],
25+
globals: {
26+
'react': 'React',
27+
},
28+
dest: './index.js',
29+
banner: `/*! ${pkg.name} v${pkg.version} | (c) ${new Date().getFullYear()} Ryan Hefner | ${pkg.license} License | https://github.com/${pkg.repository} !*/`,
30+
footer: '/* follow me on Twitter! @ryanhefner */',
31+
};
32+
33+
if (process.env.NODE_ENV === 'production') {
34+
config.plugins.push(uglify());
35+
}
36+
37+
export default config;

src/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "../tools/babel-preset.js" ]
3+
}

src/index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
33
import ReactDOM from 'react-dom';
4-
import omit from 'lodash/omit';
5-
import throttle from 'lodash/throttle';
4+
import throttle from 'lodash.throttle';
5+
import cleanProps from 'clean-react-props';
66

77
class ScrollTrigger extends Component {
88

@@ -123,16 +123,9 @@ class ScrollTrigger extends Component {
123123
children,
124124
} = this.props;
125125

126-
const props = omit(this.props, [
127-
'onEnter',
128-
'onExit',
129-
'onProgress',
130-
'triggerOnLoad',
131-
]);
132-
133126
return (
134127
<div
135-
{...props}
128+
{...cleanProps(this.props)}
136129
ref={(element) => {
137130
this.element = element;
138131
}}

tools/babel-preset.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const BABEL_ENV = process.env.BABEL_ENV;
2+
const building = BABEL_ENV != undefined && BABEL_ENV !== 'cjs';
3+
4+
const plugins = [];
5+
6+
if (BABEL_ENV === 'umd') {
7+
plugins.push('external-helpers');
8+
}
9+
10+
if (process.env.NODE_ENV === 'production') {
11+
plugins.push(
12+
'dev-expression',
13+
'transform-react-remove-prop-types'
14+
);
15+
}
16+
17+
module.exports = {
18+
presets: [
19+
['latest', {
20+
'es2015': {
21+
'loose': true,
22+
'modules': building ? false : 'commonjs'
23+
}
24+
}],
25+
'react'
26+
],
27+
plugins: plugins
28+
};

tools/build.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const fs = require('fs');
2+
const execSync = require('child_process').execSync;
3+
const prettyBytes = require('pretty-bytes');
4+
const gzipSize = require('gzip-size');
5+
6+
const exec = (command, extraEnv) => {
7+
execSync(command, {
8+
stdio: 'inherit',
9+
env: Object.assign({}, process.env, extraEnv),
10+
});
11+
};
12+
13+
console.log('Building CommonJS modules ...');
14+
15+
exec('babel src -d . --ignore __tests__', {
16+
BABEL_ENV: 'cjs',
17+
});
18+
19+
console.log('\nBuilding ES modules ...');
20+
21+
exec('babel src -d es --ignore __tests__', {
22+
BABEL_ENV: 'es',
23+
});
24+
25+
console.log('\nBuilding react-scroll-trigger.js ...');
26+
27+
exec('rollup -c -f umd -o umd/react-scroll-trigger.js', {
28+
BABEL_ENV: 'umd',
29+
NODE_ENV: 'development',
30+
});
31+
32+
console.log('\nBuilding react-scroll-trigger.min.js ...');
33+
34+
exec('rollup -c -f umd -o umd/react-scroll-trigger.min.js', {
35+
BABEL_ENV: 'umd',
36+
NODE_ENV: 'production',
37+
});
38+
39+
const size = gzipSize.sync(
40+
fs.readFileSync('umd/react-scroll-trigger.min.js')
41+
);
42+
43+
console.log('\ngzipped, the UMD build is %s', prettyBytes(size));

0 commit comments

Comments
 (0)