1

I am using feathersjs as restful API and primusjs as websocket connection. Below is the code I am using to generate primus.js file:

app.configure(primus({
    transformer: 'websockets',
    timeout: false
  }, (primus) => {
    primus.library();
    primus.save(path.join(__dirname, '../public/dist/primus.js'));
  }))

In order to let my client to use the generated primus.js file. I have to serve this file from my server. From the client side, it can use it like below:

<script src='http://xxxxxx/public/dist/primus.js'>

But my client is using webpack to package every dependencies into a few big js files. How can I package primus.js file in client if it is an auto generated file?

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

1 Answers1

0

I don't believe you can out of the box but it looks like there is a primus-webpack-plugin:

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

Daff
  • 43,734
  • 9
  • 106
  • 120
  • this plugin works on client side right? I think the package should include server source code to generate the primus js file. How does client side get the server code? Is it done through npm dependency? – Joey Yi Zhao Mar 07 '17 at 23:22
  • No, you add it to your Webpack configuration as documented and point it to the Primus library you created. It should then include it in the bundle. – Daff Mar 08 '17 at 00:02
  • Is the webpack configuration in server or client side? – Joey Yi Zhao Mar 08 '17 at 00:48
  • This plugin one only works for `primus` but not for `feathers-primus`. I am writing a webpack plugin for `feathers-primus` but facing a problem. I have created a question for that could you have a look at? http://stackoverflow.com/questions/42775262/how-to-generate-feathersjs-primus-client-on-webpack-plugin – Joey Yi Zhao Mar 13 '17 at 23:31
  • I don't think Stackoverflow is the right place for figuring this out (probably much easier in an issue [here](https://github.com/feathersjs/feathers-primus/issues/new)). I don't really see at the moment how feathers-primus is doing anything that would interfere with using the original Webpack plugin. – Daff Mar 14 '17 at 04:52