Skip to content

Commit 681738c

Browse files
virgofxTheSharpieOne
authored andcommitted
fix(Build): Cross-platform postbuild support, improved Readme documentation, updated dependencies. (#608)
chore(build): Cross-platform postbuild support, improved Readme documentation, updated dependencies.
1 parent 72fb714 commit 681738c

7 files changed

Lines changed: 565 additions & 362 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ module.exports = {
5858
'sourceType': 'module',
5959
'ecmaFeatures': ecmaFeatures
6060
},
61-
'ecmaFeatures': ecmaFeatures,
6261
rules: rules
6362
};

README.md

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,78 @@ Import required reactstrap components within ```src/App.js``` file or your custo
4343
import { Button } from 'reactstrap';
4444
```
4545

46-
Now you are ready to use the imported reactstrap components within your component hierarchy defined in the render method. Here is an example [`App.js`](https://gist.github.com/eddywashere/e13033c0e655ab7cda995f8bc77ce40d) redone using reactstrap.
46+
Now you are ready to use the imported reactstrap components within your component hierarchy defined in the render
47+
method. Here is an example [`App.js`](https://gist.github.com/eddywashere/e13033c0e655ab7cda995f8bc77ce40d) redone
48+
using reactstrap.
49+
50+
### Dependencies
51+
52+
##### Required Peer Dependencies
53+
54+
These libraries are not bundled with Reactstrap and required at runtime:
55+
56+
* [**react**](https://www.npmjs.com/package/react)
57+
* [**react-dom**](https://www.npmjs.com/package/react-dom)
58+
59+
##### Optional Dependencies
60+
61+
These libraries are not included in the main distribution file `reactstrap.min.js` and need to be manually
62+
included when using components that require transitions or popover effects (e.g. Tooltip, Modal, etc).
63+
64+
* [**react-transition-group**](https://www.npmjs.com/package/react-transition-group)
65+
* [**react-popper**](https://www.npmjs.com/package/react-popper)
66+
4767

4868
### CDN
4969

50-
If you prefer to include Reactstrap globally by marking `reactstrap` as external in your application, the `reactstrap` library provides various single-file distributions, which are hosted on the following CDNs:
70+
If you prefer to include Reactstrap globally by marking `reactstrap` as external in your application, the
71+
`reactstrap` library provides various single-file distributions, which are hosted on the following CDNs:
5172

5273
* [**cdnjs**](https://cdnjs.com/libraries/reactstrap)
5374
```html
54-
<!-- main version -->
75+
<!-- Main version -->
5576
<script src="https://cdnjs.cloudflare.com/ajax/libs/reactstrap/5.0.0-alpha.3/reactstrap.min.js"></script>
5677

57-
<!-- all dependencies version -->
78+
<!-- All optional dependencies version -->
5879
<script src="https://cdnjs.cloudflare.com/ajax/libs/reactstrap/5.0.0-alpha.3/reactstrap.full.min.js"></script>
5980
```
6081

6182
* [**unpkg**](https://unpkg.com/reactstrap/)
6283
```html
63-
<!-- main version -->
84+
<!-- Main version -->
6485
<script src="https://unpkg.com/[email protected]/reactstrap.min.js"></script>
6586

66-
<!-- all dependencies version -->
87+
<!-- All optional dependencies version -->
6788
<script src="https://unpkg.com/[email protected]/reactstrap.full.min.js"></script>
6889
```
6990

70-
To load a specific version of Reactstrap replace `5.0.0-alpha.3` with the version number.
91+
> **Note**: To load a specific version of Reactstrap replace `5.0.0-alpha.3` with the version number.
92+
93+
#### Versions
94+
95+
Reactstrap has two primary distribution versions:
7196

72-
Reactstrap has two primary versions that can be included directly:
97+
1) `reactstrap.min.js`
7398

74-
1) `reactstrap.min.js` - This file excludes `react-popper` and `react-transition-group` from
75-
the build. This is similar to Bootstrap and results in the smallest file size possible for
76-
Reactstrap. Using any components that require `Popper` or transitions will not work unless
77-
the required dependencies are included. This is the recommended approach for including
78-
Reactstrap as it allows the user to only include the optional dependencies once and re-use
79-
those dependencies in your application as well.
99+
This file **excludes** the optional dependencies – `react-popper` and `react-transition-group`.
100+
This is the recommended approach (similar approach in Bootstrap's JavaScript components) for including
101+
Reactstrap as it reduces the filesize and gives more flexibility in configuring needed dependencies.
102+
103+
**Recommended use cases:**
104+
105+
* Small, medium, or large applications
106+
* Applications that do not use any transitions or popper components
107+
* Applications that directly use `react-popper` or `react-transition-group` – Reactstrap and your application
108+
will use the single global version included
80109

81110
2) `reactstrap.full.min.js`
82-
This file includes all optional dependencies. (PropTypes, React, and ReactDOM must
83-
still be included)
111+
112+
This file **includes** the optional dependencies – `react-popper` and `react-transition-group`
113+
114+
**Recommended use cases:**
115+
116+
* Small applications
117+
84118

85119
#### Example
86120

@@ -92,22 +126,20 @@ Reactstrap has two primary versions that can be included directly:
92126
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.0/prop-types.min.js"></script>
93127
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react/16.0.0/umd/react.production.min.js"></script>
94128
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react-dom/16.0.0/umd/react-dom.production.min.js"></script>
95-
<!-- Most apps require transitions, so include transition dependency -->
96-
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react-transition-group/2.2.0/react-transition-group.min.js"></script>
129+
<!-- Optional dependencies -->
130+
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react-transition-group/2.2.1/react-transition-group.min.js"></script>
131+
<script type="text/javascript" src="//unpkg.com/[email protected]/dist/react-popper.min.js"></script>
97132
<!-- Reactstrap -->
98133
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/reactstrap/5.0.0-alpha.3/reactstrap.min.js"></script>
99-
<!-- Lastly, include your app's bundle
134+
<!-- Lastly, include your app's bundle -->
100135
<script type="text/javascript" src="/assets/bundle.js"></script>
101-
-->
102136
</head>
103137
<body>
104138
<div id="my-app" />
105139
</body>
106140
</html>
107-
108141
```
109142

