You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 17, 2021. It is now read-only.
Copy file name to clipboardexpand all lines: README.md
+27-3
Original file line number
Diff line number
Diff line change
@@ -58,9 +58,10 @@ Emits `file.png` as file in the output directory and returns the public URL
58
58
|Name|Type|Default|Description|
59
59
|:--:|:--:|:-----:|:----------|
60
60
|**`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|
61
62
|**`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|
64
65
|**`useRelativePath`**|`{Boolean}`|`false`|Should be `true` if you wish to generate a `context` relative URL for each file|
65
66
|**`emitFile`**|`{Boolean}`|`true`|By default a file is emitted, however this can be disabled if required (e.g. for server side packages)|
66
67
@@ -98,6 +99,29 @@ You can configure a custom filename template for your file using the query param
98
99
}
99
100
```
100
101
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
+
importimgfrom'./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
+
101
125
#### `placeholders`
102
126
103
127
|Name|Type|Default|Description|
@@ -106,7 +130,7 @@ You can configure a custom filename template for your file using the query param
106
130
|**`[name]`**|`{String}`|`file.basename`|The basename of the resource|
107
131
|**`[path]`**|`{String}`|`file.dirname`|The path of the resource relative to the `context`|
108
132
|**`[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`|
0 commit comments