160

I ran 'yo angular' and realized afterwards that it installs 1.0.8, I uninstalled the angular components, however the original bower.json file had angular-mocks and angular-scenario under 'devDependencies' when I re-add all the 1.2.0-rc.2 components angular-mocks and angular-scenario under dependencies instead of devDependencies.

I'm curious as to how devDependencies is used and if I should bother manually fixing it or leave as is. Is there a way to specify on the bower CLI how to mark something as a dev dependency?

After edits file:

{
    name: "Angular",
    version: "0.0.0",
    dependencies: {
        json3: "~3.2.4",
        jquery: "~1.9.1",
        bootstrap-sass: "~2.3.1",
        es5-shim: "~2.0.8",
        angular-mocks: "1.2.0-rc.2",
        angular-sanitize: "1.2.0-rc.2",
        angular-resource: "1.2.0-rc.2",
        angular-cookies: "1.2.0-rc.2",
        angular: "1.2.0-rc.2",
        angular-scenario: "1.2.0-rc.2"
    },
    devDependencies: { }
}

Before Edits:

{
    "name": "Angular",
    "version": "0.0.0",
    "dependencies": {
        "angular": "~1.0.7",
        "json3": "~3.2.4",
        "jquery": "~1.9.1",
        "bootstrap-sass": "~2.3.1",
        "es5-shim": "~2.0.8",
        "angular-resource": "~1.0.7",
        "angular-cookies": "~1.0.7",
        "angular-sanitize": "~1.0.7"
    },
    "devDependencies": {
        "angular-mocks": "~1.0.7",
        "angular-scenario": "~1.0.7"
    }
}
Gary
  • 2,241
  • 3
  • 19
  • 21

1 Answers1

287

devDependencies are for the development-related scripts, e.g. unit testing, packaging scripts, documentation generation, etc.

dependencies are required for production use, and assumed required for dev as well.

Including devDependencies within dependencies, as you have it, won't be harmful; the module will just bundle more files (bytes) during the install - consuming more (unnecessary) resources. From a purist POV, these extra bytes could be detrimental, just depends on your perspective.

To shed some light, looking at bower help install, modules listed under devDependencies can be omitted during the module installation via -p or --production, e.g.:

bower install angular-latest --production

This is the recommended way to perform an installation for anything other than a development platform.

On the contrary, there is no way to omit modules listed under dependencies.


As of bower@1.2.7 (see bower latest source), bower help yields:

Usage:

    bower <command> [<args>] [<options>]

Commands:

    cache                   Manage bower cache
    help                    Display help information about Bower
    home                    Opens a package homepage into your favorite browser
    info                    Info of a particular package
    init                    Interactively create a bower.json file
    install                 Install a package locally
    link                    Symlink a package folder
    list                    List local packages
    lookup                  Look up a package URL by name
    prune                   Removes local extraneous packages
    register                Register a package
    search                  Search for a package by name
    update                  Update a local package
    uninstall               Remove a local package

Options:

    -f, --force             Makes various commands more forceful
    -j, --json              Output consumable JSON
    -l, --log-level         What level of logs to report
    -o, --offline           Do not hit the network
    -q, --quiet             Only output important information
    -s, --silent            Do not output anything, besides errors
    -V, --verbose           Makes output more verbose
    --allow-root            Allows running commands as root

See 'bower help <command>' for more information on a specific command.

and further, bower help install yields (see latest source):

Usage:

    bower install [<options>]
    bower install <endpoint> [<endpoint> ..] [<options>]

Options:

    -F, --force-latest      Force latest version on conflict
    -h, --help              Show this help message
    -p, --production        Do not install project devDependencies
    -S, --save              Save installed packages into the project's bower.json dependencies
    -D, --save-dev          Save installed packages into the project's bower.json devDependencies

    Additionally all global options listed in 'bower help' are available

Description:

    Installs the project dependencies or a specific set of endpoints.
    Endpoints can have multiple forms:
    - <source>
    - <source>#<target>
    - <name>=<source>#<target>

    Where:
    - <source> is a package URL, physical location or registry name
    - <target> is a valid range, commit, branch, etc.
    - <name> is the name it should have locally.
zamnuts
  • 9,492
  • 3
  • 39
  • 46
  • is there a way to get bower to auto removed unneeded deps when you remove them from bower.json? – FutuToad Jan 07 '14 at 18:09
  • 1
    @FutuToad, I haven't tried it but a `bower update` (to get the latest version with the old deps removed) followed by a `bower prune` (deletes extraneous local packages) might do the trick. – zamnuts Jan 07 '14 at 22:48
  • is there maybe a way to have devDependancies install in a different folder than regular dependancies? that way, if you have no other access to a production server than FTP, you can copy over ONLY the dependancies folder to a /dist folder instead of copying over both dev dependancies and 'regular' dependancies? – Michahell Feb 11 '14 at 14:30
  • 1
    @MichaelTrouw this is not possible since the directory structure is fundamental. I'd suggest performing a production installation in another directory on your development machine (or other staging environment) uploading a snapshot of that via FTP to the target. – zamnuts Feb 24 '14 at 20:27
  • @zamnuts nice workaround/solution. Could be automated as well (better automate on a copy of- instead of development machine) – Michahell Feb 28 '14 at 20:54
  • Is there a way to exclude some dependencies in a development environment? For example, in prod, I route all errors to bugsnag rather than the console, but in dev, I want all my errors/exceptions to display in the console – Genu Jan 13 '15 at 22:34
  • 1
    @Genu, yes you can: https://github.com/blittle/bower-installer#ignore-files see SO question [Filter (include/exclude) files for Bower dependency](http://stackoverflow.com/questions/22263820/filter-include-exclude-files-for-bower-dependency) – zamnuts Jan 13 '15 at 22:52
  • What will happen with the `imported` `required` `devDependencies` that are not bundled in production? Shouldn't I get errors : `module not found`? – Edgar May 20 '17 at 11:33
  • 1
    @Edgar your production code should NOT depend on your `devDependencies`, and therefore is not part of your bootstrap code, logic, nor any other aspect of your application while running normally. Only if you attempt to run dev-related tasks (build scripts, test suites, etc.), you will get module not found. If you require further information, please ask a new question on SO. Lastly, consider migrating away from bower since it is pretty much deprecated: https://github.com/bower/bower/issues/2298 – zamnuts May 23 '17 at 05:58