mv3-hot-reload
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -10,3 +10,3 @@ #!/usr/bin/env node | ||
const WebSocket = require("ws"); | ||
const lodash_1 = require("lodash"); | ||
const debounce_1 = __importDefault(require("lodash/debounce")); | ||
const path_1 = __importDefault(require("path")); | ||
@@ -39,10 +39,9 @@ const utils_1 = require("../src/utils"); | ||
wss.on('connection', (ws) => { | ||
chokidar_1.default | ||
.watch(directoryPath, { | ||
const watcher = chokidar_1.default.watch(directoryPath, { | ||
ignoreInitial: true, | ||
}) | ||
.on('all', lodash_1.debounce((_, path) => { | ||
}); | ||
watcher.on('all', debounce_1.default((_, path) => { | ||
if (!excludePaths.includes(path)) { | ||
if (!quiet) { | ||
console.log('file change detected.'); | ||
console.log(`File change detected. Path: ${path}`); | ||
} | ||
@@ -52,2 +51,5 @@ ws.send(utils_1.Message.FileChange); | ||
}, 500)); | ||
ws.on('close', () => { | ||
watcher.close(); | ||
}); | ||
}); |
{ | ||
"name": "mv3-hot-reload", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Enable hot reloading for content script and background script in MV3.", | ||
@@ -30,3 +30,3 @@ "bin": "./out/bin/mv3-hot-reload.js", | ||
"@types/jest": "^26.0.24", | ||
"@types/lodash": "^4.14.171", | ||
"@types/lodash": "^4.14.178", | ||
"@types/node": "^16.0.1", | ||
@@ -33,0 +33,0 @@ "@types/ws": "^7.4.6", |
@@ -11,6 +11,28 @@ # mv3-hot-reload | ||
## Usage | ||
## How to use | ||
### 1. Import files into your background script (service worker) and content script | ||
### 1. Inject the code for hot reloading | ||
#### Leverage Webpack's "multi-main entry" (Recommended) | ||
```ts | ||
// webpack.config.ts | ||
const isDev = process.env.NODE_ENV === 'development' | ||
function getEntry(name: string) { | ||
return [path.join(srcDir, name), ...(isDev ? [`mv3-hot-reload/${name}`] : [])] | ||
} | ||
const webpackConfig = { | ||
// ... | ||
entry: { | ||
// ... | ||
background: getEntry('background'), | ||
content: getEntry('content'), | ||
}, | ||
} | ||
``` | ||
#### 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'`. | ||
@@ -42,3 +64,3 @@ | ||
## mv3-hot-reload.config.js | ||
## mv3-hot-reload.config.js (Optional) | ||
@@ -45,0 +67,0 @@ ```js |
7628
89
107