diff --git a/README.md b/README.md index 30d4ad5..dd0caee 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,39 @@ You can run the dev mode on other port if you want. Just specify the env var `po $ PORT=6002 npm run start ``` +##Content Scripts + +Although this boilerplate uses the webpack dev server, it's also prepared to write all your bundles files on the disk at every code change, so you can point, on your extension manifest, to your bundles that you want to use as [content scripts](https://developer.chrome.com/extensions/content_scripts), but you need to exclude these entry points from hot reloading [(why?)](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/issues/4#issuecomment-261788690). To do so you need to expose which entry points are content scripts on the `webpack.config.js` using the `chromeExtensionBoilerplate -> notHotReload` config. Look the example below. + +Let's say that you want use the `myContentScript` entry point as content script, so on your `webpack.config.js` you will configure the entry point and exclude it from hot reloading, like this: + +```js +{ + … + entry: { + myContentScript: "./src/js/myContentScript.js" + }, + chromeExtensionBoilerplate: { + notHotReload: ["myContentScript"] + } + … +} +``` + +and on your `src/manifest.json`: + +```json +{ + "content_scripts": [ + { + "matches": ["https://www.google.com/*"], + "js": ["myContentScript.bundle.js"] + } + ] +} + +``` + ##Packing After the development of your extension run the command diff --git a/utils/webserver.js b/utils/webserver.js index 07ef7c7..0fb5442 100644 --- a/utils/webserver.js +++ b/utils/webserver.js @@ -6,7 +6,8 @@ var WebpackDevServer = require("webpack-dev-server"), require("./prepare"); -var excludeEntriesToHotReload = (config.excludeEntriesToHotReload || []); +var options = (config.chromeExtensionBoilerplate || {}); +var excludeEntriesToHotReload = (options.notHotReload || []); for (var entryName in config.entry) { if (excludeEntriesToHotReload.indexOf(entryName) === -1) {