Skip to content

Commit 7a2b3f0

Browse files
committed
Update documentation
1 parent 8c440ee commit 7a2b3f0

3 files changed

Lines changed: 27 additions & 35 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 dokmic
3+
Copyright (c) 2017-2021 dokmic
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Webpack Redis Plugin
22

33
[![NPM](https://img.shields.io/npm/v/webpack-redis-plugin.svg)](https://www.npmjs.com/package/webpack-redis-plugin)
4-
[![Build Status](https://travis-ci.org/dokmic/webpack-redis-plugin.svg?branch=master)](https://travis-ci.org/dokmic/webpack-redis-plugin)
4+
[![Build Status](https://github.com/dokmic/webpack-redis-plugin/actions/workflows/main.yaml/badge.svg?branch=master)](https://github.com/dokmic/webpack-redis-plugin/actions/workflows/main.yaml)
55
[![Code Coverage](https://codecov.io/gh/dokmic/webpack-redis-plugin/badge.svg?branch=master)](https://codecov.io/gh/dokmic/webpack-redis-plugin?branch=master)
66

7-
This webpack plugin provides an ability to save your assets in [Redis](https://redis.io/).
7+
This Webpack plugin provides an ability to save your assets in [Redis](https://redis.io/). The plugin supports _all_ the Webpack versions and is [tested](https://github.com/dokmic/webpack-redis-plugin/actions/workflows/main.yaml) with Webpack 2, 3, 4, and 5.
88

99
## Install
1010
```bash
@@ -14,8 +14,8 @@ npm install --save-dev webpack-redis-plugin
1414
## Usage
1515
In your `webpack.config.js`:
1616
```javascript
17-
const WebpackRedisPlugin = require('webpack-redis-plugin'),
18-
sha1 = require('sha1');
17+
const { WebpackRedisPlugin } = require('webpack-redis-plugin');
18+
const sha1 = require('sha1');
1919

2020
module.exports = {
2121
entry: {
@@ -39,56 +39,47 @@ module.exports = {
3939
host: 'redis.example.com',
4040
password: 'password',
4141
},
42-
filter: (key, asset) => {
43-
return key === 'js/page1.js' && asset.size();
44-
},
45-
transform: (key, asset) => Object({
46-
key: key + '.sha1',
47-
value: sha1(asset.source()),
42+
43+
filter: (key, asset) => key === 'js/page1.js' && asset.size(),
44+
45+
transform: (key, asset) => ({
46+
key: `${key}.sha1`,
47+
value: sha1(asset.source().toString()),
4848
}),
4949
}),
5050
],
5151
};
5252
```
5353

54-
This config tells the plugin to filter out everything except non-empty `js/page1.js` and save a hash sum of the contents at `js/page1.js.sha1` key.
54+
This config tells the plugin to filter out everything except non-empty `js/page1.js` and save a hash sum of the contents at the `js/page1.js.sha1` key.
5555

5656
## API
5757

5858
### `options.config`
5959
Redis client configuration. All possible options can be found [here](https://www.npmjs.com/package/redis#options-object-properties).
6060

61+
**Default:** `undefined`
62+
6163
### `options.filter`
62-
The callback function filters keys/assets that will be set in Redis:
64+
The callback function to filter keys/assets that will be set in Redis:
6365

64-
```javascript
65-
Function(
66-
key: string,
67-
asset: {
68-
size: Function(): number,
69-
source: Function(): string,
70-
}
71-
): boolean
66+
```typescript
67+
filter(key: string, asset: Source): boolean | Promise<boolean>;
7268
```
7369

74-
- `key` - the destination file name relative to your output directory.
75-
- `asset` - related webpack asset.
70+
- `key` - relative asset path.
71+
- `asset` - Webpack asset.
7672

7773
**Default:** `() => true`
7874

7975
### `options.transform`
8076
The callback function transforms keys and values that will be set in Redis:
8177

8278
```javascript
83-
Function(
84-
key: string,
85-
asset: {
86-
size: Function(): number,
87-
source: Function(): string,
88-
}
89-
): { key: string, value: string }
79+
transform(key: string, asset: Source): KeyValuePair | Promise<KeyValuePair>
9080
```
91-
- `key` - the destination file name relative to your output directory.
92-
- `asset` - related webpack asset.
9381

94-
**Default:** `(key, asset) => { key, value: asset.source() }`
82+
- `key` - relative asset path.
83+
- `asset` - Webpack asset.
84+
85+
**Default:** `(key, asset) => ({ key, value: asset.source() })`

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "webpack-redis-plugin",
33
"version": "1.0.0",
4-
"description": "Webpack redis integration",
4+
"description": "Webpack Redis Integration",
55
"keywords": [
66
"webpack",
7-
"redis"
7+
"redis",
8+
"plugin"
89
],
910
"author": "Michael Dokolin <m@dokol.in>",
1011
"license": "MIT",

0 commit comments

Comments
 (0)