npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chrome-dev-webpack-plugin

v0.3.3

Published

A plugin to help streamlining chrome extension development by providing features for maintaining and synchronizing manifest.json.

Downloads

19

Readme

Chrome development plugin for webpack

Adds chrome related development features to webpack. Helps with generating and synchronizing the manifest.json.

License Latest version on npm Build Status Dependency Status Known Vulnerabilities

install

    npm install --save-dev chrome-dev-webpack-plugin

Add the plugin to your webpack configuration file:

//webpack.config.js
var ChromeDevPlugin = require("chrome-dev-webpack-plugin");
var path = require("path");

module.exports = {
  context: path.join(__dirname, "src"),
  entry:  {
    background: [path.join(__dirname, "src", "background.js")],
  },
  output: {
    path: path.join(__dirname, "dist"),
    filename: "[name].bundle.js"
  },
  plugins: [new ChromeDevPlugin()]
}

Features

This plugin helps streamlining chrome extension development by providing features for maintaining and synchronizing the manifest.json.

manifest.json

By default the plugin expects a manifest.json file to be present in the context path. It will generate a new manifest.json in the output.path.

auto completion

The manifest.json file doesn't need to be complete. You can omit some of the keys (name, description, version) as long as they are present in the package.json. The missing keys in the manifest.json will be filled from the project's package.json file.

If the version key is filled, the semver notation will be translated to be compliant with chrome's version notation.

build number

Chrome's versions are composed of up to 4 fields contrarily to the semver notation.

Optionally the 4th field in version can be filled with a build number. It can be generated or set manually.

resources mapping

The plugin will automatically try to map resources with resulting bundles (ex: background.js to background.bundle.js).

Additionally if a resulting bundle ends-up being optimized (using webpack.optimize.CommonsChunkPlugin) all the resulting scripts lists will have the optimized bundles prepended (ex: ['background.js'] to ['vendor.bundle.js', 'background.bundle.js']).

example

{
  "manifest_version": 2,
  "background": {
    "scripts": [
      "background.js" // -> will be translated to "background.bundle.js"
    ]
  },
  "content_scripts": [
    {
      "matches": [
        "*://*/*"
      ],
      "js": [
        "content.js" // -> will be translated to "content.bundle.js"
      ]
    }
  ],
  // The plugin will add the following keys from package.json:
  // - "name": "webpack-chrome-dev-plugin-example-default",
  // - "version": "1.0.0"
}

Options

//webpack.config.js
var ChromeDevPlugin = require("chrome-dev-webpack-plugin");
var path = require("path");

var manifestFile = "manifest.json";
var sourcePath = path.join(__dirname, "src");
var distPath = path.join(__dirname, "dist");
var sourceManifest = path.join(sourcePath, manifestFile); // ./src/manifest.json

var plugins = [
  new ChromeDevPlugin({
    //The source manifest file you want to use for your extension 
    //(defaults to {$context}/"manifest.json")
    entry:sourceManifest,

    //The resulting manifest to emit (defaults to "manifest.json")
    output:manifestFile,
    
    //The package.json file you want to use to sync data from
    package:"./package.json",

    //Sets the logging functions
    log:console.log,
    warm:console.warn,
    error:console.error,

    //Will set the version to 1.2.3 no matter what the manifest.json and
    //the package.json contains
    version: "1.2.3",

    //Will not stamp the resulting manifest.json version with a build 
    //number (default behavior).
    buildId:false,

    //sets the build number to 10 and disables file and autoIncrement.
    buildId: 10,
    buildId: "10",

    //Will use the file "./.build" to read and save the build number.
    //Will also auto-increment the build id for every successfull
    //webpack run.
    buildId:true,
    buildId:".build",
    buildId: {
      file:".build",
      autoIncrement:true,
    }
  }),
];

module.exports = {
  context: path.resolve(sourcePath),
  entry:  {
    background: [path.join(sourcePath, "background.js")],
  },
  output: {
    path: distPath,
    filename: "[name].bundle.js"
  },
  plugins: plugins
}

options

  • entry: the path to the source manifest file (tries to find one if none provided)
  • output: the path to the resulting manifest file (defaults to "manifest.json")
  • package: the path to the source package.json file (defaults to "./package.json")

logging

  • log: the logging function you would like use. Will override warn and error if they are not provided.
  • warn: the logging function you would like use for warnings
  • error: the logging function you would like use for errors

override version

You can completely override the version by specifying a string:

  • version: the version number you want to set in your manifest.json (overrides the version found in json files)

build number

You can choose to stamp the version in your manifest.json with a build number.

To simplify development and deployment the build id can be automatically generated when new files are emitted. First the build Id is read from a file, increased applied and saved. To enable this feature set buildId to true, or to a filename.

If you pass a build number instead, the build number will be used as is.

  • buildId: activates the stamping of the version with a build number.
config = {
  buildId = process.env.TRAVIS_BUILD_NUMBER || "./.BUILDID"
}

default manifest.json

If you don't set the entry option the plugin will try to find a manifest.json file:

  • if another plugin already emits a manifest file (ex:CopyWebpackPlugin) this file will be used as an entry. output will also be automatically filled if it has not been set.
  • otherwise the plugin expects to find a manifest.json file in the context path of your project.

Progress

Here is the status of the features:

  • [x] emit a manifest file.
  • [x] synchronize the missing mandatory keys in the manifest file from a package.json file.
  • [x] if no manifest is given uses the manifest.json emitted by another plugin.
  • [x] if no manifest is given uses the one in the context folder if available.
  • [x] if no package.json is given uses the package.json found in cwd.
  • [x] map all the js files in manifest.json to the resulting compiled bundle files.
  • [x] files split with the webpack.optimize.CommonsChunkPlugin have their dependencies prepended.
  • [x] can add a build number to the version key (ex: 1.2.3.9878)
  • [x] generate a build number from a file or from a given parameter
  • [x] auto increments the build number and saves it to file by default
  • [x] examples
  • [x] testing with examples
  • [ ] automatically add files listed in manifest.json to the build pipeline (if they are not already there).
  • [ ] automatically reset the build number if a reset is requested on major, minor, or patch increase.

License

Copyright (c) 2017, Slawomir CALUCH

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.