From bc736888ab9c3d0754a0dfb01d5f8691ff2d9f7f Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Thu, 5 Oct 2017 06:36:50 +0200 Subject: [PATCH] docs(README): update `name` docs (`options.name`) (#217) --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de9ba23..ac56a70 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Emits `file.png` as file in the output directory and returns the public URL |Name|Type|Default|Description| |:--:|:--:|:-----:|:----------| -|**`name`**|`{String}`|`[hash].[ext]`|Configure a custom filename template for your file| +|**`name`**|`{String\|Function}`|`[hash].[ext]`|Configure a custom filename template for your file| |**`context`**|`{String}`|`this.options.context`|Configure a custom file context, defaults to `webpack.config.js` [context](https://webpack.js.org/configuration/entry-context/#context)| |**`publicPath`**|`{String\|Function}`|[`__webpack_public_path__ `](https://webpack.js.org/api/module-variables/#__webpack_public_path__-webpack-specific-)|Configure a custom `public` path for your files| |**`outputPath`**|`{String\|Function}`|`'undefined'`|Configure a custom `output` path for your files| @@ -68,6 +68,8 @@ Emits `file.png` as file in the output directory and returns the public URL You can configure a custom filename template for your file using the query parameter `name`. For instance, to copy a file from your `context` directory into the output directory retaining the full directory structure, you might use +#### `{String}` + **webpack.config.js** ```js { @@ -78,6 +80,24 @@ You can configure a custom filename template for your file using the query param } ``` +#### `{Function}` + +**webpack.config.js** +```js +{ + loader: 'file-loader', + options: { + name (file) { + if (env === 'development') { + return '[path][name].[ext]' + } + + return '[hash].[ext]' + } + } +} +``` + #### `placeholders` |Name|Type|Default|Description|