Skip to content
Dmitry Chestnykh edited this page Aug 9, 2014 · 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?window.nacl!imports?this=>window,module=>{},require=>false'
      },
      {
         test: /[\\\/]tweetnacl-auth[\\\/]/,
         loader: 'exports?window.nacl.auth!imports?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