Catalog npm
Back to packageRELEASE DETAILS

2.3.2

npm

@0xdv/webpack-userscript

A Webpack4+ plugin for userscript projects.

greasemonkeytampermonkeyuserscriptwebpack
Published29 Nov 2019
Direct dependencies17
Transitive dependenciesNot calculated

README

Current package documentation

webpack-userscript

Build Status JavaScript Style Guide npm Gitmoji

A Webpack4+ plugin for userscript projects. 🙈

The package has been renamed from webpack-tampermonkey.

Features

  • Combine your userscript development with Webpack

    With powerful Webpack support, you can even package everything in your userscript, e.g. icons and json data.

  • Ability to generate userscript headers
  • Ability to generate both .user.js and .meta.js

    .meta.js is used for update check containing headers only.

  • Properly track files in watch mode

    Including external header files and package.json.

Installation

npm i webpack-userscript -D

Usage

webpack.config.js

Include the plugin in the webpack.config.js as the following example.

const WebpackUserscript = require('webpack-userscript')

module.exports = {
  plugins: [
    new WebpackUserscript()
  ]
}

Examples

Hot Development

The following example can be used in development mode with the help of webpack-dev-server.

webpack-dev-server will build the userscript in watch mode. Each time the project is built, the buildNo variable will increase by 1.

In the following configuration, a portion of the version contains the buildNo; therefore, each time there is a build, the version is also increased so as to indicate a new update available for the script engine like Tampermonkey or GreaseMonkey.

After the first time starting the webpack-dev-server, you can install the script via http://localhost:8080/<project-name>.user.js (the URL is actually refered to your configuration of webpack-dev-server). Once installed, there is no need to manually reinstall the script until you stop the server. To update the script, the script engine has an update button on the GUI for you.

  • webpack.config.dev.js
const path = require('path')
const WebpackUserscript = require('webpack-userscript')
const dev = process.env.NODE_ENV === 'development'

module.exports = {
  mode: dev ? 'development' : 'production',
  entry: path.resolve(__dirname, 'src', 'index.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '<project-name>.user.js'
  },
  devServer: {
    contentBase: path.join(__dirname, 'dist')
  },
  plugins: [
    new WebpackUserscript({
      headers: {
        version: dev ? `[version]-build.[buildNo]` : `[version]`
      }
    })
  ]
}

Other

Other examples can be found under the test fixture folder.

Configuration

WebpackUserscript

The WebpackUserscript constructor has the following signature.

new WebpackUserscript(options)

options

Also see the schema of options.

type WebpackUserscriptOptions =
  WPUSOptions |
  HeaderFile |   // shorthand for WPUSOptions.headers
  HeaderProvider // shorthand for WPUSOptions.headers

WPUSOptions

interface WPUSOptions {
  headers: HeaderFile | HeaderProvider | HeaderObject

  /**
   * Output *.meta.js or not
   */
  metajs: boolean

  /**
   * Rename all .js files to .user.js files.
   */
  renameExt: boolean

  /**
   * Prettify the header
   */
  pretty: boolean
}

HeaderFile

A path to a js or json file which exports a header object or a header provider function.

type HeaderFile = string

HeaderProvider

A function that returns a header object.

type HeaderProvider = (data: DataObject) => HeaderObject

HeaderObject

A header object, whose leaves are webpack-like template strings in [<var_name>] format. Available variables can be found at DataObject.

Also see explicit-config/webpack.config.js and template-strings/webpack.config.js.

type HeaderObject = Record<string, string | Array<string>>

DataObject

Local variables used to interpolate the templates of a HeaderObject.

interface DataObject {
  /**
   * Hash of Webpack compilation
   */
  hash: string

  /**
   * Webpack chunk hash
   */
  chunkHash: string

  /**
   * Webpack chunk name
   */
  chunkName: string

  /**
   * Entry file path, which may contain queries
   */
  file: string

  /**
   * Query string
   */
  query: string

  /**
   * Build number
   */
  buildNo: number

  /**
   * Info from package.json
   */
  name: string
  version: string
  description: string
  author: string
  homepage: string
  bugs: string // URL
}

Also see template-strings/webpack.config.js.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 18

