Home

Awesome

webpack-easy-config

Unix Build status Code Coverage Version Support on gitter chat

Webpack config, made easy

Ideas:

Note that you can provide normal configuration before or after special keys handled by this package. Order should be respected.

Installation

$ npm install webpack-easy-config

Usage

import webpackEasyConfig from "webpack-easy-config"

export default webpackEasyConfig({
  include: "src", // relative to process.cwd(), or can be absolute
  // can also be an array like
  // include: [ "src", "web_modules" ],
  loaders: {
    css: {
      "postcss-loader": true,
      "css-loader": {
        modules: true,
        localIdentName: "[path][name]--[local]--[hash:base64:5]",
      },
      "style-loader": true,
    },
    "html|ico|jpe?g|png|gif": {
      "file-loader": {
        name: "[path][name].[ext]",
        context: "src",
      },
    },
    "svg": [ "svgo-loader", "raw-loader" ],
    "woff2|woff|ttf|eot": "file-loader",
  },
  extract: {
    css: {
      filename: "[name].[hash].css",
      disable: process.argv.indexOf("--dev") > -1,
    },
  },
})

Will generate the equivalent config

export default {
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract(
          "style-loader",
          "css-loader" +
            "?modules" +
            "&localIdentName=[path][name]--[local]--[hash:base64:5]" +
          "!postcss-loader!"
        ),
        include: `/absolute/path/to/src`,
      },
      {
        test: /\.(html|ico|jpe?g|png|gif)$/,
        loader:
          "file-loader" +
          "?name=[path][name].[ext]" +
          "&context=src",
        include: `/absolute/path/to/src`,
      },
      {
        test: /\.svg$/,
        loader: "raw-loader!svgo-loader",
        include: `/absolute/path/to/src`,
      },
      {
        test: /\.(woff2|woff|ttf|eot)$/,
        loader: "file-loader",
        include: `/absolute/path/to/src`,
      },
    ],
  },
  plugins: [
    new ExtractTextPlugin("[name].[hash].css", {
      disable: process.argv.indexOf("--dev") > -1
    })
  ],
}

CONTRIBUTING

CHANGELOG

LICENSE