Skip to content

Commit

Permalink
Merge pull request #27 from sn-satyendra/ts-definitions
Browse files Browse the repository at this point in the history
Adding types and filter option
  • Loading branch information
sn-satyendra authored Dec 13, 2021
2 parents 346f0ec + ad5add6 commit d26fec7
Show file tree
Hide file tree
Showing 8 changed files with 1,276 additions and 618 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ module.exports = {
rules: {
"class-methods-use-this": OFF,
"import/no-extraneous-dependencies": [ERROR, { devDependencies: true }],
"import/no-relative-packages": OFF,
"import/no-import-module-exports": OFF,
},
};
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ And run `webpack` via your preferred method.

### `index`

Type: `String`
Type: `string`
Default: `index.html`
Optional: `true`

Name of the index file which needs modification.

Expand All @@ -55,8 +56,9 @@ new FontPreloadPlugin({

### `extensions`

Type: `Array`
Type: `string[]`
Default: `['woff', 'ttf', 'eot']`
Optional: `true`

Default font extensions which should be used.

Expand All @@ -69,8 +71,9 @@ new FontPreloadPlugin({

### `crossorigin`

Type: `Boolean`
Type: `boolean`
Default: `true`
Optional: `true`

Is the font request crossorigin or not.

Expand All @@ -83,8 +86,9 @@ new FontPreloadPlugin({

### `loadType`

Type: `String`
Type: `string`
Default: `preload`
Optional: `true`

Type of load. It can be either `preload` or `prefetch`.

Expand All @@ -97,8 +101,9 @@ new FontPreloadPlugin({

### `insertBefore`

Type: `String`
Type: `string`
Default: `head > title`
Optional: `true`

The selector for node before which the preload/prefetch links should be added.

Expand All @@ -114,6 +119,7 @@ new FontPreloadPlugin({

Type: `Function`
Default: `undefined`
Optional: `true`

Callback for doing custom manipulations to index.html for special use cases like templating or server side rendering. This callback would be passed an `object` as parameter with 2 keys:

Expand All @@ -133,6 +139,25 @@ new FontPreloadPlugin({
});
```

### `filter`

Type: `string`
Default: `undefined`
Optional: `true`

Expression for allowing more granular filtering of the font assets for doing a preload/prefetch. The filter is applied on the font assets selected by the `extensions` option. If the filter is a string, all the font assets which contain the string as part of the name are included in the preload and rest are ignored. In case filter is regex, the font asset's name is tested to match the regex for allowing preload. If you don't pass this option, all the font assets will be preloaded.

```js
// To only preload font's which have string `app-font` as part of there name.
new FontPreloadPlugin({
filter: "app-font"
});

// To preload fonts which start with `mui` or `app` in there name.
new FontPreloadPlugin({
filter: /^mui|^app/i
});
```
## License

[MIT](./LICENSE)
Expand Down
Loading

0 comments on commit d26fec7

Please sign in to comment.