I've just set up Grunt for my project and I'm trying to run min task but I get the error:
Task 'min' not found
Here is my gruntfile.js:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
min: {
dist: {
src: "calculator/add.js",
dest: "add.min.js"
}
}
});
};
What could be wrong here? Thanks!
You need to load the npm module containing the task in to grunt. Update your Gruntfile so it looks like the example below.
Please note, that you need to have the correct name for the npm module to be loaded in. Although the grunt task may be called min, this is probably not the case for the npm module. I referenced grunt-example-min in the example file below, so be sure to update this to the correct name.
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
min: {
dist: {
src: "calculator/add.js",
dest: "add.min.js"
}
}
});
grunt.loadNpmTasks('grunt-example-min');
grunt.registerTask('default',['min']);
};
Related
I'm trying to convert .css files to .sass files using 'grunt-sass-convert' npm module.
'Gruntfile.js' for the same is as follows:
'use strict';
module.exports = function(grunt){
grunt.loadNpmTasks('grunt-sass-convert');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Sass: {
options: {
// command line options here
style: 'expanded',
from: 'css',
to: 'sass'
},
files: {
// Target-specific file lists and/or options go here.
cwd: 'style',
src: '*.css',
filePrefix: '_',
dest: 'sass/'
}
}
});
grunt.registerTask('default',['Sass']);
};
I referred grunt-sass-convert npm module documentation for writing the GruntFile.js file.
While running the grunt command in cmd, I'm getting the following error:
Warning: Task "Sass" not found. Use --force to continue.
Aborted due to warnings.
I went through so many stackoverflow links regarding the same but I'm unable to fix it and All I understood that there's some error in .js file that's why it's throwing the error.
Directory structure I'm using is as here
Thanks..!!
I guess this would help you -
'use strict';
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Sass: {
options: {
// command line options here
style: 'expanded',
from: 'css',
to: 'sass'
},
files: {
// Target-specific file lists and/or options go here.
cwd: 'style',
src: '*.css',
file_prefix: '_',
dest: 'sass/'
}
}
});
grunt.loadNpmTasks('grunt-sass-convert');
grunt.registerTask('default',['Sass']);
};
Sorry, I'm newbie in npm-bower-grunt services. Maybe this question is stupid, but I can't find solution in google.
So, I have installed single page app based on npm/bower/grunt/angular.js
In the root I have gruntfile.js with this code
module.exports = function(grunt) {
var gtx = require('gruntfile-gtx').wrap(grunt);
gtx.loadAuto();
var gruntConfig = require('./grunt');
gruntConfig.package = require('./package.json');
gtx.config(gruntConfig);
// We need our bower components in order to develop
gtx.alias('build:standardversion', [
'compass:standardversion',
...
]);
gtx.finalise();
};
Else I have file grunt/compass.js with:
module.exports = {
standardversion: {
options: {
config: 'STANDARD/master/config.rb'
}
}
};
Then in bower_components folder I have gruntfiles for each plugin with code something like:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma: {
...
},
uglify: {
...
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('default', [
'karma',
'uglify'
]);
};
So now I have to install css-flip plugin from here https://www.npmjs.com/package/grunt-css-flip
I installed it with npm and now I don't know where to write a task for this.
Am I need to create new file in bower_components or somewhere else?
Please tell me or give me a link to understand it properly
Thanx
I would like to set up grunt sweet so that I can have it start watching my sweetjs-using files and compile them as they change.
However, I am new to making gruntfiles and there is simply not enough information in that link for me to know how to set it up. Searching for files that use grunt.loadNpmTasks('grunt-sweet'); I was able to find a file to use as a template but I cannot get it working.
This gruntfile
/*global module:false*/
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
sweet: {
content_dir: 'src',
publish_dir: 'build',
},
watch: {
sweet: {
files: [
'src/**'
],
tasks: 'sweet'
}
}
});
grunt.loadNpmTasks('grunt-sweet');
// Project tasks
grunt.registerTask('default', 'sweet');
};
Gives me
W:\sweetjs-playground> grunt sweet:watch
Running "sweet:watch" (sweet) task
Fatal error: Object #<Object> has no method 'done'
W:\sweetjs-playground> grunt sweet -v
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Initializing config...OK
Registering "grunt-sweet" local Npm module tasks.
Reading W:\sweetjs-playground\node_modules\grunt-sweet\package.json...OK
Parsing W:\sweetjs-playground\node_modules\grunt-sweet\package.json...OK
Loading "sweet.js" tasks...OK
+ sweet
Loading "Gruntfile.js" tasks...OK
+ default
Running tasks: sweet
Running "sweet" task
Verifying property sweet exists in config...OK
Fatal error: Object #<Object> has no method 'done'
Which seems like a success until it's not. What am I doing wrong here?
All I want is for it to automatically compile files in src into build
I'm not an expert on this, but you can try out this snippet. I hope it can help some way.
module.exports = function(grunt) {
grunt.initConfig({
sweetjs: {
src: {
files: [{
expand: true,
cwd: 'src/',
src: ['**/*.js'],
dest: 'build/'
}]
}
},
watch: {
sweetjs: {
files: ['src/**/*.js'],
tasks: ['sweetjs:src']
}
}
});
grunt.event.on('watch', function(action, filepath, target) {
if(action == 'changed' && target == 'sweetjs') {
grunt.config.set('sweetjs.src.src', [filepath]);
grunt.config.set('sweetjs.src.dest', filepath.replace(/^src/, 'build'));
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sweet.js');
grunt.registerTask('default', ['sweetjs']);
};
If it wont work, maybe your files path is the problem. Try out adding an extension src: ['src/**/*{.php,.html}'],
i dont know if thats the reason for your error, but i think so. delete the comma after sweets last config-property:
publish_dir: 'build', <--
I have installed grunt-cli,grunt(local),grunt-init. Below is the simple grunt file to minify javascript files in source folder.
module.exports = function (grunt) {
grunt.initConfig({
min: {
dev: {
src: 'calculator/*.js',
dest: 'calculator.min.js'
}
}
});
};
when I run grunt, it does nothing, nor it gives any message out. nor does grunt --help or grunt --version..none of them seem to say anything. but if I dont' have grunt.js file it does complain about the grunt file not existing and help gives the details..
What you need to do is add a task that then calls min. To get it to run by just using grunt you must call this task default.
If you call it anything else (e.g. development, you must run grunt development)
You also need to make sure you have the necessary dependencies installed with npm. So min you probably want to minify JS with the gruntjs uglify module.
From the docs:
Install this plugin with this command:
npm install
grunt-contrib-uglify --save-dev
Once the plugin has been installed,
it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-contrib-uglify');
For example, here are some snippets from one of my Gruntfile.js
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var yeomanConfig = {
app: 'resources',
dist: 'dist'
};
grunt.initConfig({
yeoman: yeomanConfig,
uglify: {
dist: {
files: {
'<%= yeoman.dist %>/js/scripts.js': [
'<%= yeoman.app %>/js/lib/*.js'
],
'<%= yeoman.dist %>/js/output.js': [
'<%= yeoman.app %>/js/*.js'
],
}
}
},
});
grunt.registerTask('default', [
// 'jshint',
// 'test',
'uglify'
]);
The above sets up an uglify task and then the grunt.registerTask('default'.. part calls uglify when I run grunt.
The above was generated and used as part of the yeoman workflow.
Just Getting started with grunt, and when I run grunt I get this error
Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: grunt is not defined
This is my Gruntfile.js
module.exports = function(grunt){
'use strict';
};
I had it suddenly happen to me,
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
sass: {
dist: {
files: {
'style.css': 'style.scss'
},
options: {
includePaths: ['css/'],
outputStyle: 'nested'
}
}
},
});
grunt.loadNpmTasks('grunt-sass');
grunt.registerTask('sass', ['sass']);
};
Make sure the loadNpmTasks and registerTask commands are inside the module.export, if they're outside of the scope of that closure grunt won't be defined, so it fails
Not entirely sure why, but this resolved that issue:
'use strict';
module.exports = function(grunt){
};
I too saw many "grunt not defined" error messages on my terminal.
I grabbed another gruntfile.js from the same directory where I had Node and NPM installed, and replaced the boilerplate gruntfile.js with the other gruntfile.js.
Now, I call Grunt and it works.
I had trailing commas in my gruntfile code which was throwing that error. Thank you ReSharper. Hope this helps someone.
pkg: grunt.file.readJSON('package.json'),
ngAnnotate: {
options: {
singleQuotes: true
},
FFApp: {
files: {
'Scripts/Angular-Annotated/Annotated.js': ['Scripts/Angular/**/*js']
}
, (< deleted this)
}
,(< and this one)
},