Search code examples
ember.jsember-cli

How do I exclude jQuery from the vendorFiles?


In my app I'm adding EmberJS to a page where jQuery is already loaded. So I don't need the ember-cli to include jQuery.


Solution

  • The ember-cli build step has the addition of jQuery hardcoded, but you can override it via configuration. I'm not sure if this is documented, but you can check node_modules/ember-cli/lib/broccoli/ember-app.js

      this.vendorFiles = merge(options.vendorFiles, {
        'loader.js': this.bowerDirectory + '/loader/loader.js',
        'jquery.js': this.bowerDirectory + '/jquery/dist/jquery.js',
        'handlebars.js': {
          development: this.bowerDirectory + '/handlebars/handlebars.js',
          production:  this.bowerDirectory + '/handlebars/handlebars.runtime.js'
        } /* etc, etc, */
      }
    

    options is the hash that is passed to a new instance of EmberApp in your Brocfile.js

    Instead of,

      var EmberApp = require('ember-cli/lib/broccoli/ember-app');
      var app = new EmberApp({});
    

    Pass the location of a stub file (use the vendor/ dir for this),

      var EmberApp = require('ember-cli/lib/broccoli/ember-app');
      var app = new EmberApp({
          vendorFiles : {
              'jquery.js': 'vendor/stub.js'
          }
      });
    

    This stub will take priority over the hard-coded jQuery path. Just make sure you load in jQuery before your ember app is loaded.