【发布时间】:2016-09-28 23:29:14
【问题描述】:
我有一个 Gruntfile 来安装一些 npm 并制作其他功能。
问题是:npm的下载工作正常,但是在全局下载node_modules
/User/my_user/node_modules
我希望 gruntfile 在我的项目中本地下载 nom 而无需指定路径。
这是我的 grunt 文件的一部分:
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
返回我没有找到模块的错误,因为它不是本地的而是全局的..
我该如何解决?
谢谢
【问题讨论】:
-
确保您的 shell 命令在您的 CWD 中运行。
-
我不明白你为什么要把这些东西放在你的 Gruntfile 中。看起来它们应该在您的
package.json中,然后与npm install一起安装。