WebPack - Plugin (Task)

About

Plugins are build tasks.

Steps

  • require() it
  • Add it to the plugins array.
  • Call it with the new operator because a plugin can be use multiple times with different config.

Example

WebPack - webpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm
const webpack = require('webpack'); //to access built-in plugins
const path = require('path');

const config = {
  entry: './path/to/my/entry/file.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'my-first-webpack.bundle.js'
  },
  module: {
    rules: [
      { test: /\.txt$/, use: 'raw-loader' }
    ]
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin(),
    new HtmlWebpackPlugin({template: './src/index.html'})
  ]
};

module.exports = config;

List

https://webpack.js.org/plugins

Documentation / Reference







Share this page:
Follow us:
Task Runner