Skip to content

Commit a62ecba

Browse files
authored
Export browser bundle of drivers as ECMAScript module (#1038)
ECMAScript modules are the official standard format to package JavaScript code for reuse. This is standard improve the modularity of the applications by avoiding leaking global variables and other benefits. Usage example of the `neo4j-driver-lite` esm in browser: ```javascript // jsDelivr CDN minified for production use, version X.Y.Z where X.Y.Z >= 5.4.0 import neo4j from 'https://cdn.jsdelivr.net/npm/[email protected]/lib/browser/neo4j-lite-web.esm.min.js' const driver = neo4j.driver(/* your host */, neo4j.auth.basic(/* user */, /* password */)) driver.verifyConnectivity() .then(() => console.log('Connected')) .catch(e => console.error(e)) ``` **Changes in the `neo4j-driver-lite`** `Browserify` was replaced by `rollup` as the browser building tool for building `umd` and `esm` outputs. Since `rollup` is already being used in the `testkit-backend`, this change also standardise the tooling in the monorepo. The esm module is exported as `neo4j-lite-web.esm.js` (non-minified) and `neo4j-lite-web.esm.min.js` (minified). The files are available under `lib/browser` along with `umd` modules. **Changes in the `neo4j-driver`** `Browserify` was replace by `rollup` as in the `neo4j-driver-lite`. However, its usage is done using `gulp`. The library build was changed to use `tsc` building tool instead of `babel`. Removed dev dependencies: * @babel/eslint-parser * @babel/preset-env * @istanbuljs/nyc-config-babel * babel-plugin-istanbul * babelify * browserify * browserify-transform-tools * gulp-babel * istanbul * karma-browserify * nyc * vinyl-source-stream Removed prod dependencies: * @babel/runtime Some babel dependencies still needed since the gulp script depends on ES6 imports.
1 parent 3db98f5 commit a62ecba

File tree

23 files changed

+60486
-66147
lines changed

23 files changed

+60486
-66147
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ var driver = neo4j.driver(
7878
)
7979
```
8080

81+
From `5.4.0`, this version is also exported as ECMA Script Module.
82+
It can be imported from a module using the following statements:
83+
84+
```javascript
85+
// Direct reference
86+
import neo4j from 'lib/browser/neo4j-web.esm.min.js'
87+
88+
// unpkg CDN non-minified , version X.Y.Z where X.Y.Z >= 5.4.0
89+
import neo4j from 'https://unpkg.com/browse/[email protected]/lib/browser/neo4j-web.esm.js'
90+
91+
// unpkg CDN minified for production use, version X.Y.Z where X.Y.Z >= 5.4.0
92+
import neo4j from 'https://unpkg.com/browse/[email protected]/lib/browser/neo4j-web.esm.min.js'
93+
94+
// jsDelivr CDN non-minified, version X.Y.Z where X.Y.Z >= 5.4.0
95+
import neo4j from 'https://cdn.jsdelivr.net/npm/[email protected]/lib/browser/neo4j-web.esm.js'
96+
97+
// jsDelivr CDN minified for production use, version X.Y.Z where X.Y.Z >= 5.4.0
98+
import neo4j from 'https://cdn.jsdelivr.net/npm/[email protected]/lib/browser/neo4j-web.esm.min.js'
99+
100+
```
101+
81102
It is not required to explicitly close the driver on a web page. Web browser should gracefully close all open
82103
WebSockets when the page is unloaded. However, driver instance should be explicitly closed when it's lifetime
83104
is not the same as the lifetime of the web page:

0 commit comments

Comments
 (0)