Skip to content

Commit

Permalink
updated README. Made sure it can be loaded as a standalone script still
Browse files Browse the repository at this point in the history
  • Loading branch information
mikob committed May 26, 2020
1 parent 1909970 commit 6a48d8f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ Here's [a blog post explaining it](https://60devs.com/hot-reloading-for-chrome-e
- Works by checking timestamps of files
- Supports nested directories
- Automatically disables itself in production
- And it's just a <a href="https://github.com/xpl/crx-hotreload/blob/master/hot-reload.js">50 lines of code</a>!
- And it's just <a href="https://github.com/xpl/crx-hotreload/blob/master/hot-reload.js">50 lines of code</a>!

## Options

| Name | Value | Description |
|--------------|----------------------------|----------------------------------------|
| `reloadTab` | `boolean` (default: true) | reload the active tab when crx changes.|

## How To Use

Expand All @@ -31,4 +37,10 @@ It is also available as NPM module:
npm install crx-hotreload
```

Then use a `require` (or `import`) to execute the script.
In your script:
```
const hotReload = require('crx-hotreload');
hotReload.default({
reloadTab: false
});
```
12 changes: 11 additions & 1 deletion hot-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,23 @@ const watchChanges = (dir, reloadTab, lastTimestamp) => {

}

const defaultOpts = {
reloadTab: true
};

if (typeof module === 'object') {
exports.default = (opts) => {
const combinedOpts = Object.assign({}, defaultOpts, opts);
chrome.management.getSelf (self => {
if (self.installType === 'development') {
chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir, opts.reloadTab))
chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir, combinedOpts.reloadTab))
}
})
}
} else {
chrome.management.getSelf (self => {
if (self.installType === 'development') {
chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir, defaultOpts.reloadTab))
}
})
}

0 comments on commit 6a48d8f

Please sign in to comment.