JSPM

chrome-extension-reloader-webpack-plugin

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q37490F
  • License MIT

A webpack plugin to auto reloader when content scripts change

Package Exports

  • chrome-extension-reloader-webpack-plugin

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chrome-extension-reloader-webpack-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

chrome-extension-reloader-webpack-plugin

A webpack plugin to auto reloader when content scripts change

Features

  • Support auto reload when content scripts change
  • Support dynamic generate content scripts

Usage

npm i -D chrome-extension-reloader-webpack-plugin

add to webpack config

...
import { ChromeExtensionReloaderWebpackPlugin } from 'chrome-extension-reloader-webpack-plugin';

import pkg from '../package.json';

const chromeMainfestVersion = pkg.chromeExtension['mainifest-version'];
...

{
  plugins:[
    ...
    new ChromeExtensionReloaderWebpackPlugin({
      manifestPath: path.resolve(__dirname, '../src/manifest.v2.json'),
      entry: {
        background: path.resolve(
          __dirname,
          chromeMainfestVersion === 3 ? '../src/background/v3.ts' : '../src/background/v2.ts'
        ),
        popup: path.resolve(__dirname, '../src/popup/index.tsx'),
        options: path.resolve(__dirname, '../src/options/index.tsx'),
        contentScriptDirPath: path.resolve(__dirname, '../src/contents')
      }
    }),
    ...
  ]
}

Options

  • host - default localhost
  • port - default 9988
  • manifestPath - when manifest change, reloader extension
  • entry
    • background - required background file path
    • popup - popup file path
    • options - options file path
    • contentScriptDirPath

ContentScriptDirPath

All content script in this directory will dynamic generate(There can only be two levels of nesting

If the contentScriptDirPath is contents:

contents/test.js 🆗

contents/test/index.js 🆗

contents/test/a.js 🚫

contents/test/t/index.js 🚫

PS

Because background and content script file can't import other file, so this plugin will override some webpack options for chrome extension dev

  • devServer
  • devtool
  • optimization
    • splitChunks
    • runtimeChunk

devServer

{
  host: "localhost",
  port: 8080,
  ...your options,
  injectClient: false,
  injectHot: false,
  hot: true,
  writeToDisk: true,
  disableHostCheck: true,
}

devtool

For debug by vscode, this options will use inline-source-map

optimization

Because background js can't import file, so this option will use:

splitChunks: {
  cacheGroups: {
    vendor: {
      name: "vendor",
      chunks(chunk) {
        return ["popup", "options"].includes(chunk.name);
      },
      test: /[\\/]node_modules[\\/]/,
      priority: -10,
    },
    common: {
      chunks(chunk) {
        return ["popup", "options"].includes(chunk.name);
      },
      minChunks: 2,
      priority: -20,
      reuseExistingChunk: true,
    },
  },
},
runtimeChunk: false,

Projects