Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/diegohaz/webpack-blocks-happypack

A webpack block that adds happypack support to your webpack config
https://github.com/diegohaz/webpack-blocks-happypack

happypack webpack webpack-blocks webpack2

Last synced: 2 months ago
JSON representation

A webpack block that adds happypack support to your webpack config

Awesome Lists containing this project

README

        

# webpack-blocks-happypack

[![Generated with nod](https://img.shields.io/badge/generator-nod-2196F3.svg?style=flat-square)](https://github.com/diegohaz/nod)
[![NPM version](https://img.shields.io/npm/v/webpack-blocks-happypack.svg?style=flat-square)](https://npmjs.org/package/webpack-blocks-happypack)
[![Build Status](https://img.shields.io/travis/diegohaz/webpack-blocks-happypack/master.svg?style=flat-square)](https://travis-ci.org/diegohaz/webpack-blocks-happypack) [![Coverage Status](https://img.shields.io/codecov/c/github/diegohaz/webpack-blocks-happypack/master.svg?style=flat-square)](https://codecov.io/gh/diegohaz/webpack-blocks-happypack/branch/master)

A webpack block that adds [happypack](https://github.com/amireh/happypack) support to your webpack config.

This package is based on the [PR](https://github.com/andywer/webpack-blocks/pull/126) by [**@fenos**](https://github.com/fenos) on the official [webpack-blocks](https://github.com/andywer/webpack-blocks) repository.

## Install

$ npm install --save-dev webpack-blocks-happypack

## Usage

### Basic

```js
const { createConfig, babel, css, extractText } = require('webpack-blocks')
const happypack = require('webpack-blocks-happypack')

const config = createConfig([
css.modules(),
happypack([
// these will be happypack'd
extractText(),
babel(),
]),
])
```

### Configuration

```js
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

```sh
$ 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 webpack
```

## How it does

This webpack block adds `HappyPack` plugins with proper IDs and replaces loaders by `happypack/loader?id=${id}`.

## API

#### Table of Contents

- [happypack](#happypack)
- [Loader](#loader)
- [Rule](#rule)
- [Block](#block)
- [BlockOptions](#blockoptions)
- [WebpackBlock](#webpackblock)

### happypack

**Parameters**

- `blocks` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[WebpackBlock](#webpackblock)>**
- `$1` **any** (optional, default `{}`)
- `$1.loaders` (optional, default `['babel-loader','css-loader']`)
- `$1.happypackOptions` **...any**

Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Block](#block)>**

### Loader

Type: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)

### Rule

Type: {test: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp), loader: ([Loader](#loader) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Loader](#loader)>)?, loaders: ([Loader](#loader) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Loader](#loader)>)?, use: ([Loader](#loader) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Loader](#loader)>)?, options: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?}

**Properties**

- `test` **[RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)**
- `loader` **([Loader](#loader) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Loader](#loader)>)?**
- `loaders` **([Loader](#loader) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Loader](#loader)>)?**
- `use` **([Loader](#loader) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Loader](#loader)>)?**
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?**

### Block

Type: {plugins: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<any>?, module: {loaders: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Rule](#rule)>?, rules: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Rule](#rule)>?}}

**Properties**

- `plugins` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<any>?**
- `module` **{loaders: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Rule](#rule)>?, rules: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Rule](#rule)>?}**
- `module.loaders` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Rule](#rule)>?**
- `module.rules` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Rule](#rule)>?**

### BlockOptions

Type: {loaders: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>?, refresh: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, cache: any?, cacheContext: {}?}

**Properties**

- `loaders` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>?**
- `refresh` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
- `cache` **any?**
- `cacheContext` **{}?**

### WebpackBlock

Type: function (context: any, utils: any): function (prevCongig: any): [Block](#block)

## Other useful webpack blocks

- [`webpack-blocks-split-vendor`](https://github.com/diegohaz/webpack-blocks-split-vendor)
- [`webpack-blocks-server-source-map`](https://github.com/diegohaz/webpack-blocks-server-source-map)

## License

MIT © [Diego Haz](https://github.com/diegohaz)