From a3007b5243ecfa01b9941b78c4991b72e1f74fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Sim=C3=B5es?= Date: Sat, 31 Dec 2016 10:18:44 -0200 Subject: [PATCH] Updates the README with instructions about the content scripts resolves #4 --- README.md | 33 +++++++++++++++++++++++++++++++++ utils/webserver.js | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) 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) {