{"id":17060972,"url":"https://github.com/kkemple/primus-webpack-plugin","last_synced_at":"2025-04-12T18:10:28.024Z","repository":{"id":57152742,"uuid":"84014266","full_name":"kkemple/primus-webpack-plugin","owner":"kkemple","description":"Build client side primus script and add to build assets 📦⚡","archived":false,"fork":false,"pushed_at":"2018-03-03T05:04:52.000Z","size":11,"stargazers_count":6,"open_issues_count":4,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T12:21:38.010Z","etag":null,"topics":["primus","webpack","webpack-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kkemple.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-06T00:48:02.000Z","updated_at":"2025-02-03T18:13:07.000Z","dependencies_parsed_at":"2022-09-06T20:50:40.327Z","dependency_job_id":null,"html_url":"https://github.com/kkemple/primus-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkemple%2Fprimus-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkemple%2Fprimus-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkemple%2Fprimus-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkemple%2Fprimus-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kkemple","download_url":"https://codeload.github.com/kkemple/primus-webpack-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610338,"owners_count":21132919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["primus","webpack","webpack-plugin"],"created_at":"2024-10-14T10:45:42.612Z","updated_at":"2025-04-12T18:10:27.991Z","avatar_url":"https://github.com/kkemple.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PrimusWebpackPlugin\n\n### Build client side Primus script and add to build assets 📦⚡\n\n## Introduction\n[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.\n\nThis 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.\n\nThis plugin allows you to pass in your Primus options and then adds the client library to your Webpack build assets.\n\n\u003e If HtmlWebpackPlugin is being used it will also add the asset to the output HTML :tada:\n\n## Usage\n\nInstall PrimusWebpackPlugin:\n\n```shell\nnpm install --save-dev primus-webpack-plugin\n```\n\nWith Yarn:\n\n```shell\nyarn add -D primus-webpack-plugin\n```\n\nIn webpack.config.js:\n\n```shell\nconst PrimusWebpackPlugin = require('primus-webpack-plugin')\n\n...\n\nnew PrimusWebpackPlugin({\n  filename: 'primus-client.[hash].js',\n  minify: true,\n  primusOptions: {\n    transformer: 'uws',\n    parser: {\n      encoder: function (data, fn) {\n        fn(null, JSON.stringify(data))\n      },\n      decoder: function (data, fn) {\n        fn(null, JSON.parse(data))\n      }\n    }\n  }\n})\n```\n\nOptions:\n\nName                | Description                               | Default\n--------------------|-------------------------------------------|---------------\nfilename            | Name of generated file                    | `primus-client.js`\nminify              | Whether or not to minify the file         | `false`\nprimusOptions       | Options for the Primus Server             | `{}`\n\n\u003e https://github.com/primus/primus#getting-started\n\n## Caveats\n\n`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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkkemple%2Fprimus-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkkemple%2Fprimus-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkkemple%2Fprimus-webpack-plugin/lists"}