Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 114499f

Browse files
TrySoundFezVrasta
authored andcommitted
Bundle UMD with rollup (#159)
* build: bundle UMD with rollup UMD is important as an easy way to use library via `<script>` tag. In this diff I added rollup with size snapshot plugin to track final size of the library with all dependencies (except react ones). I replaced mixed imports with `import * as React from 'react'` since they are being semantically incorrect are failed with rollup.
1 parent 525b27f commit 114499f

File tree

7 files changed

+557
-20
lines changed

7 files changed

+557
-20
lines changed

.size-snapshot.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"dist/index.umd.js": {
3+
"bundled": 51328,
4+
"minified": 18567,
5+
"gzipped": 5953
6+
}
7+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"/typings/react-popper.d.ts"
1515
],
1616
"scripts": {
17-
"build": "npm run build:clean && npm run build:es && npm run build:cjs && npm run build:flow",
17+
"build": "npm run build:clean && npm run build:es && npm run build:cjs && npm run build:umd && npm run build:flow",
1818
"build:clean": "rimraf dist/ && rimraf lib/",
19+
"build:umd": "rollup -c",
1920
"build:es": "cross-env BABEL_ENV=es babel src --ignore '*.test.js,__mocks__' --out-dir lib/es",
2021
"build:cjs": "cross-env BABEL_ENV=cjs babel src --ignore '*.test.js,__mocks__' --out-dir lib/cjs",
2122
"build:flow": "flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib/cjs",
@@ -103,6 +104,12 @@
103104
"react-spring": "^4.0.1",
104105
"recompose": "^0.26.0",
105106
"rimraf": "^2.6.2",
107+
"rollup": "^0.58.2",
108+
"rollup-plugin-babel": "^3.0.4",
109+
"rollup-plugin-commonjs": "^9.1.3",
110+
"rollup-plugin-node-resolve": "^3.3.0",
111+
"rollup-plugin-size-snapshot": "^0.4.0",
112+
"rollup-plugin-uglify": "^3.0.0",
106113
"typescript": "^2.8.1"
107114
}
108115
}

rollup.config.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import nodeResolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import babel from 'rollup-plugin-babel';
4+
import uglify from 'rollup-plugin-uglify';
5+
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
6+
7+
const input = './src/index.js';
8+
9+
const umdGlobals = {
10+
react: 'React',
11+
'react-dom': 'ReactDOM',
12+
'popper.js': 'Popper',
13+
};
14+
15+
const getBabelOptions = () => ({
16+
babelrc: false,
17+
exclude: '**/node_modules/**',
18+
presets: [['env', { modules: false }], 'stage-1', 'react'],
19+
plugins: ['external-helpers'],
20+
});
21+
22+
export default [
23+
{
24+
input,
25+
output: {
26+
file: 'dist/index.umd.js',
27+
format: 'umd',
28+
name: 'ReactPopper',
29+
globals: umdGlobals,
30+
},
31+
external: Object.keys(umdGlobals),
32+
plugins: [
33+
nodeResolve(),
34+
commonjs({ include: '**/node_modules/**' }),
35+
babel(getBabelOptions()),
36+
sizeSnapshot(),
37+
],
38+
},
39+
40+
{
41+
input,
42+
output: {
43+
file: 'dist/index.umd.min.js',
44+
format: 'umd',
45+
name: 'ReactPopper',
46+
globals: umdGlobals,
47+
},
48+
external: Object.keys(umdGlobals),
49+
plugins: [
50+
nodeResolve(),
51+
commonjs({ include: '**/node_modules/**' }),
52+
babel(getBabelOptions()),
53+
uglify(),
54+
],
55+
},
56+
];

src/Manager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import React, { Component, type Node } from "react";
2+
import * as React from "react";
33
import createContext, { type Context } from "create-react-context";
44

55
export const ManagerContext: Context<{
@@ -8,7 +8,7 @@ export const ManagerContext: Context<{
88
}> = createContext({ getReferenceRef: undefined, referenceNode: undefined });
99

1010
export type ManagerProps = {
11-
children: Node,
11+
children: React.Node,
1212
};
1313
type ManagerState = {
1414
context: {
@@ -17,7 +17,7 @@ type ManagerState = {
1717
},
1818
};
1919

20-
export default class Manager extends Component<ManagerProps, ManagerState> {
20+
export default class Manager extends React.Component<ManagerProps, ManagerState> {
2121
constructor() {
2222
super();
2323
this.state = {

src/Popper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import React, { Component, type Node } from 'react';
2+
import * as React from 'react';
33
import PopperJS, {
44
type Placement,
55
type Instance as PopperJS$Instance,
@@ -28,7 +28,7 @@ export type PopperChildrenProps = {|
2828
scheduleUpdate: () => void,
2929
arrowProps: PopperArrowProps,
3030
|};
31-
export type PopperChildren = PopperChildrenProps => Node;
31+
export type PopperChildren = PopperChildrenProps => React.Node;
3232

3333
export type PopperProps = {
3434
modifiers?: Modifiers,
@@ -56,7 +56,7 @@ const initialStyle = {
5656

5757
const initialArrowStyle = {};
5858

59-
export class InnerPopper extends Component<PopperProps, PopperState> {
59+
export class InnerPopper extends React.Component<PopperProps, PopperState> {
6060
static defaultProps = {
6161
placement: 'bottom',
6262
eventsEnabled: true,

src/Reference.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @flow
2-
import React, { type Node } from 'react';
2+
import * as React from 'react';
33
import warning from 'warning';
44
import { ManagerContext } from './Manager';
55
import { unwrapArray } from './utils';
66

77
export type ReferenceChildrenProps = { ref: (?HTMLElement) => void };
88
export type ReferenceProps = {
9-
children: ReferenceChildrenProps => Node,
9+
children: ReferenceChildrenProps => React.Node,
1010
};
1111

1212
export default function Reference({ children }: ReferenceProps) {

0 commit comments

Comments
 (0)