[英]Grunt plugins are not installed in current location
I'm working with Mac OS X 10.7.5 and I'm using Grunt to concate some js files and minify them. 我正在使用Mac OS X 10.7.5,我正在使用Grunt来连接一些js文件并缩小它们。 Now I want to also minify my css files.
现在我想缩小我的CSS文件。 As grunt does not provide any functionality I wanted to install a grunt plugin for that.
由于grunt没有提供任何功能,我想为此安装一个grunt插件。 According to the instructions i have to cd into my projects root folder and install the plugin with npm.
根据说明我必须进入我的项目根文件夹并使用npm安装插件。 So I did the following:
所以我做了以下事情:
cd <PROJECT_ROOT>
npm install grunt-contrib-css
The instructions for the plugin are here: https://npmjs.org/package/grunt-contrib-mincss The I opened my grunt.js file and added 插件的说明如下: https ://npmjs.org/package/grunt-contrib-mincss我打开了我的grunt.js文件并添加了
grunt.loadNpmTasks('grunt-contrib-mincss');
But when I try to run grunt I just get 但是,当我试图运行咕噜声时,我才得到
Local Npm module "grunt-contrib-mincss" not found. Is it installed?
<WARN> Task "mincss" not found. Use --force to continue. </WARN>
The installation works without any problem and npm ls does list the module. 安装工作没有任何问题,npm ls列出了模块。
Any ideas what I have done wrong? 我做错了什么想法? Many Thanks!
非常感谢!
UPDATED 更新
When I cd into a project like so 当我进入这样的项目时
cd ~/Sites/path/to/project
and then install the plugin 然后安装插件
sudo npm install grunt-contrib-mincss
the module is actually installed in 该模块实际安装在
~/node_modules/grunt-contrib-mincss
I could hard copy the files into my projects root directory (which works) but it's kind of strange isn't it? 我可以将文件硬复制到我的项目根目录(这是有效的),但它有点奇怪不是吗?
UPDATE 2 I've updated node and tried it again. 更新2我已更新节点并再次尝试。 Below is the console output.
下面是控制台输出。
me:~ Fritz$ node -v
v0.8.10
me:~ Fritz$ npm -v
1.1.62
me:~ Fritz$ mkdir ./Sites/npm-test
me:~ Fritz$ cd ./Sites/npm-test/
me:npm-test Fritz$ sudo npm install grunt-contrib-mincss
Password:
npm http GET https://registry.npmjs.org/grunt-contrib-mincss
npm http 304 https://registry.npmjs.org/grunt-contrib-mincss
npm http GET https://registry.npmjs.org/gzip-js
npm http GET https://registry.npmjs.org/clean-css
npm http GET https://registry.npmjs.org/grunt-contrib-lib
npm http 304 https://registry.npmjs.org/gzip-js
npm http 304 https://registry.npmjs.org/clean-css
npm http 304 https://registry.npmjs.org/grunt-contrib-lib
npm http GET https://registry.npmjs.org/crc32
npm http GET https://registry.npmjs.org/deflate-js
npm http GET https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/deflate-js
npm http 304 https://registry.npmjs.org/crc32
npm http 304 https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/wordwrap
grunt-contrib-mincss@0.3.0 ../../node_modules/grunt-contrib-mincss
├── grunt-contrib-lib@0.3.0
├── gzip-js@0.3.1 (crc32@0.2.2, deflate-js@0.2.2)
└── clean-css@0.4.2 (optimist@0.3.4)
Why is the plugin installed outside? 为什么插件安装在外面? Or is there a way to define the actual location where it is installed?
或者有没有办法定义安装它的实际位置?
I had a similar issue on Ubuntu 12.04 for the module grunt-jasmine-task
(same error message as above). 我在Ubuntu 12.04上遇到类似的问题
grunt-jasmine-task
模块(与上面相同的错误信息)。 This solved the issue for me: 这解决了我的问题:
node_modules
in the root of the project. node_modules
。 npm install grunt-jasmine-task
again. npm install grunt-jasmine-task
。 This way to install worked for me: 这种安装方式对我有用:
cd <PROJECT_ROOT>
. cd <PROJECT_ROOT>
。 npm install grunt-contrib-mincss
. npm install grunt-contrib-mincss
。 Created test file in the current dir with the following testing content: 使用以下测试内容在当前目录中创建测试文件:
module.exports = function(grunt) { grunt.initConfig({ mincss: { compress: { files: { "path/to/output.css": ["path/to/input_one.css", "path/to/input_two.css"] } } } }); grunt.loadNpmTasks('grunt-contrib-mincss'); grunt.registerTask('default', 'mincss'); };
My directory structure looks like this at this moment (please check this, if some files are not there or in some other folder, then it can be reason why it doesn't work): 我的目录结构此时看起来像这样(请检查一下,如果某些文件不在那里或在其他文件夹中,那么它可能是它不起作用的原因):
<PROJECT_ROOT> / node_modules / grunt-contrib-mincss/ grunt.js
Run grunt
in terminal. 在终端中运行
grunt
。
Script worked. 脚本有效。
Possible reasons why it didn't work in your case: 在您的情况下它不起作用的可能原因:
Please check it. 请检查一下。
I have seen cases where not having a package.json
file present caused the modules to be installed globally. 我见过没有
package.json
文件的情况导致模块全局安装。 I'm not sure what version was running at the time, as it was not my machine. 我不确定当时正在运行什么版本,因为它不是我的机器。
Next time try running npm init
prior to installing modules. 下次在安装模块之前尝试运行
npm init
。 After that, install using npm install grunt-contrib-css --save
to have it added to your package.json
file. 之后,使用
npm install grunt-contrib-css --save
将它添加到package.json
文件中。 You can also use --save-dev
to have it added to your devDependencies. 您还可以使用
--save-dev
将其添加到您的devDependencies中。
In my case, I forgot to add: 在我的情况下,我忘了添加:
grunt.loadNpmTasks('grunt-jsdoc-plugin');
to grunt.js, so it should look like this: 到grunt.js,所以看起来应该是这样的:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jsdoc : {
dist : {
src: ['frontend/js/**/*.js'],
dest: 'docs/frontend'
}
}
});
grunt.loadNpmTasks('grunt-jsdoc-plugin');
};
If you take a look under the grunt-contrib-mincss folder, there is a readme file, they changed name from grunt-contrib- mincss to grunt-contrib- cssmin . 如果你把咕噜-的contrib-mincss文件夹下的样子,有一个自述文件,他们从繁重的-contrib- mincss更名为咕噜-contrib- cssmin。
anyway, it's not your(and mine) fault. 无论如何,这不是你(和我的)的错。 XD
XD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.