Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Feature] UMD module in unpkg (#349)
Giuseppe Macrì0e7eea57d8d2
diff --git a/.gitignore b/.gitignoreindex 8335d325c..b4334c78f 100644--- a/.gitignore+++ b/.gitignore@@ -3,6 +3,7 @@ node_modules/coverage/.nyc_output/dist/+umd/*/**/dist/*/**/yarn.lockdiff --git a/README.md b/README.mdindex 53e4ae1a8..22cc64a77 100644--- a/README.md+++ b/README.md@@ -56,6 +56,16 @@ yarn add kepler.glkepler.gl is built upon [mapbox][mapbox]. You will need a [Mapbox Access Token][mapbox-token] to use it.+If you don't use a module bundler, it's also fine. Kepler.gl npm package includes precompiled production UMD builds in the (umd folder)[https://unpkg.com/kepler.gl/umd].+You can add the script tag to your html file as it follows:+```html+<script src="https://unpkg.com/kepler.gl/umd/keplergl.min.js"></script>+```+or if you would like, you can load a specific version+```html+<script src="https://unpkg.com/[email protected]/umd/keplergl.min.js"></script>+```+## Develop kepler.glTake a look at the [development guide][developers] to develop kepler.gl locally.@@ -233,7 +243,6 @@ export default composedReducer;You can add a dispatch function to your component that dispatches actions to a specific `keplerGl` component,using connect.-```js// componentimport KeplerGl from 'kepler.gl';diff --git a/examples/demo-app/webpack.config.js b/examples/demo-app/webpack.config.jsindex ef379c2db..71728ec8b 100644--- a/examples/demo-app/webpack.config.js+++ b/examples/demo-app/webpack.config.js@@ -70,7 +70,7 @@ const CONFIG = {historyApiFallback: true},- // Optional: Enables reading mapbox token from environment variable+ // Optional: Enables reading mapbox and dropbox client token from environment variableplugins: [new webpack.EnvironmentPlugin(['MapboxAccessToken', 'DropboxClientId'])]diff --git a/examples/umd-client/index.html b/examples/umd-client/index.htmlnew file mode 100644index 000000000..86d471b2b--- /dev/null+++ b/examples/umd-client/index.html@@ -0,0 +1,104 @@+<!DOCTYPE html>+<html>+<head>+ <meta charset="UTF-8"/>+ <title>Kepler.gl embedded map</title>++ <!-- Load React/Redux -->+ <script src="https://unpkg.com/[email protected]/dist/react.min.js" crossorigin></script>+ <script src="https://unpkg.com/[email protected]/dist/react-dom.min.js" crossorigin></script>+ <script src="https://unpkg.com/[email protected]/dist/redux.js" crossorigin></script>+ <script src="https://unpkg.com/[email protected]/dist/react-redux.min.js" crossorigin></script>++ <!-- Load Kepler.gl latest version-->+ <script src="https://unpkg.com/kepler.gl/umd/keplergl.min.js"></script>+ <!-- You can also specify a specific versions by doing the following -->+ <!--<script src="https://unpkg.com/[email protected]/umd/keplergl.min.js"></script>-->++ <!--MapBox token-->+ <script>+ /**+ * Provide your MapBox Token+ * This will be used in app.js (imported later)+ * */+ const MAPBOX_TOKEN = 'PROVIDE_MAPBOX_TOKEN';+ </script>++</head>+<body>+ <!-- We will put our React component inside this div. -->+ <div id="app">+ <!-- Kepler.gl map will be placed here-->+ </div>++ <!-- Load our React component. -->+ <script>+ const map = (function initKeplerGl(react, reactDOM, redux, reactRedux, keplerGl, mapboxToken) {+ /** STORE **/+ const reducers = redux.combineReducers({+ // mount keplerGl reducer+ keplerGl: keplerGl.keplerGlReducer+ });++ const middlewares = keplerGl.enhanceReduxMiddleware([+ // Add other middlewares here+ ]);++ const enhancers = redux.applyMiddleware(...middlewares);++ const initialState = {};++ const store = redux.createStore(+ reducers,+ initialState,+ redux.compose(enhancers)+ );+ /** END STORE **/++ /** COMPONENTS **/+ function App(props) {+ return react.createElement(+ 'div',+ {style: {position: 'absolute', left: 0, width: '100vw', height: '100vh'}},+ react.createElement(+ keplerGl.KeplerGl,+ {+ mapboxApiAccessToken: mapboxToken,+ id: 'map',+ width: props.width || 1200,+ height: props.height || 800+ }+ )+ )+ }++ return {+ render: () => {+ reactDOM.render(react.createElement(+ reactRedux.Provider,+ {store},+ react.createElement(App, null)+ ), document.getElementById('app'));+ },+ // By returning store we can interact with the map, e.g. add data+ store+ };++ /** END COMPONENTS **/+ }(React, ReactDOM, Redux, ReactRedux, KeplerGl, MAPBOX_TOKEN));++ // Render kepler in the html page+ map.render();+ </script>+ <!-- The next script will show how to interact directly with Kepler map store -->+ <script>+ /**+ * Customize map.+ * Interact with map store to customize data and behavior+ */+ (function customize(keplerGl, map) {+ // map.store.dispatch(keplerGl.toggleSplitMap());+ }(KeplerGl, map))+ </script>+</body>+</html>diff --git a/middleware.js b/middleware.jsnew file mode 100644index 000000000..c42c97c53--- /dev/null+++ b/middleware.js@@ -0,0 +1,21 @@+// Copyright (c) 2019 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++module.exports = require('./dist/middleware');diff --git a/package.json b/package.jsonindex 4cf8bd3d8..9e760b83e 100644--- a/package.json+++ b/package.json@@ -37,10 +37,11 @@"start:custom-reducer": "npm run install-and-start -- examples/custom-reducer start-local","start:web": "npm run install-and-start -- website start","build": "rm -fr dist && uber-licence && babel src --out-dir dist --source-maps inline",+ "build:umd": "webpack --progress --env.prod","lint": "eslint src examples/**/src website/src","check-licence": "uber-licence --dry","add-licence": "uber-licence",- "prepublish": "uber-licence && npm run build",+ "prepublish": "uber-licence && yarn build && yarn build:umd","web": "(yarn && yarn install:web && yarn start:web)","deploy": "yarn clean && yarn && yarn install:web && (cd website && yarn build && git checkout gh-pages && cp dist/* .. && git add .. && git commit -m 'Update website' && git push origin gh-pages && git checkout master)","deploy:test": "yarn clean && yarn && yarn install:web && (cd website && yarn build && git checkout -B gh-pages-test gh-pages && cp dist/* .. && git add .. && git commit -m 'Update website' && git push -f test gh-pages-test:master)",@@ -56,7 +57,8 @@"processors.js","reducers.js","schemas.js",- "styles.js"+ "styles.js",+ "umd"],"dependencies": {"@deck.gl/experimental-layers": "6.3.0",diff --git a/src/index.js b/src/index.jsindex 43f1c2fda..230dab2a9 100644--- a/src/index.js+++ b/src/index.js@@ -42,5 +42,8 @@ export * from './layers';// Stylesexport * from './styles';+// Middleware+export * from './middleware';+// Default exportexport {default} from './components';diff --git a/src/middleware/index.js b/src/middleware/index.jsnew file mode 100644index 000000000..298ab9911--- /dev/null+++ b/src/middleware/index.js@@ -0,0 +1,37 @@+// Copyright (c) 2019 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++// Extra helpers for redux+// We are exposing this secause react-palm has no UMD module and+// users need taskMiddleware to initiate their redux middle ware+import {taskMiddleware} from 'react-palm/tasks';++/**+ * This method is used to enhance redux middleware and provide+ * functionality to support react-palm+ * @param middlewares current redux middlewares+ * @returns {*[]} the original list of middlewares plus the react-palm middleware+ */+export function enhanceReduxMiddleware(middlewares = []) {+ return [+ ...middlewares,+ taskMiddleware+ ];+}diff --git a/webpack.config.js b/webpack.config.jsindex 34609d414..6f18a4723 100644--- a/webpack.config.js+++ b/webpack.config.js@@ -19,13 +19,12 @@// THE SOFTWARE.const resolve = require('path').resolve;-const webpack = require('webpack');const SRC_DIR = resolve('./src');+const LIBRARY_BUNDLE_CONFIG = env => ({- // Bundle the source codeentry: {- lib: SRC_DIR + '/index.js'+ KeplerGl: SRC_DIR + '/index.js'},// Silence warnings about big bundles@@ -35,78 +34,58 @@ const LIBRARY_BUNDLE_CONFIG = env => ({output: {// Generate the bundle in dist folder- path: resolve('./dist'),- filename: 'index.js',- library: 'kepler.gl'- // libraryTarget: 'umd'- },-- // Exclude any non-relative imports from resulting bundle- externals: [- /^[a-z\.\-0-9]+$/- ],-- module: {- rules: [{- test: /\.js$/,- loader: 'babel-loader',- include: [SRC_DIR]- }, {- test: /\.json$/,- loader: 'json-loader'- }, {- test: /\.scss$/,- use: ['style-loader', 'css-loader', 'sass-loader'],- include: [SRC_DIR]- }]- },-- node: {- fs: 'empty'+ path: resolve('./umd'),+ filename: 'keplergl.min.js',+ globalObject: 'this',+ library: '[name]',+ libraryTarget: 'umd'},- plugins: [- // leave minification to app- // new webpack.optimize.UglifyJsPlugin({comments: false}),- new webpack.DefinePlugin({- 'process.env': {- NODE_ENV: JSON.stringify(env),- BROWSER: JSON.stringify(true),- }- })- ]-});--const TEST_BROWSER_CONFIG = {- devServer: {- stats: {- warnings: false+ // let's put everything in+ externals: {+ react: {+ root: 'React',+ commonjs2: 'react',+ commonjs: 'react',+ amd: 'react',+ umd: 'react'},- quiet: true- },-- // Bundle the tests for running in the browser- entry: {- 'test-browser': resolve('./test/browser.js')- },-- // Generate a bundle in dist folder- output: {- path: resolve('./dist'),- filename: '[name]-bundle.js'- },-- devtool: '#inline-source-maps',-- resolve: {- alias: {- 'kepler.gl/test': resolve('./test'),- 'kepler.gl': resolve('./src')+ 'react-dom': {+ root: 'ReactDOM',+ commonjs2: 'react-dom',+ commonjs: 'react-dom',+ amd: 'react-dom',+ umd: 'react-dom'+ },+ redux: {+ root: 'Redux',+ commonjs2: 'redux',+ commonjs: 'redux',+ amd: 'redux',+ umd: 'redux'+ },+ 'react-redux': {+ root: 'ReactRedux',+ commonjs2: 'react-redux',+ commonjs: 'react-redux',+ amd: 'react-redux',+ umd: 'react-redux'}},module: {- rules: []+ rules: [+ {+ test: /\.js$/,+ loader: 'babel-loader',+ include: [SRC_DIR]+ },+ {+ test: /\.json$/,+ loader: 'json-loader',+ type: 'javascript/auto'+ }+ ]},node: {@@ -114,16 +93,6 @@ const TEST_BROWSER_CONFIG = {},plugins: []-};---module.exports = env => {- env = env || {};- if (env.test) {- return TEST_BROWSER_CONFIG;- }+});- console.log(- JSON.stringify(LIBRARY_BUNDLE_CONFIG(env), null, 2));- return LIBRARY_BUNDLE_CONFIG(env);-};+module.exports = env => LIBRARY_BUNDLE_CONFIG(env);