# primus-client-webpack-plugin

> Build client side primus script and add to build assets

Latest version **1.1.0** (published 2018-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install primus-client-webpack-plugin
pnpm add primus-client-webpack-plugin
yarn add primus-client-webpack-plugin
bun add primus-client-webpack-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-06-12 |
| First published | 2018-03-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | newyork.anthonyng@gmail.com |
| Maintainers | newyork.anthonyng |
| Keywords | webpack-plugin, webpack, primus, sockets |

## Links

- npm: https://www.npmjs.com/package/primus-client-webpack-plugin
- Repository: https://github.com/newyork-anthonyng/primus-webpack-plugin
- Homepage: https://github.com/newyork-anthonyng/primus-webpack-plugin#readme
- Issues: https://github.com/newyork-anthonyng/primus-webpack-plugin/issues
- npm.io page: https://npm.io/package/primus-client-webpack-plugin

## Dependencies (1)

- [uglify-js](https://npm.io/package/uglify-js.md) ^2.8.7

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-06-12
- 1.0.1 — 2018-03-03
- 1.0.0 — 2018-03-02
- 0.0.38 — 2018-03-01

## README

# PrimusClientWebpackPlugin

> This is a fork of [primus-webpack-plugin](https://github.com/kkemple/primus-webpack-plugin). It uses publicPath inside your HtmlWebpackPlugin.
>
> [See this issue here](https://github.com/kkemple/primus-webpack-plugin/issues/6)

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

## Introduction
[Primus](https://github.com/primus/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 PrimusClientWebpackPlugin:

```shell
npm install --save-dev primus-client-webpack-plugin
```

In webpack.config.js:

```javascript
const PrimusClientWebpackPlugin = require('primus-client-webpack-plugin')

...

new PrimusClientWebpackPlugin({
  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:

Name                | Description                               | Default
--------------------|-------------------------------------------|---------------
filename            | Name of generated file                    | `primus-client.js`
minify              | Whether or not to minify the file         | `false`
primusOptions       | Options for the Primus Server             | `{}`

> [See primus options here](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](https://github.com/webpack/docs/wiki/shimming-modules#plugin-provideplugin) it in your Webpack config.

---
_Source: https://npm.io/package/primus-client-webpack-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
