Reputation: 12282
I'm trying to come up with a way to keep either sensitive or local configuration for grunt out of the repository.
For example, I'd like to have a custom dist directory on local machine
what I've done so far is this:
dist: require('./local.conf.json').distPath || 'dist'
which works fine when I define a local.conf.json file, but I don't won't this to be mandatory and so I'm wondering if there's a way for require not to throw/end a task if local.conf.json is not found, or maybe there's a different way to achieve this?
Upvotes: 0
Views: 157
Reputation: 6703
You can test if the file is present synchronously:
var fs = require('fs');
...
dist: (fs.existsSync('./local.conf.json') ? require('./local.conf.json').distPath : 'dist')
Or even better - have the default config and your local config in separate js files and load them in the beginning of your gruntfile and if the local.config.js
is not present then fallback to the default.config.js
.
Upvotes: 1