1 | # write-file-webpack-plugin
|
2 |
|
3 | [![NPM version](http://img.shields.io/npm/v/write-file-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/write-file-webpack-plugin)
|
4 | [![js-canonical-style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
|
5 |
|
6 | Forces `webpack-dev-server` program to write bundle files to the file system.
|
7 |
|
8 | This plugin has no effect when [`webpack`](https://webpack.github.io/docs/usage.html) program
|
9 | is used instead of [`webpack-dev-server`](https://webpack.github.io/docs/webpack-dev-server.html).
|
10 |
|
11 | ## Install
|
12 |
|
13 | ```sh
|
14 | npm install write-file-webpack-plugin --save-dev
|
15 | ```
|
16 |
|
17 | ## API
|
18 |
|
19 | ```js
|
20 | /**
|
21 | * @typedef {Object} options
|
22 | * @property {boolean} exitOnErrors Stop writing files on webpack errors (default: true).
|
23 | * @property {boolean} force Forces the execution of the plugin regardless of being using `webpack-dev-server` or not (default: false).
|
24 | * @property {boolean} log Logs names of the files that are being written (or skipped because they have not changed) (default: true).
|
25 | * @property {RegExp} test A regular expression used to test if file should be written. When not present, all bundle will be written.
|
26 | * @property {boolean} useHashIndex Use hash index to write only files that have changed since the last iteration (default: true).
|
27 | */
|
28 |
|
29 | /**
|
30 | * @param {options} options
|
31 | * @returns {Object}
|
32 | */
|
33 | new WriteFilePlugin();
|
34 |
|
35 | new WriteFilePlugin({
|
36 | // Write only files that have ".css" extension.
|
37 | test: /\.css$/,
|
38 | useHashIndex: true
|
39 | });
|
40 | ```
|
41 |
|
42 | ## Usage
|
43 |
|
44 | Configure [`webpack.config.js`](https://webpack.github.io/docs/configuration.html) to use the `write-file-webpack-plugin` plugin.
|
45 |
|
46 | ```js
|
47 | import path from 'path';
|
48 | import WriteFilePlugin from 'write-file-webpack-plugin';
|
49 |
|
50 | export default {
|
51 | output: {
|
52 | path: path.join(__dirname, './dist')
|
53 | },
|
54 | plugins: [
|
55 | new WriteFilePlugin()
|
56 | ],
|
57 | // ...
|
58 | }
|
59 | ```
|
60 |
|
61 | See [./sandbox](./sandbox) for a working `webpack` configuration.
|