Native requirements
17 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@tkausl/userscript-meta
Environment
{
  "local_name": "@tkausl/userscript-meta",
  "alias": false,
  "peer_metadata": null
}
^1.0.2runtime
schema-utils
Environment
{
  "local_name": "schema-utils",
  "alias": false,
  "peer_metadata": null
}
^1.0.0runtime
webpack-sources
Environment
{
  "local_name": "webpack-sources",
  "alias": false,
  "peer_metadata": null
}
^1.3.0runtime
@semantic-release/git
Environment
{
  "local_name": "@semantic-release/git",
  "alias": false,
  "peer_metadata": null
}
^7.0.16development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^5.15.3development
eslint-config-standard
Environment
{
  "local_name": "eslint-config-standard",
  "alias": false,
  "peer_metadata": null
}
^12.0.0development
eslint-plugin-import
Environment
{
  "local_name": "eslint-plugin-import",
  "alias": false,
  "peer_metadata": null
}
^2.16.0development
eslint-plugin-node
Environment
{
  "local_name": "eslint-plugin-node",
  "alias": false,
  "peer_metadata": null
}
^8.0.1development
eslint-plugin-promise
Environment
{
  "local_name": "eslint-plugin-promise",
  "alias": false,
  "peer_metadata": null
}
^4.0.1development
eslint-plugin-standard
Environment
{
  "local_name": "eslint-plugin-standard",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development
gitmoji-cli
Environment
{
  "local_name": "gitmoji-cli",
  "alias": false,
  "peer_metadata": null
}
^1.9.2development
memory-fs
Environment
{
  "local_name": "memory-fs",
  "alias": false,
  "peer_metadata": null
}
^0.4.1development
semantic-release
Environment
{
  "local_name": "semantic-release",
  "alias": false,
  "peer_metadata": null
}
^15.13.18development
semantic-release-gitmoji
Environment
{
  "local_name": "semantic-release-gitmoji",
  "alias": false,
  "peer_metadata": null
}
^1.3.2development
tape
Environment
{
  "local_name": "tape",
  "alias": false,
  "peer_metadata": null
}
^4.10.1development
webpack
Environment
{
  "local_name": "webpack",
  "alias": false,
  "peer_metadata": null
}
^4.29.6development
webpack-cli
Environment
{
  "local_name": "webpack-cli",
  "alias": false,
  "peer_metadata": null
}
^3.3.0development
webpack
Environment
{
  "local_name": "webpack",
  "alias": false,
  "peer_metadata": null
}
^4.0.0peer

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-tr2JM6KW6GRepCp7vCnF0Fp9+bi78U4xvegbURv8v5RJ5an58d7OW+VHAeLMNMBa1zx0rhCepmo/vP7CyQBZZQ==",
  "shasum": "2f4d6b9ddbe0f5e6441c60424d743faf9a9b5329",
  "tarball": "https://registry.npmjs.org/@0xdv/webpack-userscript/-/webpack-userscript-2.3.2.tgz",
  "fileCount": 9,
  "unpackedSize": 16537,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd4X3ACRA9TVsSAnZWagAAze0P/R6V9yyOVSSdqi6yB2MD\nkXImF+Qdl+rYC7OkZS6jMklq8+m7rU0d/afdA2QsLmScDEp2VF9hxO7basH0\nOOFfZWEckypQVPnZ8MZwW8eore5hKpFmq1Cvt86ZPfGlM+Pqm2966Vb+uwL3\n5bqX3obHXPHwGgUXtXSWFJ1XrFH7Rw8wMPC2kR1CFK8MftDFRK2hP/RriBX8\nhEjzUgcc+lmD2wSU7lJJEdgNc6JYGxpZZOP04yiERw6xZMN3vVxg6IkSR9jN\npkQsZq9dSIn9a+UWBHDzYZH4uJfNgJ1ePNIcqcz3LKnqq+6ccHbH0gDC5K2s\nTjnAeUJk4zr4KMTkPuD8NSSSynYt376VGeUhWCoiHZ9zEQaxy12719exjVCD\nDtqu3NiENTrKV2cDtH/IHItuXom+tkqAmO889LSGcbG2i0lyWHAYA6T7RCfy\naA51mthh8V41aUef26pSMHabtJ6UU5X3DaGai9XmpF0a/vhYJKckIB0qWObN\n9D8ROVVMMnGzrsaGqq3GU4nQjh4wJxNa4/ngI0z4PjWJV5n7KOmFV64A2gf9\ntCIq8QVVcWvppcGVojyN5GZDz4M9BhCB8UROkDuoj6w7Pgfc6qMiGcwYoXEX\n3q2hqyxaoIgldwOTQkdjGJFqXSD0fuz1lF+wCLHsrVBhmIoke8C76xHdDAMa\ngiUb\r\n=R2D8\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQDPwK7vMmpN2wZ/GGzC1goBTyTWHzSZlBsRvixufDrn/gIgO06aRlRZuqkockuXp9ZzThudt+GWalMlK/xhjnOh/gI="
    }
  ]
}

Repository

PENDING
0xdv/webpack-userscript

Shared repository data · GitHub

License detected in repository
Not collected

Repository

NOT_FOUND
0xdv/webpack-tampermonkey

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:06 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:8546525b2d2c515bfcde457278b61e1105a9b5ff83067bc02ef409e536cd1ed9

Other collected versions

2.3.128 NovView all collected versions →