110-
111143
## About the Project
112144

113145
This library contains React Bootstrap 4 components that favor composition and control. The library does not depend on jQuery or Bootstrap javascript. However, [Poppers.js](https://popper.js.org/) via [react-popper](https://github.com/souporserious/react-popper) is relied upon for advanced positioning of content like Tooltips, Popovers, and auto-flipping Dropdowns.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build-docs": "cross-env BABEL_ENV=webpack WEBPACK_BUILD=production webpack --config ./webpack.dev.config.js --progress --colors",
1414
"build": "rollup -c",
1515
"prebuild": "cross-env BABEL_ENV=lib-dir babel src --out-dir lib --ignore src/__tests__/",
16-
"postbuild": "./scripts/post-build",
16+
"postbuild": "node ./scripts/postbuild.js",
1717
"create-release": "npm test && sh ./scripts/release",
1818
"publish-release": "npm test && sh ./scripts/publish",
1919
"lint": "eslint src"

rollup.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ libConfig.targets = [
4545
4646
Goal of this configuration is to be directly included on web pages.
4747
This configuration is minimized and will include dependencies that are not
48-
marked as peer dependencies.
48+
marked as peer dependencies. ** See below
4949
5050
Defining this config will also check that all peer dependencies are set up
5151
correctly in the globals entry.
@@ -60,6 +60,9 @@ libConfig.targets = [
6060
2) `reactstrap.full.min.js`
6161
This file includes all dependencies.
6262
63+
For both versions the peer dependencies are always excluded and must be manually
64+
included - `react` and `react-dom`.
65+
6366
*/
6467
const umdFullConfig = baseConfig();
6568
umdFullConfig.external = peerDependencies;
@@ -85,14 +88,16 @@ if (missingGlobals.length) {
8588

8689
const external = umdFullConfig.external.slice();
8790
external.push('react-transition-group/Transition');
91+
external.push('react-popper');
8892

8993
const umdConfig = Object.assign({}, umdFullConfig, {
9094
targets: [
9195
{ dest: 'dist/reactstrap.min.js', format: 'umd' },
9296
],
9397
external: external,
9498
globals: Object.assign({}, umdFullConfig.globals, {
95-
'react-transition-group/Transition': 'ReactTransitionGroup.Transition'
99+
'react-popper': 'ReactPopper',
100+
'react-transition-group/Transition': 'ReactTransitionGroup.Transition',
96101
})
97102
});
98103

scripts/post-build

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

scripts/postbuild.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var fs = require('fs');
2+
3+
// Ensure that any optional peer dependency (e.g. ReactTransitionGroup and
4+
// ReactPopper) are properly set as optional globals. Specifically, do not
5+
// error if the user has not loaded these dependencies. Degrade gracefully.
6+
7+
fs.readFile(__dirname + '/../dist/reactstrap.min.js', 'utf8', function(err, data) {
8+
if (err) {
9+
return console.error(err);
10+
}
11+
12+
var result = data.replace(
13+
/\,([a-zA-Z]+)\.ReactTransitionGroup\.Transition/,
14+
',$1.ReactTransitionGroup && $1.ReactTransitionGroup.Transition || undefined'
15+
).replace(
16+
/\,([a-zA-Z]+)\.ReactPopper/,
17+
',$1.ReactPopper || undefined'
18+
);
19+
20+
fs.writeFile(__dirname + '/../dist/reactstrap.min.js', result, 'utf8', function(err) {
21+
if (err) {
22+
console.error(err);
23+
}
24+
});
25+
26+
});

0 commit comments

Comments
 (0)