【问题标题】:Bower and devDependencies vs dependenciesBower 和 devDependencies 与依赖项
【发布时间】:2013-10-20 18:41:06
【问题描述】:

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

我很好奇 devDependencies 是如何使用的,以及我是否应该手动修复它或保持原样。有没有办法在 Bower CLI 上指定如何将某些东西标记为开发依赖项?

编辑文件后:

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

【问题讨论】:

    标签: bower


    【解决方案1】:

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

    dependencies 是生产使用所必需的,并且假定也是开发所必需的。

    dependencies中包含devDependencies,你有它,不会有害;该模块将在安装期间捆绑更多文件(字节) - 消耗更多(不必要的)资源。从纯粹的 POV 来看,这些额外的字节可能是有害的,这取决于您的观点。

    为了说明问题,看看bower help installdevDependencies 下列出的模块可以在通过-p--production 安装模块期间省略,例如:

    bower install angular-latest --production
    

    这是为开发平台以外的任何设备执行安装的推荐方法。

    相反,没有办法省略dependencies下列出的模块。


    截至 bower@1.2.7(参见 bower latest source),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 产生(参见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.
    

    【讨论】:

    • 当你从 bower.json 中删除不需要的 deps 时,有没有办法让 bower 自动删除它们?
    • @FutuToad,我还没有尝试过,但是 bower update(获取删除旧的 deps 的最新版本)后跟 bower prune(删除无关的本地包)可能会解决问题.
    • @MichaelTrouw 这是不可能的,因为目录结构是基本的。我建议在您的开发机器(或其他暂存环境)上的另一个目录中执行生产安装,通过 FTP 将其快照上传到目标。
    • @Edgar 您的生产代码不应依赖于您的devDependencies,因此在正常运行时,它不属于您的引导代码、逻辑或应用程序的任何其他方面。只有当您尝试运行与开发相关的任务(构建脚本、测试套件等)时,您才会得到模块未找到。如果您需要更多信息,请在 SO 上提出一个新问题。最后,考虑从 bower 迁移出来,因为它几乎已被弃用:github.com/bower/bower/issues/2298
    猜你喜欢
    • 1970-01-01
    • 2018-09-19
    • 2013-08-18
    • 2014-10-26
    • 1970-01-01
    • 2017-11-19
    • 2023-01-24
    • 2020-06-15
    • 2015-05-17
    相关资源
    最近更新 更多