Fix bcrypt issues for browserify

This commit is contained in:
Raymond Feng 2014-12-08 14:59:21 -08:00
parent bb2632a5fc
commit cb2f40bb86
3 changed files with 9 additions and 3 deletions

View File

@ -70,7 +70,7 @@ module.exports = function(grunt) {
'dist/loopback.js': ['index.js'], 'dist/loopback.js': ['index.js'],
}, },
options: { options: {
ignore: ['nodemailer', 'passport'], ignore: ['nodemailer', 'passport', 'bcrypt'],
standalone: 'loopback' standalone: 'loopback'
} }
} }
@ -174,7 +174,8 @@ module.exports = function(grunt) {
'passport', 'passport',
'passport-local', 'passport-local',
'superagent', 'superagent',
'supertest' 'supertest',
'bcrypt'
], ],
// transform: ['coffeeify'], // transform: ['coffeeify'],
// debug: true, // debug: true,

View File

@ -11,6 +11,10 @@ var bcrypt;
try { try {
// Try the native module first // Try the native module first
bcrypt = require('bcrypt'); bcrypt = require('bcrypt');
// Browserify returns an empty object
if (bcrypt && typeof bcrypt.compare !== 'function') {
bcrypt = require('bcryptjs');
}
} catch (err) { } catch (err) {
// Fall back to pure JS impl // Fall back to pure JS impl
bcrypt = require('bcryptjs'); bcrypt = require('bcryptjs');

View File

@ -94,7 +94,8 @@
"express": "./lib/browser-express.js", "express": "./lib/browser-express.js",
"./lib/server-app.js": "./lib/browser-express.js", "./lib/server-app.js": "./lib/browser-express.js",
"connect": false, "connect": false,
"nodemailer": false "nodemailer": false,
"bcrypt": false
}, },
"license": { "license": {
"name": "Dual MIT/StrongLoop", "name": "Dual MIT/StrongLoop",