javascript - 使用 grunt 自动化 npm 和 bower 安装

标签 javascript node.js npm bower gruntjs

我有一个 Node/Angular 项目,它使用 npm 进行后端依赖管理,使用 bower 进行前端依赖管理。我想使用 grunt 任务来执行这两个安装命令。我一直不知道该怎么做。

我尝试使用 exec,但它实际上并没有安装任何东西。

module.exports = function(grunt) {

    grunt.registerTask('install', 'install the backend and frontend dependencies', function() {
        // adapted from http://www.dzone.com/snippets/execute-unix-command-nodejs
        var exec = require('child_process').exec,
            sys  = require('sys');

        function puts(error, stdout, stderr) { console.log(stdout); sys.puts(stdout) }

        // assuming this command is run from the root of the repo
        exec('bower install', {cwd: './frontend'}, puts);
    });

};

当我 cd 进入前端时,打开 node,并从控制台运行此代码,这工作正常。我在 grunt 任务中做错了什么?

(我也尝试使用 bower 和 npm API,但也无法使用。)

最佳答案

要在 npm install 期间安装客户端组件,同时安装服务器端库,您可以添加 package.json

"dependencies": {
    ...
    "bower" : ""
},
"scripts": {
    ...
    "postinstall" : "bower install"
}

我更喜欢区分安装和测试/构建

关于javascript - 使用 grunt 自动化 npm 和 bower 安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14166591/

相关文章:

javascript - 类型错误 : Cannot read properties of undefined (reading 'split' ) happened when I try to run "npm run compile"

git - SSL_connect : SSL_ERROR_SYSCALL in connection to github. com:443

javascript - Node.js/Express.js - 如何覆盖/拦截 res.render 函数?

javascript - 将 html 元素大小调整为最大浏览器大小

javascript - 不使用 Ext.getCmp 获取复选框值

javascript - 如何更改 React 应用程序中静态资源的缓存策略(使用 create-react-app 创建)

javascript - 如何防止 sailsjs 文件上传覆盖

node.js - Selenium 网络驱动程序 : Connection refused (Connection refused)

javascript - 在 Node.js 中监听所有发出的事件

javascript - npm 风格的 Emacs JS 模式