Skip to content

Commit f21ae1e

Browse files
authored
Merge pull request #435 from icelam/asset-preserve-pattern-readme
docs: include usage detail on new assetsPreservePattern parameter
2 parents ab6742b + 0e7db54 commit f21ae1e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,19 @@ Inspired by [react-dev-utils](https://github.com/facebook/create-react-app/blob/
1616

1717
### Webpack5
1818

19-
#### NPM
20-
2119
```bash
2220
npm i html-inline-script-webpack-plugin -D
2321
```
2422

25-
#### Yarn
26-
27-
```bash
28-
yarn add html-inline-script-webpack-plugin -D
29-
```
30-
3123
### Webpack4
3224

33-
#### NPM
34-
3525
```bash
3626
npm i html-inline-script-webpack-plugin@^1 -D
3727
```
3828

39-
#### Yarn
40-
41-
```bash
42-
yarn add html-inline-script-webpack-plugin@^1 -D
43-
```
44-
4529
## Usage
4630

47-
By default, the plugin will convert all the external script files to inline script block.
31+
By default, the plugin will convert all the external script files to inline script block, and remove the original script file from build assets.
4832

4933
```js
5034
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -63,6 +47,7 @@ Below are lists of options supported by this plugin:
6347
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
6448
| scriptMatchPattern | List of script files that should be processed and inject as inline script. This will be filtered using the output file name. | RegExp[] |
6549
| htmlMatchPattern | List of HTML template files that should be processed by this plugin. Useful when you have multiple `html-webpack-plugin` initialized. This will be filtered using the [`options?.filename`](https://github.com/jantimon/html-webpack-plugin#options) provided by `html-webpack-plugin`. | RegExp[] |
50+
| assetPreservePattern | List of script files that should be preserved by this plugin after inserting them inline. This will be filtered using the output file name. | RegExp[] |
6651

6752
Here are some examples illustrating how to use these options:
6853

@@ -128,3 +113,18 @@ module.exports = {
128113
],
129114
};
130115
```
116+
##### Process any script files but preserve `main.js` from build assets
117+
118+
```js
119+
const HtmlWebpackPlugin = require('html-webpack-plugin');
120+
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
121+
122+
module.exports = {
123+
plugins: [
124+
new HtmlWebpackPlugin(),
125+
new HtmlInlineScriptPlugin({
126+
assetPreservePattern: [/main.js$/],
127+
}),
128+
],
129+
};
130+
```

0 commit comments

Comments
 (0)