Build ember-cli addon without dependencies

I developed an ember-cli addon that works fine. My addon is a project by itself with a dummy site to test it, a couple of unit tests etc.

When I run the command ember build --production, it basically creates a vendor.js file that contains my addon and all dependencies (bower_components such ember, jquery etc…) which is about 2MB.

I’d like to know if it’s possible to export the addon on its own (vendor.js) without any dependencies inside, just as a vendor I can use? My main project that is using this addon already have ember, jquery… so I don’t want that to be duplicated.

I’m basically trying to make my ember-cli addon a component that I can include in multiple ember projects. My addon and all dev dependencies are more than 100MB of data (including node modules, express, broccoli, tests…), so when I run the command npm install my-addon in my main project, it installs everything (including dev dependencies, tests etc…) which is pretty big. I don’t really need that in my other project, the addon itself (dist version) should be only couple of KB and that’s all I need…

My addon looks like this:

/my-addon
  /addon
  /app
  /bower_components
  /node_modules
  /tests
  package.json
  Brocfile.js etc..

package.json:

{
  "name": "my-addon",
  "version": "0.0.1",
  "directories": {
        "doc": "doc",
        "test": "tests"
  },
  "scripts": {
        "start": "ember server",
        "build": "ember build",
        "test": "ember test"
  },
  "engines": {
        "node": ">= 0.10.0"
  },
  "devDependencies": {
        "body-parser": "^1.2.0",
        "broccoli-sass": "0.3.2",
        "broccoli-asset-rev": "0.3.1",
        "broccoli-ember-hbs-template-compiler": "^1.6.1",
        "ember-cli": "0.1.2",
        "ember-cli-content-security-policy": "0.3.0",
        "ember-cli-ic-ajax": "0.1.1",
        "ember-cli-inject-live-reload": "^1.3.0",
        "ember-cli-qunit": "0.1.0",
        "ember-data": "1.0.0-beta.10",
        "ember-export-application-global": "^1.0.0",
        "express": "^4.8.5",
        "glob": "^4.0.5"
    }
    "keywords": [
        "ember-addon"
    ],

    "ember-addon": {
        "configPath": "tests/dummy/config"
    }
}

Thanks

All you should need to do is include the addon into your consuming ember-cli app’s package.json (possibly via npm install --save-dev my-addon-name) as described in The Ember CLI - Introduction - Ember CLI Guides. Installing in this way should not result in the addon’s dev dependencies being re-downloaded or included into the consuming app.

The way I’m doing it in my ember-cli app is using a git link, it looks something like that:

 "devDependencies": {
    "my-addon": "git+ssh://git@10.0.0.1:projects/my-addon.git#master"
  }

Basically, I think because it’s a link to a git repository on a private server, it downloads everything from this git repo which actually contains the full addon project

My project looks like that after the install:

/my-project
  /app
  /node_modules
    /my-addon
      /addon
      /app
      /bower_components
      /node_modules
      /tests
      package.json
      Brocfile.js etc..

@tilix I think you should add bower_components, node_modules etc to your .gitignore so that it doesn’t get checked in to github. Now, when your main project fetches this addon from devDependencies, there will be no bower_componets, node_modules in your final build.

1 Like