我有一个Gruntfile来安装一些npm和其他功能。
问题是: npm的下载工作正常,但在
/User/my_user/node_modules我希望gruntfile在不指定路径的情况下动态地在项目中本地下载nom。
这是我的咕噜文件的一部分:
module.exports = function(grunt) {
grunt.initConfig({
shell: {
install: {
options: {
stdout: true,
stderr: true
},
command: [
"npm install grunt-contrib-sass",
"npm install node-sass",
"npm install grunt-contrib-less",
"npm install less",
"npm install grunt-contrib-watch",
"npm install grunt-contrib-clean",
"npm install grunt-contrib-copy",
"npm install grunt-csso",
"npm install grunt-deployments"
].join("&&")
},
install_test: {
options: {
stdout: true,
stderr: true
},
command: [
"sudo npm install -g phantomjs",
"npm install -g casperjs",
"mkdir app/Test/Frontend",
"sudo chmod -R 777 app/Test/Frontend"
].join("&&")
},
}
});
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-shell");
grunt.loadNpmTasks("grunt-csso");
grunt.loadNpmTasks("grunt-rsync");
grunt.registerTask("install", [
"shell:cake_tmp",
"shell:install",
"shell:install_test"
]);
};在我做完这些之后:
sudo npm install grunt
sudo npm install grunt-shell
grunt install返回错误,因为它找不到模块,因为不是本地的,而是全局的。
我该怎么解决呢?
谢谢
发布于 2014-02-20 12:36:01
这是一种非常粗野的工作方式。理想情况下,所有这些都应该进入根目录中的package.json。将其放入您的package.json中,如果有必要的更改,然后执行npm install,它将在本地安装包,preinstall钩子将在执行安装之前安装全局包。
{
"name": "appname",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-sass": "*",
"node-sass": "*",
"less": "*",
"grunt-concurrent": "*",
"grunt-contrib-clean": "*",
"grunt-contrib-watch": "*",
"grunt-contrib-less": "*",
"grunt-contrib-copy": "*",
"grunt-shell": "*",
"grunt-csso": "*",
"grunt-deployments": "*"
},
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"test": "grunt test",
"preinstall": "sudo npm install -g phantomjs && npm install -g casperjs"
}
}npm给出的钩子叫做预装、安装、后安装等,用它们来做-g安装。
请按照此链接获取更多信息
可以在Gruntfile.js中作为shell目标包括的其他任务
https://stackoverflow.com/questions/21867417
复制相似问题