Skip to content

mnifakram/webpack-redis-plugin

 
 

Repository files navigation

Webpack Redis Plugin

NPM Build Status Code Coverage

This webpack plugin provides an ability to save your assets in Redis.

Install

npm install --save-dev webpack5-redis-plugin

Usage

In your webpack.config.js:

const WebpackRedisPlugin = require('webpack5-redis-plugin');

module.exports = {
  entry: {
    page1: [
      './src/page1/index.js',
    ],
    page2: [
      './src/page2/index.js',
    ],
  },

  output: {
    filename: 'js/[name].js',
  },

  // ...

  plugins: [
    new WebpackRedisPlugin({
      config: {
        host: 'redis.example.com',
        password: 'password',
      },
      filter: key => key === 'js/page1.js',
      transform: (key, content) => Object({
        key: key + ':current',
        value: content+'suffix',
      }),
    }),
  ],
};

This config tells the plugin to filter out everything js/page1.js and save key value pair in redis db

API

options.config

Redis client configuration. All possible options can be found here.

options.filter

The callback function filters keys/assets that will be set in Redis:

Function(
  key: string
): boolean
  • key - the destination file name relative to your output directory.

Default: () => true

options.transform

The callback function transforms keys and values that will be set in Redis:

Function(
  key: string,
  content: string
): { key: string, value: string }
  • key - the destination file name relative to your output directory.
  • content - UTF-8 file conent

Default: (key, content) => { key, value: content }

About

Webpack redis integration

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%