I was wondering why my jshint grunt task is so dead slow. Thats short example config:
var config = {
jshint: {
scripts: ['**/*.js', '!node_modules/**']
},
watch: {
files: ['**/*.js', '!node_modules/**'],
tasks: ['jshint']
}
}
What does that pattern? If I have understood things correctly, both file patterns are using grunt api to build file list for task. That pattern works, it filters everything inside node_modules away but it does it extremely slowly because before applying filter, grunt digs whole node_modules directory recursively (~100 MB).
Is there any way to actually tell grunt not to even look at node_modules?
That example config takes about 30s on my laptop. If using whitelist pattern istead of blacklisting, jshint task takes just couple of seconds. But whitelisting means I have to be looking Gruntfile all the time if I do any refactoring etc which is super annoying.
Current while list pattern looks like this:
var allJSFiles = [
'*.js',
'{browser,server,config,models,routes,tasks,schema,test,utils,views}/**/*.js',
'!browser/bower_components/**'
];
Can't you just add your JS files to a new folder off root? That way you can "ignore" node_modules
by not including it in the list.
Sample folder structure
- root
- node_modules
- jshint
- src
// your bespoke code
Grunt config
var config = {
jshint: {
scripts: ['src/**/*.js']
},
watch: {
files: ['src/**/*.js'],
tasks: ['jshint']
}
}
Like Andy already mentioned, I'd recommend a different file structure as well, keeping your code in a "src" or "public" directory for example.
The problem here is that your rule
'**/*.js'
always digs through all directories and only later excludes node_modules, which cannot be prevented at this point.
Not only because of this, but also to seperate code from other assets (images? documentation?), another structure should be the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With