Meteor Npm-module client-side?

前端 未结 4 665
情书的邮戳
情书的邮戳 2020-12-14 20:10

Is it possible to use Npm-Modules on client-side?

More specifically:

I want to use node.js built-in crypto-module for encrypting a password the

相关标签:
4条回答
  • 2020-12-14 20:36

    You can use https://github.com/elidoran/cosmos-browserify now to archive this. I used wrapped packages before and it was real pain to update them and to create new ones. Now with browserify support I can include library with just several lines of code. See their example how to do it. I don't publish it here as it may be subject of change.

    0 讨论(0)
  • 2020-12-14 20:39

    You can use browserify to build a .js bundle with all all the Npm modules you want on the client side. See:

    2013 Meteor NPM Packages

    0 讨论(0)
  • 2020-12-14 20:41

    You can try to add the js-files you need on client-side from .npm folder under crypto's package directory. So, your package.js file might look like this:

    Package.describe({
      summary: 'Description of your crypto package'
    });
    
    Npm.depends({
      'crypto': '1.0.0'
    });
    
    Package.on_use(function (api) {
      api.add_files('crypto.js', 'server');
      api.add_files('.npm/node_modules/crypto/crypto.js', 'client');
    });
    
    0 讨论(0)
  • 2020-12-14 20:44

    Its not possible to use Npm modules on the client side since Npm modules are extensions via node.js which only runs on the server end.

    If you want to use a file like crypto you would have to make a client side only version and put it in /client/lib of your Meteor app

    While this may be possible officially, Meteor doesn't support this.

    You would have to include requirejs manually using this project: https://github.com/apendua/require

    0 讨论(0)
提交回复
热议问题