Skip to content

Commit

Permalink
doc: Add section related to basic setup with ES6 module loader (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpl authored Dec 23, 2019
1 parent f85b5d8 commit 5c8a743
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Table of contents
* [Supported Browsers](#supported-browsers)
* [Installation](#installation)
* [Basic Setup](#basic-setup)
* [Basic Setup with ES6 module loader](#basic-setup-with-es6-module-loader)
* [Basic Setup with module bundlers](#basic-setup-with-module-bundlers)
* [Usage with webpack without bundling](#usage-with-webpack-without-bundling)
* [Using the Promise-based APIs](#using-the-promise-based-apis)
Expand Down Expand Up @@ -117,6 +118,31 @@ browser.tabs.executeScript({file: "content.js"}).then(result => {
});
```

### Basic Setup with ES6 module loader

The polyfill can also be loaded using the native ES6 module loader available in
the recent browsers versions.

Be aware that the polyfill module does not export the `browser` API object,
but defines the `browser` object in the global namespace (i.e. `window`).

```html
<!DOCTYPE html>
<html>
<head>
<script type="module" src="browser-polyfill.js"></script>
<script type="module" src="background.js"></script>
</head>
<!-- ... -->
</html>
```

```javascript
// In background.js (loaded after browser-polyfill.js) the `browser`
// API object is already defined and provides the promise-based APIs.
browser.runtime.onMessage.addListener(...);
```

### Basic Setup with module bundlers

This library is built as a **UMD module** (Universal Module Definition), and so it can also be used with module bundlers (and explicitly tested on both **webpack** and **browserify**) or AMD module loaders.
Expand Down

0 comments on commit 5c8a743

Please sign in to comment.