new to grunt - warning: task "concat, uglify" not found - javascript

As the title says I'm new to Grunt. I am following a tutorial located at: http://24ways.org/2013/grunt-is-not-weird-and-hard/. It is an older tutorial but most seems to work the same. I have installed "grunt-contrib-concat" and "grunt-contrib-uglify" and can run both individually. But when I run grunt, I get the following error: Warning: Task "concat, uglify" not found. Use --force to continue. Aborted due to errors. I've been looking around and can't seem to figure it out. My files are as follows:
Gruntfile.js:
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'js/libs/*.js', // All JS in the libs folder
'js/controls.js', // This specific file
],
dest: 'dist/built.js',
}
},
uglify: {
build: {
src: 'js/build/production.js',
dest: 'js/build/production.min.js',
}
},
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
// 4. Where we tell Grunt what to do when we type 'grunt' into the terminal.
grunt.registerTask('default', ['concat, uglify']);
};
package.json:
{
"name": "grunt_libsass_example-project",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-uglify": "^0.9.1"
}
}

Your passing in only one string for the registerTask task list. It should be a array with a list of strings like:
grunt.registerTask('default', ['concat', 'uglify']);
You're getting that error because it's looking for a task named 'concat, uglify'.

I had to run:
npm install grunt-contrib-uglify --save-dev

Related

Error when typing cmd grunt jshint.

I am currently going to the Learn how to Program with Steve Foote. I am using ubuntu as the operating system.I have installed Node.js, installed the grunt command-line, and installed the npm install to the correct folder.
I noticed a problem that when I ran node on the specified folder it wouldn't run the js files I have. I even went to the folder with the js files and it didn't work. I then tried node values.js but nothing came up.
This is my code for the package.json file:
{
"name": "kittenbook",
"version": "0.0.1",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-jshint": "~0.6.3"
}
}
And this is the Gruntfile.js
module.exports = function(grunt) {
//Project Configuiration
grunt.initConfig({
/*
* We will configuire our tasks here
*/
concat: {
release: {
src:['js/values.js', 'js/prompt.js'],
dest: 'release/main.js'
}
},
copy: {
release{
src: 'manifest.json',
dest: 'release/manifest.json'
}
},
jshint: {
files: ['js/values.js', 'js/prompt.js']
}
});
//We will load our plugins here
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
//We will register our tasks here
grunt.registerTask('default', ['jshint', 'concat', 'copy']);
};
Sorry if the formatting is bad here it genuinely is all lined up on the text file.
When I type grunt jshint a warning comes up saying:
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token {
Warning: Task "jshint" not found. Use --force to continue.
Aborted due to warnings.
You are missing a colon (:) in your grunt.initConfig object.
copy: {
release{ /*<--Missing colon in between "release" and the opening bracket {*/
src: 'manifest.json',
dest: 'release/manifest.json'
}
},

Grunt + Babel successfully runs but doesn't do anything

I'm rather new to grunt/npm but after reading up the docs. I have made myself a package.json and a Gruntfile.js. Here's my folder structure:
/
|- src
|- myfile.es6
|- anotherfile.es6
|- etc.
|- Gruntfile.js
|- package.json
What I have
Here's my Gruntfile:
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
babel: {
options: {
sourceMap: true,
plugins: ['es2015']
},
dist: {
files: [{
expand: true,
cwd: 'src/',
src: ['*.es6'],
dest: 'dist/',
ext: '.js'
}]
}
}
});
grunt.registerTask('default', ['babel'])
};
And then here's my package.json:
{
"name": "Cheddar",
"version": "0.2.0",
"devDependencies": {
"babel-preset-es2015": "^6.6.0",
"grunt": "^1.0.1",
"grunt-babel": "^6.0.0"
},
"scripts": {
"test": "grunt --verbose"
}
}
What does it do?
I have my src/ folder which contains my source files (*.es6). I want to transpile these to a dist/ directory with grunt.
What I've tried
Then I installed all the dependencies / babel-cli / grunt-cli/ etc. with npm install and npm-update --save
Seems good, so I went ahead and ran grunt:
$ grunt
Running "babel:dist" (babel) task
Done.
$ ls
Gruntfile.js node_modules/ package.json src/
The ls is outputting the exact same thing as before I ran grunt. So nothing is appearing to happen. Where's my output dist? This has been bugging me for the past few hours. I've tried installing babelify, and quite a few other fixes from blogs across the internet but alas, nothing works.
Try using the keyword "presets" instead of "plugins":
babel: {
options: {
sourceMap: true,
presets: ['es2015']
}
...
}
When I use your configuration, grunt seems to error out because it can't find the plugin called "es2015". Everything worked after I made that change.
Try a more literal example from the README like:
grunt.initConfig({
babel: {
options: {
sourceMap: true,
presets: ['es2015']
},
dist: {
files: {
'dist/myfile.js': 'src/myfile.es6'
}
}
} });
After you get that working try specifying *.es6 etc. under files. If you look at the source for the grunt-babel plugin it may be more limited than one would assume.
You can also just use npm scripts and specify the babel command line directly which I feel is simpler than using grunt.

Grunt tasks stuck in endless loop

