Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 9ee8332

Browse files
serutmichael-ciniawsky
authored andcommittedFeb 14, 2018
docs(README): add regExp option (options.regExp) (#244)
1 parent f62bc44 commit 9ee8332

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed
 

‎README.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ Emits `file.png` as file in the output directory and returns the public URL
5858
|Name|Type|Default|Description|
5959
|:--:|:--:|:-----:|:----------|
6060
|**`name`**|`{String\|Function}`|`[hash].[ext]`|Configure a custom filename template for your file|
61+
|**`regExp`**|`{RegExp}`|`'undefined'`|Let you extract some parts of the file path to reuse them in the `name` property|
6162
|**`context`**|`{String}`|`this.options.context`|Configure a custom file context, defaults to `webpack.config.js` [context](https://webpack.js.org/configuration/entry-context/#context)|
62-
|**`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|
63-
|**`outputPath`**|`{String\|Function}`|`'undefined'`|Configure a custom `output` path for your files|
63+
|**`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 file|
64+
|**`outputPath`**|`{String\|Function}`|`'undefined'`|Configure a custom `output` path for your file|
6465
|**`useRelativePath`**|`{Boolean}`|`false`|Should be `true` if you wish to generate a `context` relative URL for each file|
6566
|**`emitFile`**|`{Boolean}`|`true`|By default a file is emitted, however this can be disabled if required (e.g. for server side packages)|
6667

@@ -98,6 +99,29 @@ You can configure a custom filename template for your file using the query param
9899
}
99100
```
100101

102+
### `regExp`
103+
104+
Defines a `regExp` to match some parts of the file path. These capture groups can be reused in the `name` property using `[N]` placeholder. Note that `[0]` will be replaced by the entire tested string, whereas `[1]` will contain the first capturing parenthesis of your regex and so on...
105+
106+
```js
107+
import img from './customer01/file.png'
108+
```
109+
110+
**webpack.config.js**
111+
```js
112+
{
113+
loader: 'file-loader',
114+
options: {
115+
regExp: /\/([a-z0-9]+)\/[a-z0-9]+\.png$/,
116+
name: '[1]-[name].[ext]'
117+
}
118+
}
119+
```
120+
121+
```
122+
customer01-file.png
123+
```
124+
101125
#### `placeholders`
102126

103127
|Name|Type|Default|Description|
@@ -106,7 +130,7 @@ You can configure a custom filename template for your file using the query param
106130
|**`[name]`**|`{String}`|`file.basename`|The basename of the resource|
107131
|**`[path]`**|`{String}`|`file.dirname`|The path of the resource relative to the `context`|
108132
|**`[hash]`**|`{String}`|`md5`|The hash of the content, hashes below for more info|
109-
|**`[N]`**|`{Number}`|``|The `n-th` match obtained from matching the current file name against the query param `regExp`|
133+
|**`[N]`**|`{String}`|``|The `n-th` match obtained from matching the current file name against the `regExp`|
110134

111135
#### `hashes`
112136

0 commit comments

Comments
 (0)
This repository has been archived.