From 1974e3cea638fe0b6a1fc6ad8acf0543e108efe7 Mon Sep 17 00:00:00 2001 From: Martin Giger Date: Thu, 29 Sep 2016 12:11:56 +0200 Subject: [PATCH] Improve documentation and move build target to addon folder --- webpack-modules/README.md | 20 +++++++++++++----- .../{ => addon}/dist/icons/leftpad-32.png | Bin .../{ => addon}/dist/manifest.json | 0 .../{ => addon}/dist/popup/left-pad.html | 0 webpack-modules/package.json | 2 -- webpack-modules/webpack.config.js | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) rename webpack-modules/{ => addon}/dist/icons/leftpad-32.png (100%) rename webpack-modules/{ => addon}/dist/manifest.json (100%) rename webpack-modules/{ => addon}/dist/popup/left-pad.html (100%) diff --git a/webpack-modules/README.md b/webpack-modules/README.md index 3c042d8..de261bd 100644 --- a/webpack-modules/README.md +++ b/webpack-modules/README.md @@ -1,15 +1,25 @@ # WebExtension Webpack Example -A minimal example of how to use npm modules from within a WebExtension. +A minimal example of how to use [webpack](https://webpack.github.io) to package +[npm](https://npmjs.com) modules so they can be used in a WebExtension. The example package used by this extension is `left-pad`, an essential package in almost any situation. ## What it does -This setup takes a background and a content script entrypoint and outputs them -to their respective target. +This example shows how to use a node module in a background and a content script. +It defines two build targets in [webpack.config.js](webpack.config.js), they each +generate a file that includes all modules used the entry point and store it in +the [addon](addon/) folder. The first one starts with [background_scripts/background.js](background_scripts/background.js) +and stores it in `addon/background_scripts/index.js`. The other one does the +same for [popup/left-pad.js](popup/left-pad.js) and stores it in `addon/popup/index.js`. + +The extension includes a browser action with a popup, which provides an UI for +running left-pad on a string with a chosen character. The operation can either be +performed with the left-pad module included in the panel's script or in the +background script. ## What it could do This could be infinitely extended - injecting global jQuery, adding babel, -react/jsx, css modules, image processing and so on. +react/jsx, css modules, image processing, local modules and so on. ## What it shows @@ -20,7 +30,7 @@ react/jsx, css modules, image processing and so on. - `npm install` - `npm run build` -The WebExtension in the [dist](dist/) folder should now work. +The WebExtension in the [addon](addon/) folder should now work. ## What about Browserify? Browserify works just as well as webpack for extensions, in the end it's a diff --git a/webpack-modules/dist/icons/leftpad-32.png b/webpack-modules/addon/dist/icons/leftpad-32.png similarity index 100% rename from webpack-modules/dist/icons/leftpad-32.png rename to webpack-modules/addon/dist/icons/leftpad-32.png diff --git a/webpack-modules/dist/manifest.json b/webpack-modules/addon/dist/manifest.json similarity index 100% rename from webpack-modules/dist/manifest.json rename to webpack-modules/addon/dist/manifest.json diff --git a/webpack-modules/dist/popup/left-pad.html b/webpack-modules/addon/dist/popup/left-pad.html similarity index 100% rename from webpack-modules/dist/popup/left-pad.html rename to webpack-modules/addon/dist/popup/left-pad.html diff --git a/webpack-modules/package.json b/webpack-modules/package.json index 5962183..c4915ed 100644 --- a/webpack-modules/package.json +++ b/webpack-modules/package.json @@ -2,12 +2,10 @@ "name": "webpack-webextension", "version": "1.0.0", "description": "A minimal example of how to use npm modules from within a WebExtension.", - "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack" }, - "author": "Martin Giger (https://humanoids.be)", "license": "MPL-2.0", "devDependencies": { "webpack": "^1.13.1" diff --git a/webpack-modules/webpack.config.js b/webpack-modules/webpack.config.js index 9997743..03bf28d 100644 --- a/webpack-modules/webpack.config.js +++ b/webpack-modules/webpack.config.js @@ -4,7 +4,7 @@ module.exports = { popup: "./popup/left-pad.js" }, output: { - path: "dist", + path: "addon", filename: "[name]/index.js" } };