Skip to content

Webpack plugin to emit files. The only one that does it right.

License

Notifications You must be signed in to change notification settings

Kir-Antipov/emit-file-webpack-plugin

Repository files navigation

Emit file plugin for Webpack

npm: emit-file-webpack-plugin License

Webpack plugin to emit files. The only one that does it right.

Installation

  • With npm:
npm i --save-dev emit-file-webpack-plugin
  • With yarn:
yarn add --dev emit-file-webpack-plugin

Usage

webpack.config.js

const webpack = require('webpack');
const EmitFilePlugin = require('emit-file-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    new EmitFilePlugin({
      // OPTIONAL: defaults to the Webpack output path.
      // Output path.
      // Can be relative (to Webpack output path) or absolute.
      path: `.`,

      // REQUIRED.
      // Name of the file to add to assets.
      // If hash option is enabled add `[hash]` here to choose where to insert the compilation hash.
      // See the hash option for more information.
      filename: `index.js`,

      // REQUIRED.
      // File content. Can be either a string, a buffer, or a (asynchronous) function.
      // If the resulting object is not a string or a buffer, it will be converted
      // to string via `.toString` (if the function was overridden) or `JSON.stringify`.
      content: `console.log('Hello world!');`,

      // OPTIONAL: defaults to the webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL.
      // Asset processing stage.
      // https://webpack.js.org/api/compilation-hooks/#processassets
      stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,

      // OPTIONAL: defaults to false.
      // Adds the compilation hash to the filename. You can either choose within the filename
      // where the hash is inserted by adding `[hash]` i.e. `test.[hash].js` or the hash will be
      // appended to the end of the file i.e. `test.js?hash`.
      hash: false
    })
  ]
};