Working on putting together a base Gruntfile.js for some upcoming projects. Starting in on a new computer so everything has been a fresh build. Installed Node and NPM using Homebrew, and then installed Grunt globally, as well as in my local directory.
Here is my package.json:
{
"name": "timespent-prototype",
"version": "0.1.0",
"devDependencies": {
"assemble": "0.4.37",
"bower": "^1.4.1",
"grunt": "^0.4.5",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-newer": "^1.1.0",
"grunt-wiredep": "^2.0.0"
}
}
And here is my Gruntfile.js:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
vendor: {
src: ['vendor/**/*.min.js'],
dest: 'build/javascripts/library.js',
}
},
// Takes your scss files and compiles them to css
sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'build/stylesheets/application.css': 'app/stylesheets/application/index.scss'
}
}
},
// Assembles your templates into HTML files
assemble: {
options: {
layoutdir: 'app/views/layouts/',
partials: ['app/views/partials/*.hbs'],
flatten: true,
expand: true
},
pages: {
src: ['app/views/**/*.hbs','!app/views/layouts/*.hbs','!app/views/partials/*.hbs'],
dest: 'build/'
}
},
wiredep: {
task: {
src: ['app/views/layouts/*.hbs']
}
},
// Watches for file changes, runs the default task
watch: {
files: ['app/**/*'],
tasks: ['default'],
options: {
// Start another live reload server on port 1337
livereload: 1337,
}
}
});
// Load the plugins
grunt.loadNpmTasks('assemble');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-wiredep');
// Register the tasks
grunt.registerTask('default', ['sass','assemble']);
grunt.registerTask('watch', ['watch']);
grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);
};
The problem that I am seeing is that with multiple tasks, here specifically with wiredep and concat, the task gets stuck in a loop and never ends. Running grunt concat with verbose outputs like this:
Registering "grunt-contrib-concat" local Npm module tasks.
Reading /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Parsing /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Loading "concat.js" tasks...OK
+ concat
Running tasks: concat
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
Running "concat" task
Where Running "concat" task will continue to print until I stop it. As I am seeing this with multiple plugins and tasks this might be a problem with my installation of NPM or Grunt, but I'm having a very hard time debugging this. If anyone has run into this before, please let me know what helped!
Thanks!
Edit: in response to Alireza Ahmadi's comment, here is my file structure:
.
|
|_ app/
|_ assets/
|_ javascript/
|_ stylesheets/
|_ views/
|
|_ build/
|_stylesheets/
|_javascripts/
|
|_ vendor/
|_ bower.json
|_ Gruntfile.js
|_ package.json
In the last 2 lines of your Gruntfile.js you have redeclared the concat and wiredep tasks and when grunt tries to run your code, It stuck in an endless loop because concat refers to an undefined concat task, So you should remove these lines:
grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);
In general, When you define a task named foobar with grunt.initConfig, It's defined and does not need to registered using registerTask and it can be accessible by grunt foobar command.

Grunt: Task "grunt-bower" not found

I want to install package grunt-bower for my grunt by using npm install grunt-bower --save. After I install, I see package grunt-bower inside node_modules. Here is my gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
bower: {
dev: {
dest: 'public',
js_dest: 'public/javascripts',
css_dest: 'public/stylesheets'
}
},
watch: {
source: {
files: ['sass/**/*.scss', 'views/**/*.jade'],
tasks: ['sass'],
options: {
livereload: true, // needed to run LiveReload
}
}
}
});
grunt.loadNpmTasks('grunt-bower');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['grunt-bower']);
};
I have register this as on official page : grunt.loadNpmTasks('grunt-bower'); But when I run grunt command, I meet this error:
Warning: Task "grunt-bower" not found. Use --force to continue.
I don't know why. Does I do something wrong ? Please tell me.
Thanks :)
You've defined the task you want to run as bower and not grunt-bower therefore,
grunt.registerTask('default', ['grunt-bower']);
should be
grunt.registerTask('default', ['bower']);

Getting errors when running a grunt.js task

I'm using the uncss task with grunt.js in order reduce the size of my CSS by removing unused rules.
Here's the url for uncss: https://github.com/addyosmani/grunt-uncss
This is my Gruntfile.js setup:
module.exports = function(grunt) {
grunt.initConfig({
uncss: {
dist: {
files: {
'docs/tidy.css': ['docs/index.html']
}
},
options: {
compress:true
}
},
processhtml: {
dist: {
files: {
'docs/tidy.css': ['docs/index.html']
}
}
}
});
grunt.loadNpmTasks('grunt-uncss');
grunt.loadNpmTasks('grunt-processhtml');
grunt.registerTask('default', ['uncss','processhtml']);
};
And this is my package.json:
{
"name": "ProjectName",
"version": "0.0.1",
"private": true,
"devDependencies": {
"grunt": "~0.4.2",
"grunt-uncss": "~0.1.5",
"grunt-processhtml": "~0.2.7"
}
}
All the dependencies were installed fine, without any errors...
But when I run grunt or grunt uncss, I get the following error:
Running "uncss:dist: (uncss) task
[SyntaxError: Unmatched selector:(http]
>> Uncssing source "docs/index.html" failed.
Warning: Uncss failed. Use --force to continue.
Aborted due to warnings.
Does anybody have any idea what this error means and how to correct it? I searched and searched and I was unable to find any documentation that covers this.
Maybe you're using an unsupported selector, like in this issue : https://github.com/addyosmani/grunt-uncss/issues/14
It looks like you could have a syntax error in your css. Either that or you have a bug in your css. You could run using --force like the error hints at, which I'm assuming will ignore that single rule.
You could look for a selector that looks like this in your css file: (http

Categories

Resources