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

Commit fb7d798

Browse files
virgofxFezVrasta
authored andcommitted
fix: v0.x dist builds to ensure SSR works properly and popper.js is included in the dist builds (#146)
* fix: v0.x dist builds to ensure SSR works properly * fix: Ensure /dist folder structure uses best-practice with module types separated by folder.
1 parent 65a8cbf commit fb7d798

File tree

4 files changed

+78
-30
lines changed

4 files changed

+78
-30
lines changed

.babelrc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
{
2-
"presets": [["env", { "modules": false }], "stage-2", "react"],
3-
"plugins": ["transform-class-properties"]
2+
"presets": [
3+
["env", { "modules": false }],
4+
"stage-2",
5+
"react"
6+
],
7+
"plugins": [
8+
"external-helpers",
9+
"transform-class-properties"
10+
],
11+
"env": {
12+
"production": {
13+
"plugins": [
14+
["transform-react-remove-prop-types", { "removeImport": true }]
15+
]
16+
}
17+
}
418
}

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@ React wrapper around [PopperJS](https://github.com/FezVrasta/popper.js/).
1212

1313
`npm install react-popper --save` or `yarn add react-popper`
1414

15+
16+
### CDN
17+
18+
If you prefer to include React Popper globally by marking `react-popper` as external in your application, the `react-popper` library (exposed as `ReactPopper`) provides various single-file distributions, which are hosted on the following CDNs:
19+
20+
* [**cdnjs**](https://cdnjs.com/libraries/react-popper)
1521
```html
16-
<script src="https://unpkg.com/react-popper/dist/react-popper.js"></script>
17-
(UMD library exposed as `ReactPopper`)
22+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-popper/0.10.2/umd/react-popper.min.js"></script>
1823
```
1924

25+
* [**unpkg**](https://unpkg.com/react-popper/)
26+
```html
27+
<script src="https://unpkg.com/[email protected]/dist/umd/react-popper.min.js"></script>
28+
```
29+
30+
> **Note**: To load a specific version of React Popper replace `0.10.2` with the version number.
31+
2032
## Usage
2133

2234
```js

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
"react-popper.d.ts"
1616
],
1717
"scripts": {
18-
"build": "npm run build:clean && npm run build:es && npm run build:umd && npm run build:cjs && npm run build:umd-min && npm run build:cjs-min",
18+
"build": "npm run build:clean && npm run build:es && npm run build:dist && npm run build:dist:prod",
1919
"build:clean": "rm -rf dist/ && rm -rf lib/",
2020
"build:es": "babel src --out-dir lib && mv lib/index.js lib/react-popper.js",
21-
"build:umd": "rollup -c --output.format umd --output.name ReactPopper --output.file dist/react-popper.umd.js",
22-
"build:cjs": "rollup -c --output.format cjs --output.name ReactPopper --output.file dist/react-popper.js",
23-
"build:umd-min": "MINIFY=true rollup -c --output.format umd --output.name ReactPopper --output.file dist/react-popper.umd.min.js",
24-
"build:cjs-min": "MINIFY=true rollup -c --output.format cjs --output.name ReactPopper --output.file dist/react-popper.min.js",
21+
"build:dist": "rollup -c",
22+
"build:dist:prod": "NODE_ENV=production rollup -c",
2523
"demo": "parcel --out-dir demo/dist demo/index.html",
2624
"prepare": "npm run build",
2725
"precommit": "lint-staged",

rollup.config.js

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
11
import babel from 'rollup-plugin-babel';
22
import minify from 'rollup-plugin-babel-minify';
3+
import replace from 'rollup-plugin-replace';
4+
import nodeResolve from 'rollup-plugin-node-resolve';
35

4-
export default {
5-
input: 'src/index.js',
6-
plugins: [
7-
babel({
8-
babelrc: false,
9-
presets: [['env', { modules: false }], 'stage-2', 'react'],
10-
plugins: [
11-
'external-helpers',
12-
['transform-react-remove-prop-types', { mode: 'wrap' }],
13-
],
14-
}),
15-
process.env.MINIFY ? minify() : false,
16-
].filter(Boolean),
17-
external: ['react', 'react-dom', 'prop-types', 'popper.js'],
18-
output: {
19-
sourcemap: true,
20-
globals: {
21-
react: 'React',
22-
'prop-types': 'PropTypes',
23-
'popper.js': 'Popper',
6+
const baseConfig = (outputFormat) => {
7+
const isProduction = process.env.NODE_ENV === 'production';
8+
9+
let file;
10+
switch (outputFormat) {
11+
case 'umd':
12+
case 'cjs':
13+
file = 'dist/' + outputFormat + '/react-popper' + (isProduction ? '.min' : '') + '.js';
14+
break;
15+
16+
default:
17+
throw new Error('Unsupported output format: ' + outputFormat);
18+
}
19+
20+
return {
21+
input: 'src/index.js',
22+
plugins: [
23+
nodeResolve(),
24+
babel(),
25+
replace({
26+
'process.env.NODE_ENV': JSON.stringify('production')
27+
}),
28+
isProduction ? minify({
29+
comments: false,
30+
}) : false,
31+
],
32+
external: ['react', 'react-dom', 'prop-types', 'popper.js'],
33+
output: {
34+
name: 'ReactPopper',
35+
file: file,
36+
format: outputFormat,
37+
sourcemap: true,
38+
globals: {
39+
react: 'React',
40+
'prop-types': 'PropTypes',
41+
'popper.js': 'Popper',
42+
},
2443
},
25-
},
44+
};
2645
};
46+
47+
export default [
48+
baseConfig('cjs'),
49+
baseConfig('umd'),
50+
];

0 commit comments

Comments
 (0)