Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble using browserify-shim with grunt-browserify #364

Open
lelea2 opened this issue Oct 29, 2015 · 0 comments
Open

Trouble using browserify-shim with grunt-browserify #364

lelea2 opened this issue Oct 29, 2015 · 0 comments

Comments

@lelea2
Copy link

lelea2 commented Oct 29, 2015

I have trouble with using grunt-shim with grunt-browserify.
So basically, i have shim configured in package.json

 "browser": {
    "jquery": "./node_modules/couponscom-js-lib/lib/jquery.js",
    "underscore": "./node_modules/couponscom-js-lib/lib/underscore.js",
    "backbone": "./node_modules/couponscom-js-lib/lib/backbone.js",
    "pubsub": "./node_modules/couponscom-js-lib/lib/PubSub.js",
    "dust": "./node_modules/dustjs-linkedin/lib/dust.js",
    "dust-compiler": "./node_modules/dustjs-linkedin/lib/compiler.js",
    "dust-helpers": "./node_modules/dustjs-helpers/lib/dust-helpers.js",
  },
  "browserify-shim": "./tasks/shim/shim.js",
  "browserify": {
    "global-transform": [
      "browserify-shim"
    ]
  }

under tasks/shim/shim.js

module.exports = {
    'jquery': {
        'exports': 'jQuery'
    },
    'underscore': {
        'exports': '_'
    },
    'backbone': {
        'exports': 'Backbone',
        'depends': {
            'jquery': '$',
            'underscore': '_'
        }
    },
    'pubsub': {
        'exports': 'PubSub',
        'depends': {
            'backbone': 'Backbone'
        }
    },
    'dust': {
        'exports': 'dust'
    },
    'dust-compiler': {
        'depends': {
            'dust': 'dust'
        }
    },
    'dust-helpers': {
        'depends': {
            'dust': 'dust'
        }
    }
}

Doing some googling and realize i have to duplicate shim on grunt file

var fs = require('fs'),
    shims = require('../shim/shim.js'),
    alias = require('../shim/browser.js'),
    sharedModules = Object.keys(shims).concat([
      // place all modules you want in the lib build here
    ]);

module.exports = function browserify(grunt) {

    // Load task
    grunt.loadNpmTasks('grunt-browserify');
    var browserifyProduction = {
            options: {
                browserifyOptions: {
                    debug: false
                },
                require: sharedModules,
                preBundleCB: function (b) {
                    b.transform({global: true}, 'browserify-shim')
                }
            },
            files: [{
                expand: true,
                cwd: 'public/js/',
                src: '*.js',
                dest: 'build/js'
            }]
        }

All shimmed files are pulled in, however i have trouble with the "require" part. jQuery is pulled in for example, but it's said jQuery not defined when run in browser, realize that the hash is not maintained as the old grunt

Anyone has the same issue and know how to fix it?

Thank you
Kareen

@lelea2 lelea2 changed the title Trouble using grunt-shim with grunt-browserify Trouble using browserify-shim with grunt-browserify Oct 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant