Reputation: 12810
I'm working with Mac OS X 10.7.5 and I'm using Grunt to concate some js files and minify them. Now I want to also minify my css files. As grunt does not provide any functionality I wanted to install a grunt plugin for that. According to the instructions i have to cd into my projects root folder and install the plugin with 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
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.
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. 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
[email protected] ../../node_modules/grunt-contrib-mincss
├── [email protected]
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected])
Why is the plugin installed outside? Or is there a way to define the actual location where it is installed?
Upvotes: 4
Views: 9861
Reputation: 456
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.
anyway, it's not your(and mine) fault. XD
Upvotes: 0
Reputation: 5729
I have seen cases where not having a package.json
file present caused the modules to be installed globally. 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. After that, install using npm install grunt-contrib-css --save
to have it added to your package.json
file. You can also use --save-dev
to have it added to your devDependencies.
Upvotes: 1
Reputation: 950
In my case, I forgot to add:
grunt.loadNpmTasks('grunt-jsdoc-plugin');
to grunt.js, so it should look like this:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jsdoc : {
dist : {
src: ['frontend/js/**/*.js'],
dest: 'docs/frontend'
}
}
});
grunt.loadNpmTasks('grunt-jsdoc-plugin');
};
Upvotes: 0
Reputation: 2733
I had a similar issue on Ubuntu 12.04 for the module grunt-jasmine-task
(same error message as above). This solved the issue for me:
node_modules
in the root of the project.npm install grunt-jasmine-task
again.Upvotes: 4
Reputation: 8236
This way to install worked for me:
cd <PROJECT_ROOT>
.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.
Script worked.
Possible reasons why it didn't work in your case:
Please check it.
Upvotes: 3