generate-file-plugin

0.1.2 • Public • Published

The generate-file-plugin for WebPack lets you create a static file by running a javascript file as part of your build. This can be used to output a custom index.html or manifest.json.

Installation

npm install --save-dev --save-exact generate-file-plugin
// webpack.config.js

var GenerateFilePlugin = require('generate-file-plugin');

...
plugins: [
    new GenerateFilePlugin('index.html.js')
]
// index.html.js

module.exports = "<!doctype html><body>" +
    "The current version is " + module.compilation.hash +
"</body>";

## Options

new GenerateFilePlugin(filename, options)


* `filename` is the name of the javascript file to run, relative to the webpack context.
* `options.to` is the name of the output file to create, relative to the build directory.
If not specified the default value of `options.to` is calculated by removing
one file extension from `filename` (e.g. `index.html.js` becomes `index.html`)

## Usage

You can use multiple `GenerateFilePlugin`s if you want to generate multiple files,
each should be a javascript file that sets `module.exports` to a string. That
string will be written verbatim to the output file.

Within the module being compiled this plugin sets `module.compilation` to the
current WebPack compilation. This is particularly useful if you want to use
`compilation.assets` or `compilation.hash` as part of the file you output.

## Limitations

* Currently the file has to be pure javascript and executable by node, it would
  be nice to allow you to run programs compiled by webpack (cf. the
  static-render-webpack-plugin)
* Currently only the top-level file is watched for changes, files included
  transitively will not trigger a re-build.

Readme

Keywords

none

Package Sidebar

Install

npm i generate-file-plugin

Weekly Downloads

14

Version

0.1.2

License

MIT

Last publish

Collaborators

  • cirwin