Skip to content

Commit 23245d7

Browse files
authored
Merge pull request #14 from mohsinulhaq/rollup-build
incorporate rollup into build system
2 parents 6c58a14 + 32723e7 commit 23245d7

File tree

8 files changed

+464
-56
lines changed

8 files changed

+464
-56
lines changed

.size-snapshot.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"dist/index.js": {
3+
"bundled": 6280,
4+
"minified": 6280,
5+
"gzipped": 1974
6+
},
7+
"lib/cjs/index.js": {
8+
"bundled": 11982,
9+
"minified": 6536,
10+
"gzipped": 1904
11+
},
12+
"lib/esm/index.js": {
13+
"bundled": 11940,
14+
"minified": 6518,
15+
"gzipped": 1906,
16+
"treeshaked": {
17+
"rollup": {
18+
"code": 6028,
19+
"import_statements": 361
20+
},
21+
"webpack": {
22+
"code": 7329
23+
}
24+
}
25+
}
26+
}

babel.config.js

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
1-
const presets = [
2-
[
3-
'@babel/env',
4-
{
5-
useBuiltIns: 'usage'
6-
}
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/env',
5+
{
6+
modules: false,
7+
loose: true
8+
}
9+
],
10+
'@babel/react'
711
],
8-
[
9-
'@babel/react',
10-
{
11-
useBuiltIns: true
12-
}
13-
]
14-
];
15-
16-
const plugins = [
17-
'@babel/plugin-transform-runtime',
18-
'@babel/plugin-proposal-class-properties'
19-
];
20-
21-
const env = {
22-
esm: {
23-
presets: [
24-
[
25-
'@babel/env',
26-
{
27-
modules: false,
28-
useBuiltIns: 'usage'
29-
}
30-
]
31-
]
32-
}
12+
plugins: [['@babel/proposal-class-properties', { loose: true }]]
3313
};
34-
35-
module.exports = { presets, plugins, env };

package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
"type": "git",
88
"url": "https://github.com/mohsinulhaq/react-popper-tooltip"
99
},
10-
"main": "lib/cjs/index.js",
10+
"browser": "lib/cjs/index.js",
1111
"module": "lib/esm/index.js",
12+
"unpkg": "dist/index.js",
13+
"style": "dist/styles.css",
1214
"typings": "typings/react-popper-tooltip.d.ts",
1315
"files": [
1416
"lib",
1517
"dist",
1618
"typings/react-popper-tooltip.d.ts"
1719
],
1820
"scripts": {
19-
"build": "yarn build:cjs; yarn build:esm; mkdir -p dist && cp src/styles.css dist",
20-
"build:cjs": "babel --delete-dir-on-start src -d lib/cjs",
21-
"build:esm": "babel --delete-dir-on-start --env-name esm src -d lib/esm",
22-
"prepublishOnly": "yarn lint && yarn build && yarn docs:deploy",
21+
"build": "rimraf dist lib && rollup -c && cp src/styles.css dist",
22+
"prepublishOnly": "yarn lint && yarn build",
2323
"docs": "docz dev",
2424
"docs:build": "docz build",
2525
"docs:deploy": "yarn docs:build && cp .docz/dist/index.html .docz/dist/404.html && gh-pages -d .docz/dist",
@@ -101,6 +101,7 @@
101101
},
102102
"dependencies": {
103103
"@babel/runtime": "^7.0.0",
104+
"prop-types": "^15.6.2",
104105
"react-popper": "^1.0.2"
105106
},
106107
"devDependencies": {
@@ -121,8 +122,15 @@
121122
"gh-pages": "^2.0.0",
122123
"pre-commit": "^1.2.2",
123124
"prettier": "^1.14.3",
124-
"prop-types": "^15.6.2",
125125
"react": "^16.5.2",
126-
"react-dom": "^16.5.2"
127-
}
126+
"react-dom": "^16.5.2",
127+
"rimraf": "^2.6.2",
128+
"rollup": "^0.66.2",
129+
"rollup-plugin-babel": "^4.0.3",
130+
"rollup-plugin-commonjs": "^9.1.8",
131+
"rollup-plugin-node-resolve": "^3.4.0",
132+
"rollup-plugin-size-snapshot": "^0.7.0",
133+
"rollup-plugin-terser": "^3.0.0"
134+
},
135+
"sideEffects": false
128136
}

rollup.config.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import babel from 'rollup-plugin-babel';
2+
import resolve from 'rollup-plugin-node-resolve';
3+
import commonjs from 'rollup-plugin-commonjs';
4+
import { terser } from 'rollup-plugin-terser';
5+
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
6+
import pkg from './package.json';
7+
8+
const input = 'src/index.js';
9+
const name = 'TooltipTrigger';
10+
const globals = {
11+
react: 'React',
12+
'react-dom': 'ReactDOM',
13+
'prop-types': 'PropTypes',
14+
'react-popper': 'ReactPopper'
15+
};
16+
const external = id => !id.startsWith('.') && !id.startsWith('/');
17+
const getBabelOptions = ({ useESModules = true } = {}) => ({
18+
exclude: 'node_modules/**',
19+
runtimeHelpers: true,
20+
plugins: [['@babel/plugin-transform-runtime', { useESModules }]]
21+
});
22+
23+
export default [
24+
{
25+
input,
26+
output: {
27+
name,
28+
file: 'dist/index.js',
29+
format: 'iife',
30+
globals,
31+
interop: false
32+
},
33+
external: Object.keys(globals),
34+
plugins: [
35+
resolve({
36+
browser: true,
37+
modulesOnly: true
38+
}),
39+
commonjs({
40+
include: 'node_modules/**'
41+
}),
42+
babel(getBabelOptions()),
43+
terser(),
44+
sizeSnapshot()
45+
]
46+
},
47+
{
48+
input,
49+
output: {
50+
file: pkg.browser,
51+
format: 'cjs',
52+
interop: false
53+
},
54+
external,
55+
plugins: [babel(getBabelOptions({ useESModules: false })), sizeSnapshot()]
56+
},
57+
{
58+
input,
59+
output: {
60+
file: pkg.module,
61+
format: 'esm',
62+
interop: false
63+
},
64+
external,
65+
plugins: [babel(getBabelOptions()), sizeSnapshot()]
66+
}
67+
];

src/Tooltip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { PureComponent } from 'react';
33
import { findDOMNode } from 'react-dom';
44
import T from 'prop-types';
5-
import { TooltipContext } from './TooltipTrigger';
5+
import { TooltipContext } from './utils';
66
import { callAll } from './utils';
77

88
const MUTATION_OBSERVER_CONFIG = {

src/TooltipTrigger.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createPortal } from 'react-dom';
66
import T from 'prop-types';
77
import { Manager, Reference, Popper } from 'react-popper';
88
import Tooltip from './Tooltip';
9-
import { callAll, noop } from './utils';
9+
import { TooltipContext, callAll, noop } from './utils';
1010

1111
const DEFAULT_MODIFIERS = {
1212
preventOverflow: {
@@ -15,8 +15,6 @@ const DEFAULT_MODIFIERS = {
1515
}
1616
};
1717

18-
export const TooltipContext = React.createContext({});
19-
2018
export default class TooltipTrigger extends PureComponent {
2119
static propTypes = {
2220
/**

src/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import React from 'react';
2+
3+
export const TooltipContext = React.createContext({});
4+
15
export const callAll = (...fns) => (...args) =>
26
fns.forEach(fn => fn && fn(...args));
37

0 commit comments

Comments
 (0)