0.0.37 • Published 7 years ago

primus-webpack-plugin v0.0.37

Weekly downloads
37
License
MIT
Repository
github
Last release
7 years ago

PrimusWebpackPlugin

Build client side Primus script and add to build assets 📦⚡

Introduction

Primus is a socket wrapper implementation that requires a built client library. The client library also needs to match the configuration of the server side implementation. Primus handles this by exposing primus.library() which returns the client library as a string.

This is problematic in applications that bundle and dynamically generate client assets. It is also problematic because unless you want to serve the client script directly from your websocket server (not a great approach IMO) you need to prebuild and package the client script anyway.

This plugin allows you to pass in your Primus options and then adds the client library to your Webpack build assets.

If HtmlWebpackPlugin is being used it will also add the asset to the output HTML :tada:

Usage

Install PrimusWebpackPlugin:

npm install --save-dev primus-webpack-plugin

With Yarn:

yarn add -D primus-webpack-plugin

In webpack.config.js:

const PrimusWebpackPlugin = require('primus-webpack-plugin')

...

new PrimusWebpackPlugin({
  filename: 'primus-client.[hash].js',
  minify: true,
  primusOptions: {
    transformer: 'uws',
    parser: {
      encoder: function (data, fn) {
        fn(null, JSON.stringify(data))
      },
      decoder: function (data, fn) {
        fn(null, JSON.parse(data))
      }
    }
  }
})

Options:

NameDescriptionDefault
filenameName of generated fileprimus-client.js
minifyWhether or not to minify the filefalse
primusOptionsOptions for the Primus Server{}

https://github.com/primus/primus#getting-started

Caveats

primus.library() generates a UMDish style file but it doesn't seem to work being bundled with Webpack, instead a global Primus constructor is added. If you want to require/import Primus you will need to shim it in your Webpack config.

0.0.37

7 years ago

0.0.36

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago