0.2.0 • Published 8 years ago
webpack-blocks-happypack v0.2.0
webpack-blocks-happypack
A webpack block that adds happypack support to your webpack config.
This package is based on the PR by @fenos on the official webpack-blocks repository.
Install
$ npm install --save-dev webpack-blocks-happypackUsage
Basic
const { createConfig } = require('@webpack-blocks/webpack2')
const babel = require('@webpack-blocks/babel6')
const cssModules = require('@webpack-blocks/css-modules')
const extractText = require('@webpack-blocks/extract-text2')
const happypack = require('webpack-blocks-happypack')
const config = createConfig([
cssModules(),
happypack([
// these will be happypack'd
extractText(),
babel(),
]),
])Configuration
const config = createConfig([
happypack([
babel(),
], {
// default options
loaders: ['babel-loader', 'css-loader'], // allowed loaders
cache: !process.env.DISABLE_HAPPY_CACHE,
cacheContext: {
env: process.env.NODE_ENV,
refresh: process.env.REFRESH_HAPPY_CACHE ? Math.random() : 0,
// ... add or override happypack cacheContext options
},
// ... add or override happypack options
}),
])Environment variables
$ DISABLE_HAPPY=true webpack # turns happypack off and run webpack
$ DISABLE_HAPPY_CACHE=true webpack # turns happypack cache off and run webpack
$ REFRESH_HAPPY_CACHE=true webpack # refreshes happypack cache and run webpackHow it does
This webpack block adds HappyPack plugins with proper IDs and replaces loaders by happypack/loader?id=${id}.
API
happypack
Parameters
blocksArray<WebpackBlock>$1any (optional, default{})$1.loaders(optional, default['babel-loader','css-loader'])$1.happypackOptions...any
Loader
Type: string
Rule
Type: {test: RegExp, loader: (Loader | Array<Loader>)?, loaders: (Loader | Array<Loader>)?, use: (Loader | Array<Loader>)?, options: Object?}
Properties
testRegExploader(Loader | Array<Loader>)?loaders(Loader | Array<Loader>)?use(Loader | Array<Loader>)?optionsObject?
Block
Type: {plugins: Array<any>?, module: {loaders: Array<Rule>?, rules: Array<Rule>?}}
Properties
pluginsArray<any>?module{loaders: Array<Rule>?, rules: Array<Rule>?}module.loadersArray<Rule>?module.rulesArray<Rule>?
BlockOptions
Type: {loaders: Array<string>?, refresh: boolean?, cache: any?, cacheContext: {}?}
Properties
WebpackBlock
Type: function (context: any, utils: any): function (prevCongig: any): Block
Other useful webpack blocks
License
MIT © Diego Haz