gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:50:48 26 4
gpt4 key购买 nike

我有一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com