Skip to content

Commit 9976dce

Browse files
author
Matt Lewis
committed
feat(config): allow config to be a default export
1 parent 99d647b commit 9976dce

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ var parseConfig = function (configFilePath, cliOptions) {
342342

343343
try {
344344
configModule = require(configFilePath)
345+
if (typeof configModule === 'object' && typeof configModule.default !== 'undefined') {
346+
configModule = configModule.default
347+
}
345348
} catch (e) {
346349
if (e.code === 'MODULE_NOT_FOUND' && e.message.indexOf(configFilePath) !== -1) {
347350
log.error('File %s does not exist!', configFilePath)

test/unit/config.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe('config', () => {
4545
'/conf/exclude.js': wrapCfg({exclude: ['one.js', 'sub/two.js']}),
4646
'/conf/absolute.js': wrapCfg({files: ['http://some.com', 'https://more.org/file.js']}),
4747
'/conf/both.js': wrapCfg({files: ['one.js', 'two.js'], exclude: ['third.js']}),
48-
'/conf/coffee.coffee': wrapCfg({files: ['one.js', 'two.js']})
48+
'/conf/coffee.coffee': wrapCfg({files: ['one.js', 'two.js']}),
49+
'/conf/default-export.js': {default: wrapCfg({files: ['one.js', 'two.js']})}
4950
}
5051

5152
// load file under test
@@ -294,6 +295,11 @@ describe('config', () => {
294295
config = normalizeConfigWithDefaults({ protocol: 'unsupported:' })
295296
expect(config.protocol).to.equal('http:')
296297
})
298+
299+
it('should allow the config to be set of the default export', () => {
300+
var config = e.parseConfig('/conf/default-export.js', {})
301+
expect(config.autoWatch).to.equal(true)
302+
})
297303
})
298304

299305
describe('normalizeConfig', () => {

0 commit comments

Comments
 (0)