• This repository has been archived on 06/May/2019
  • Stars
    star
    374
  • Rank 114,346 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔥 Hot reloading while developing Chrome extensions with webpack 🔥

Disclaimer

This repository and package are archived, for now on it's recommended to use webpack-extension-reloader

Webpack Chrome Extension Reloader

A Webpack plugin to enable hot reloading while developing Chrome extensions.

npm version Build Status NPM Downloads Codacy Badge Greenkeeper badge

Installing

npm

npm install webpack-chrome-extension-reloader --save-dev

yarn

yarn add webpack-chrome-extension-reloader --dev

Solution for ...

Have your ever being annoyed while developing a Google Chrome extension, and being unable to use webpack-hot-server because it's not a web app but a browser extension?

Well, now you can do hot reloading!

What it does?

Basically something similar to what the webpack hot reload middleware does. When you change the code and the webpack trigger and finish the compilation, your extension is notified and then reloaded using the chrome.runtime API. Check out Hot reloading Chrome extensions using Webpack for more background.

How to use

Using as a plugin

Add webpack-chrome-extension-reloader to the plugins section of your webpack configuration file.

const ChromeExtensionReloader  = require('webpack-chrome-extension-reloader');

plugins: [
    new ChromeExtensionReloader()
]

You can also set some options (the following are the default ones):

// webpack.dev.js
module.exports = {
  mode: "development", // The plugin is activated only if mode is set to development
  watch: true,
  entry: {
      'content-script': './my-content-script.js',
      background: './my-background-script.js'
  },
  //...
  plugins: [
      new ChromeExtensionReloader({
        port: 9090, // Which port use to create the server
        reloadPage: true, // Force the reload of the page also
        entries: { // The entries used for the content/background scripts
          contentScript: 'content-script', // Use the entry names, not the file name or the path
          background: 'background' // *REQUIRED
        }
      })
  ]
}

And then just run your application with Webpack in watch mode:

NODE_ENV=development webpack --config myconfig.js --mode=development --watch 

Important: You need to set --mode=development to activate the plugin (only if you didn't set on the webpack.config.js already) then you need to run with --watch, as the plugin will be able to sign the extension only if webpack triggers the rebuild (again, only if you didn't set on webpack.config).

Multiple Content Script support

If you use more than one content script in your extension, like:

entry: {
    'my-first-content-script': './my-first-content-script.js',
    'my-second-content-script': './my-second-content-script.js',
    // and so on ...
    background: './my-background-script.js'
}

You can use the entries.contentScript options as an array:

plugins: [
    new ChromeExtensionReloader({
      entries: { 
        contentScript: ['my-first-content-script', 'my-second-content-script', /* and so on ... */],
        background: 'background'
      }
    })
]

CLI

If you don't want all the plugin setup, you can just use the client that comes with the package.
You can use by intalling the package globably, or directly using npx after installing locally the plugin:

npx wcer

If you run directly, it will use the default configurations, but if you want to customize you can call it with the following options:

npx wcer --config wb.config.js --port 9080 --no-page-reload --content-script my-content.js --background bg.js 

If you have multiple content scripts, just use comma (with no spaces) while passing the option

npx wcer --content-script my-first-content.js,my-second-content.js,my-third-content.js 

Client options

name default description
--help Shows this help
--config webpack.config.js The webpack configuration file path
--port 9090 The port to run the server
--content-script content-script The entry/entries name(s) for the content script(s)
--background background The entry name for the background script
--no-page-reload Disable the auto reloading of all pages which runs the plugin

Every time webpack triggers a compilation, the extension reloader are going to do the hot reload :)
Note: the plugin only works on development mode, so don't forget to set the NODE_ENV before run the command above

Contributing

Please before opening any issue or pull request check the contribution guide.

Building and Testing

Inside this repository have an example plugin, so you can test and see it working After clone the repo, run:

yarn build

And then run:

yarn sample

This will make the webpack run in watch mode for the sample plugin source and output the built files on the "dist" directory. Load the extension (the files in "sample/dist" directory) in Chrome using the "load unpacked extension", open a new tab in any site and open the developer panel on it. Watch the dev. tools console tab, and do some changes on the background or content script. Voila!

Note: You must have both background and content scripts for this plugin to work, and they must be specified in separate entry chunks in your webpack config.

The reloading script will be injected only on the main entries chunks (in background and content script). Any other chunks will be ignored.

License

This project is under the MIT LICENSE

More Repositories

1

webpack-extension-reloader

A upgrade from 🔥webpack-chrome-extension-reloader🔥, now on all browsers
TypeScript
483
star
2

leaflet-ant-path

🌿🐜 Creates a leaflet polyline with a 'ant-path' animated flux
JavaScript
422
star
3

progressive-image-loading

A live example of progressive image loading strategies
JavaScript
50
star
4

react-webpack-lazy-loading

A sample of lazy loading using React and Webpack
JavaScript
36
star
5

react-instascan

Port of Instascan library to React ⚛️
JavaScript
23
star
6

react-redux-webpack-lazy-loading

The follow up example of react-webpack-lazy-loading now using Redux
JavaScript
17
star
7

findabike

🚲🔍A app to search for shared bike stations in the chosen city
JavaScript
12
star
8

react-redux-lazy

Lazy Redux connectors for React
JavaScript
10
star
9

leaflet-ant-path-bower

The bower repository for the Leaflet plugin 'Ant Path'
7
star
10

angular-amd-styleguide

A styleguide for AngularJS using asynchronous module definition
7
star
11

socket-serv

A simple socket server in C++
C++
5
star
12

gamedev

JavaScript
4
star
13

webpack-dll-sample

A sample of DllPlugin usage
JavaScript
4
star
14

socket-cli

A simple socket client in C++
C++
3
star
15

Picasso

Framework to build dinamic forms using MVC
JavaScript
3
star
16

Wind-Potion

A RESTful API to use with Python Tornado and SQLAlchemy Elixir
Python
2
star
17

instascan-umd

A pre-compiled, minified version, UMD compatible port of Instascan
JavaScript
2
star
18

pygameoflife

PyGame Of Life - Game based in "Game of life" by John Conway
Python
1
star
19

react-duck-typing

A sample of duck typing using React
JavaScript
1
star
20

JS-GO

A Javascript mini-framework giving objects custom attribute types, with builder, setters, getters, validations, casters and collections to group this objecs with a singular query language
JavaScript
1
star
21

Voipzilla-API-for-PHP

A class to connect, send commands and receive data using the voipzilla socket API
PHP
1
star
22

Cardapio-RU-UECE

Extensão do Firefox que notifica sobre cardápio do restaurante universitário da Universidade Estadual do Ceará
JavaScript
1
star