Skip to content
treydibler edited this page Oct 10, 2018 · 9 revisions

If you use TweetNaCl.js with Webpack, it will include a lot of useless Node shims, because TweetNaCl.js tries to be compatible with browsers and Node.js.

To avoid this, tell Webpack not to parse TweetNaCl.js and tweak exported/imported variables with exports-loader and imports-loader in config (here we also do this for TweetNaCl-auth plugin):

module.exports = {
  // ...
  module: {
    loaders: [
      {
         test: /[\\\/]tweetnacl[\\\/]/,
         loader: 'exports-loader?window.nacl!imports-loader?this=>window,module=>{},require=>false'
      },
      {
         test: /[\\\/]tweetnacl-auth[\\\/]/,
         loader: 'exports-loader?window.nacl.auth!imports-loader?this=>window,module=>{},require=>false'
      }
    ],
    noParse: [
      /[\\\/]tweetnacl[\\\/]/,
      /[\\\/]tweetnacl-auth[\\\/]/
    ]
}

(Make sure to have imports-loader and exports-loader packages installed.)

Use it as you would normally use packages:

var nacl = require('tweetnacl')  // or 'tweetnacl/nacl-fast' for fast version
var naclAuth = require('tweetnacl-auth')
Clone this wiki locally