Bower和devDependencies与依赖关系


159

我运行了“ yo angular”,然后意识到它安装了1.0.8,我卸载了angular组件,但是当我重新添加所有1.2时,原始的bower.json文件在“ devDependencies”下有angular-mocks和angular-scenario。 0-rc.2组件下的依赖项而不是devDependencies下的angular-mocks和angular-scenario。

我对devDependencies的使用方式以及是否应该手动修复它或保留原样感到好奇。有没有一种方法可以在Bower CLI中指定如何将某些内容标记为dev依赖项?

编辑文件后:

{
    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: { }
}

编辑之前:

{
    "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"
    }
}

Answers:


284

devDependencies 用于与开发相关的脚本,例如单元测试,打包脚本,文档生成等。

dependencies 是生产用途所必需的,而开发人员也假定是必需的。

包括devDependenciesdependencies,因为你拥有它,也不会是有害的; 该模块将在安装过程中捆绑更多文件(字节),从而消耗更多(不必要的)资源。从纯粹的POV来看,这些额外的字节可能是有害的,仅取决于您的角度。

为了使您更加了解,在模块安装过程中,可以通过或省略bower help install下面列出devDependencies的模块,例如:-p--production

bower install angular-latest --production

建议使用此方法对开发平台以外的任何其他设备执行安装。

相反,无法忽略列出的模块dependencies


bower@1.2.7起(请参见bower最新资料),bower help得出:

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.

以及bower help install产量(请参阅最新资料):

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.

从Bower.json中删除不需要的Deps时,有没有办法让Bower自动删除?
FutuToad 2014年

1
@FutuToad,我还没有尝试过,但是bower update(先删除旧的dep以获得最新版本)然后再bower prune(删除多余的本地软件包)也许可以解决问题。
zamnuts 2014年

1
@MichaelTrouw这是不可能的,因为目录结构是基本的。我建议在开发机器(或其他暂存环境)上的另一个目录中执行生产安装,然后通过FTP将其快照上传到目标。
zamnuts 2014年


1
@Edgar您的生产代码不应取决于您的devDependencies,因此在正常运行时不属于您的引导程序代码,逻辑或应用程序的任何其他方面。仅当您尝试运行与开发相关的任务(构建脚本,测试套件等)时,才会获得未找到的模块。如果您需要更多信息,请在SO上提出一个新问题。最后,考虑从凉亭迁移,因为它已经过时了:github.com/bower/bower/issues/2298
zamnuts
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.