Skip to content

Commit

Permalink
Create README
Browse files Browse the repository at this point in the history
  • Loading branch information
pacexy committed Jul 10, 2021
1 parent f8b6908 commit 8a85ffe
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# mv3-hot-reload

Enable hot reloading for content script and background script (service worker) in MV3.

## Install

```
yarn add mv3-hot-reload
```

## Usage

### 1. Import files into your background script (service worker) and content script

The code for hot reloading will only execute when `process.env.NODE_ENV === 'development'`.

```ts
// background.ts
import 'mv3-hot-reload/background'

// your code...
```

```ts
// content.ts
import 'mv3-hot-reload/content'

// your code...
```

### 2. Add a script to your `package.json` and run it before development

Example:

```diff
"watch:src": "webpack --config webpack/webpack.dev.js --watch",
+ "watch:dist": "mv3-hot-reload",
+ "dev": "concurrently yarn:watch:*",
```

## mv3-hot-reload.config.js

```js
module.exports = {
// Specify the port of hot reload server, defaults to 9012
port: 9012,
// Specify the directory you want to watch, defaults to 'dist
directory: 'dist',
// Specifies an array of filenames that should be excluded in watched directory
exclude: [],
}
```

## Example

[pacexy/chrome-extension-typescript-starter](https://github.com/pacexy/chrome-extension-typescript-starter)

## Credits

The implementation of hot reloading in mv3 refers to [theprimone/violet](https://github.com/theprimone/violet).

## License

MIT
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"name": "mv3-hot-reload",
"version": "0.2.0",
"description": "Enable hot reloading for MV3.",
"description": "Enable hot reloading for content script and background script in MV3.",
"bin": "./out/bin/mv3-hot-reload.js",
"repository": "https://github.com/pacexy/mv3-hot-reload",
"author": "pacexy",
"license": "MIT",
"private": false,
"keywords": [
"chrome",
"extension",
"hot reload",
"automatic reload",
"reload"
],
"scripts": {
"dev": "tsc -w",
"prepare": "npm run build",
Expand Down

0 comments on commit 8a85ffe

Please sign in to comment.