GithubHelp home page GithubHelp logo

zhouguoqing917 / chrome-extension-reloader-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from njzydark/chrome-extension-reloader-webpack-plugin

0.0 1.0 0.0 71 KB

A webpack plugin to auto reloader when content scripts change

License: MIT License

TypeScript 100.00%

chrome-extension-reloader-webpack-plugin's Introduction

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

chrome-extension-reloader-webpack-plugin's People

Contributors

njzydark avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.