grunt-contrib-jshint ignores has no effect - gruntjs

I would like to exclude libs directory from being lint'ed. However, ignores in options and planted .jshintignore file in project directory won't make libs to be excluded.
jshint: {
options: {
smarttabs: true,
ignores: ['public/js/libs/**/*.js']
},
all: [
'Gruntfile.js',
'public/js/**/*.js'
]
},
grunt version:
grunt-cli v0.1.11
grunt v0.4.2
grunt-contrib-jshint#0.7.2
What did I miss out?

ignores is a jshint option and expects specific files. It's better to use the idiomatic Grunt negate ! to exclude files:
jshint: {
options: {
smarttabs: true
},
all: [
'Gruntfile.js',
'public/js/**/*.js',
'!public/js/libs/**/*.js'
],
},
See http://gruntjs.com/configuring-tasks#globbing-patterns

Related

Sourcemaps with require.js

I am using grunt-contrib-requirejs to munge my files into a single file and generate a sourcemap. The sourcemap seems to be valid but is 6 lines off in the debuggers in both Chrome and Firefox. I have googled quite a bit but can't find any reasons why this would happen. Has anyone else come across a similar problem?
This is a very large project with about 200 files, i've c/p my grunt config for reference.
dev: {
options: {
baseUrl: 'assets/javascript',
optimize: 'none',
generateSourceMaps: true,
mainConfigFile: 'assets/javascript/requireconfig.js',
name: 'app',
preserveLicenseComments: false,
include: [
'plugins/dropdown-toggle',
'brand/modules/checkmate-init',
'brand/modules/batch-handler',
'brand/modules/dataset-editors',
'brand/modules/recording-editors',
'brand/modules/recording-state'
],
out: 'public/assets/js/myapp.js'
}
},
dist: {
options: {
baseUrl: 'assets/javascript',
optimize: 'uglify2',
generateSourceMaps: false,
mainConfigFile: 'assets/javascript/requireconfig.js',
name: 'app',
include: [
'plugins/dropdown-toggle',
'brand/modules/checkmate-init',
'brand/modules/batch-handler'
],
out: 'public/assets/js/myapp.js'
}
}
This could be related to an issue with https://github.com/requirejs/requirejs/issues/1054
Adding to r.js config:
skipPragmas:true
Did the trick for me.
r.js config:
https://github.com/requirejs/r.js/blob/2.2.0/build/example.build.js#L299

grunt-bower-task and Polymer

I cannot seem to find an easy way to copy all the files from Polymer to using grunt-bower-task.
grunt.initConfig({
bower: {
install: {
options: {
targetDir: 'wwwroot/lib',
layout: 'byComponent',
install: true,
copy: true,
verbose: true,
cleanTargetDir: false,
bowerOptions: {}
}
}
}
I understand that only the main files defined inside each element's bower.json file get copied over. I am also aware that I could put a exportsOverride section in my own bower.json to include more files like this -
"exportsOverride": {
"*": {
"": "*.*",
"demo": "demo/*.*",
"test": "test/*.*"
}
}
But this doesn't cover all cases as some elements have more sub-folders than just demo and test. Do I have to manually look them all up and add their paths to the exportsOverride, or there's an easy way that I've overlooked?
hate to provide a sample of a fail....
FWIW recently , i had very similar issue ... worked it and failed
what i did is abandon the attempt to flatten everything out in the "dist" tag for a first polymer project. Rather i just ran minify/ugly on one or two elements leaving the HTTP2 type file structure ( deep and many many, dirs/files. )
// the process belo NG . Manual edit needed on "polymer-min.html" go end and chg the js file name
copy: {
main: {
files: [
// includes files within path
{expand: true, src: ['*html'], dest: 'dest/', filter: 'isFile'},
// includes files within path and its sub-directories
{expand: true, src: ['js/**', 'images/**' ,'css/**' ,'elements/**' ,'bower_components/**'], dest: 'dest/'},
{ src: ['tmp/csp/build-csp.html'], dest: 'dest/bower_components/cast-button-polymer/cast-button-polymer-min.html',
filter: 'isFile',
options: {
process: function (content, srcpath) {
return content.replace(/build-csp.js/g,"cast-button-polymer-min.js");
},
},
},
{ src: ['tmp/csp/build-csp-min.js'], dest: 'dest/bower_components/cast-button-polymer/cast-button-polymer-min.js', filter: 'isFile'},
],
},
},

Using grunt contrib concat to get it's source files from index.html

I am using grunt-contrib-concat and I need a way to automate my vendor concatenation step.
Right now, I specify manually in my GruntFile what vendor libraries should be concatenated.
Is there a way to get their names from my index.html? Using just the contrib-concat plugin and not usemin?
Any ideas?
concat: {
app: {
files: {
'dist/js/app.js': [
'src/**/*.js',
'!src/**/*.spec.js', // Exlcude the spec files.
'tmp/*.js'
]
}
},
vendor: {
src: [
'vendor/angular/angular.js',
'vendor/angular-route/angular-route.js',
'vendor/angular-bootstrap/ui-bootstrap-tpls.js'
],
dest: 'dist/js/vendor.js'
}
},

Grunt-watch livereload does not work with compiled files (stylus, jade, etc.)

My livereload is "working" in that it live reloads the page when a file is changed, but only if I modify the file directly. If the file is generated through the grunt stylus or jade compiler, nothing happens.
When I look at grunt with verbose turned on, the Live reloading root.css... line appears only if I save root.css directly. If root.css is modified through the stylus compiler, the line does not appear. It's as if watch doesn't detect the file has been changed if it's changed through a compiler. This same issue occurs with jade as well.
Here's my stylus task (trimmed):
stylus: {
options: {
compress: false,
use: [
require('autoprefixer-stylus')
]
},
src: [
'app/styl/**/*.styl'
],
dest: 'build/css/root.css'
}
And here's my watch task (trimmed):
livereload: {
options: {
livereload: 1337,
},
files: 'build/**/*'
},
stylus: {
files: [
'app/styl/**/*.styl',
],
tasks: ['stylus:dev']
},
I really hope I'm just doing something stupid. I can't find any problems similar to this one.
EDIT:
Just in case this helps, I discovered that by changing my grunt task from running ['clean','jade:dev', 'stylus:dev', 'connect:dev', 'watch'] to only running ['connect:dev', 'watch'], livereload works as intended once, then never again. (Modifying the css directly still works though.)
EDIT 2:
I was able to fix this by adding livereload to each specific task in watch, like so:
livereload: {
options: {
livereload: 1337,
},
files: 'build/**/*'
},
stylus: {
files: [
'app/styl/**/*.styl',
],
tasks: ['stylus:dev'],
options: {
livereload: 1337
}
},
As to why this works, I have no idea. If anyone can shed some light on this, it'd be much appreciated. Though to be honest, I don't know why I didn't try this earlier.

grunt-contrib-jshint is not ignoring specified directories

I have the following folders and files:
js/
lib/
jQuery.js
compiled/
all.js
file1.js
file2.js
I want JSHint to lint only file1 and file2 (without having to specify the exact files) and for it not to lint the lib folder and compiled folder.
Can anyone shed any light on why my JSHint task below is linting all .js files and not ignoring the compiled and lib folders?
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'js/**/*.js',
'!js/compiled/**/*.js',
'!js/lib/**/*.js'
]
},
Try
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'js/*.js',
'!js/compiled/*.js',
'!js/lib/*.js'
]
},
You don't need the ** as you don't have any intermediate folders.

Resources