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

Using shim + noParse leads to undefined variable error #89

Closed
ryanflorence opened this issue Aug 28, 2013 · 10 comments
Closed

Using shim + noParse leads to undefined variable error #89

ryanflorence opened this issue Aug 28, 2013 · 10 comments

Comments

@ryanflorence
Copy link

As soon as I add the noParse option I get this error in the browser:

Uncaught ReferenceError: global is not defined

Here's my config:

var vendor = {
  jquery: 'bower_components/jquery/jquery.js',
  handlebars: 'bower_components/handlebars/dist/handlebars.runtime.js',
  ember: 'bower_components/ember/ember.js'
};

module.exports = {
  build: {
    src: [
      vendor.jquery,
      vendor.handlebars,
      vendor.ember,
      'tmp/public/assets/templates.js',
      'tmp/transpiled/app/index.js'
    ],
    dest: 'tmp/public/assets/app.js',
    options: {
      noParse: [
        vendor.jquery,
        vendor.handlebars,
        vendor.ember,
        'tmp/public/assets/templates.js'
      ],
      debug: true,
      shim: {
        jquery: {
          path: vendor.jquery,
          exports: 'jQuery'
        },
        handlebars: {
          path: vendor.handlebars,
          exports: 'Handlebars'
        },
        ember: {
          path: vendor.ember,
          exports: 'Ember',
          depends: {
            'ember-imports': 'Ember',
            jquery: 'jQuery',
            handlebars: 'Handlebars'
          }
        }
      }
    }
  }
};
@jmreidy
Copy link
Owner

jmreidy commented Aug 30, 2013

Hey @rpflorence! Cool to see you're using grunt-browserify!

As of right now, browserify-shim requires the libraries being shimmed to be parsed. I'm going to leave this ticket open, though, as a reminder to update the documentation to specify this limitation.

@jmreidy
Copy link
Owner

jmreidy commented Aug 30, 2013

And if you're looking for faster build times, I'd just suggest moving the shimmed libraries into a separate vendor subtask, so that you don't need to recompile on every client code change.

@JonET
Copy link

JonET commented Sep 8, 2013

@jmreidy I was able to make this situation work in mimosa-browserify by creating a transform that inserts var global=self; before the shim when the file is configured to be both shimmed and noParsed.

index.coffee#L84-L98

@jmreidy
Copy link
Owner

jmreidy commented Sep 8, 2013

@JonET Interesting! Do you know if this approach would still work for libraries that need to be shimmed with outside dependencies?

@JonET
Copy link

JonET commented Sep 8, 2013

Seems to be resolving things okay. (conifg)
image

@jmreidy
Copy link
Owner

jmreidy commented Sep 8, 2013

Awesome! I'll merge this in. Thanks @JonET!

@JonET
Copy link

JonET commented Sep 8, 2013

That screenshot isn't right (global.$ is defined before the require('jquery') call). But Handlebars wasn't. So yep, it works.

jmreidy added a commit that referenced this issue Sep 25, 2013
Fix comes via @JonET's suggestion. Will address #89.
@jmreidy
Copy link
Owner

jmreidy commented Sep 26, 2013

For anyone that is experiencing this problem, could you try the fix_noParse_shim branch at b35b8af?

jmreidy added a commit that referenced this issue Sep 30, 2013
@jmreidy
Copy link
Owner

jmreidy commented Sep 30, 2013

Published in v1.2.7

@jmreidy jmreidy closed this as completed Sep 30, 2013
@ndreckshage
Copy link

thanks for this code snippet! was trying to find nice way to handle the ember suite

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

4 participants