Skip to content

Commit 9efb61e

Browse files
author
Herman Starikov
committed
support umd
1 parent 5ac5fed commit 9efb61e

9 files changed

+34
-27
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
# production
1010
/build
11-
/lib
1211

1312
# misc
1413
.DS_Store

config/webpack.config.dev.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
'use strict';
21

3-
const autoprefixer = require('autoprefixer');
4-
const path = require('path');
5-
const webpack = require('webpack');
6-
const HtmlWebpackPlugin = require('html-webpack-plugin');
7-
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
8-
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
9-
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
10-
const eslintFormatter = require('react-dev-utils/eslintFormatter');
11-
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
12-
const getClientEnvironment = require('./env');
13-
const paths = require('./paths');
2+
3+
const autoprefixer = require('autoprefixer')
4+
const path = require('path')
5+
const webpack = require('webpack')
6+
const HtmlWebpackPlugin = require('html-webpack-plugin')
7+
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
8+
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin')
9+
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin')
10+
const eslintFormatter = require('react-dev-utils/eslintFormatter')
11+
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin')
12+
const getClientEnvironment = require('./env')
13+
const paths = require('./paths')
1414

1515
// Webpack uses `publicPath` to determine where the app is being served from.
1616
// In development, we always serve from the root. This makes config easier.
17-
const publicPath = '/';
17+
const publicPath = '/'
1818
// `publicUrl` is just like `publicPath`, but we will provide it to our app
1919
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
2020
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
21-
const publicUrl = '';
21+
const publicUrl = ''
2222
// Get environment variables to inject into our app.
23-
const env = getClientEnvironment(publicUrl);
23+
const env = getClientEnvironment(publicUrl)
2424

2525
// This is the development configuration.
2626
// It is focused on developer experience and fast rebuilds.
@@ -59,10 +59,13 @@ module.exports = {
5959
// served by WebpackDevServer in development. This is the JS bundle
6060
// containing code from all our entry points, and the Webpack runtime.
6161
filename: 'static/js/bundle.js',
62+
library: require('../package.json').name,
63+
libraryTarget: 'umd',
64+
umdNamedDefine: true,
6265
// There are also additional JS chunk files if you use code splitting.
6366
chunkFilename: 'static/js/[name].chunk.js',
6467
// This is the URL that app is served from. We use "/" in development.
65-
publicPath: publicPath,
68+
publicPath,
6669
// Point sourcemap entries to original disk location (format as URL on Windows)
6770
devtoolModuleFilenameTemplate: info =>
6871
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
@@ -84,7 +87,7 @@ module.exports = {
8487
// for React Native Web.
8588
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
8689
alias: {
87-
90+
8891
// Support React Native Web
8992
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
9093
'react-native': 'react-native-web',
@@ -115,7 +118,7 @@ module.exports = {
115118
options: {
116119
formatter: eslintFormatter,
117120
eslintPath: require.resolve('eslint'),
118-
121+
119122
},
120123
loader: require.resolve('eslint-loader'),
121124
},
@@ -144,7 +147,7 @@ module.exports = {
144147
include: paths.appSrc,
145148
loader: require.resolve('babel-loader'),
146149
options: {
147-
150+
148151
// This is a feature of `babel-loader` for webpack (not Babel itself).
149152
// It enables caching results in ./node_modules/.cache/babel-loader/
150153
// directory for faster rebuilds.
@@ -259,4 +262,4 @@ module.exports = {
259262
performance: {
260263
hints: false,
261264
},
262-
};
265+
}

config/webpack.config.prod.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ module.exports = {
6363
// Generated JS file names (with nested folders).
6464
// There will be one main bundle, and one file per asynchronous chunk.
6565
// We don't currently advertise code splitting but Webpack supports it.
66-
filename: 'static/js/[name].[chunkhash:8].js',
66+
filename: 'static/js/[name].js',
67+
library: require('../package.json').name,
68+
libraryTarget: 'umd',
69+
umdNamedDefine: true,
6770
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
6871
// We inferred the "public path" (such as / or /my-project) from homepage.
6972
publicPath,

lib/navbar-offcanvas.css

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/navbar-offcanvas.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/navbar-offcanvas.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/navbar-offcanvas.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
4545
<script type="text/babel">
4646
const { Navbar, Nav, NavItem, MenuItem, NavDropdown, FormGroup, Button, FormControl } = ReactBootstrap
47-
const NavbarOffcanvas = ReactBootstrapNavbarOffcanvas
47+
const { default: NavbarOffcanvas } = window["react-bootstrap-navbar-offcanvas"]
4848
class App extends React.Component {
4949
render() {
5050
return (

src/index.js

-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,3 @@ class NavbarOffcanvas extends React.Component {
3333
NavbarOffcanvas.contextTypes = contextTypes
3434

3535
export default NavbarOffcanvas
36-
37-
if (typeof window !== 'undefined') {
38-
window.ReactBootstrapNavbarOffcanvas = NavbarOffcanvas
39-
}

0 commit comments

Comments
 (0)