Skip to content

Commit

Permalink
add top level config options
Browse files Browse the repository at this point in the history
  • Loading branch information
helloitsjoe committed Aug 4, 2019
1 parent 6a7d86b commit 5e3c92f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
44 changes: 33 additions & 11 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,43 @@ describe('makeWebpackConfig', () => {
expect(config.module.rules.length).toBe(2);
});

it('User can add exclude field', () => {
const reactObj = { react: 'react' };
const excludeConfig = makeWebpackConfig({ exclude: reactObj });
expect(excludeConfig.exclude).toBe(reactObj);
describe('config options', () => {
const testObject = { foo: 'bar' };
it.each`
option | value
${'mode'} | ${'production'}
${'target'} | ${'node'}
${'devtool'} | ${'source-map'}
${'entry'} | ${testObject}
${'serve'} | ${testObject}
${'stats'} | ${testObject}
${'output'} | ${testObject}
${'plugins'} | ${testObject}
${'resolve'} | ${testObject}
${'externals'} | ${testObject}
${'devServer'} | ${testObject}
${'performance'} | ${testObject}
`('User can update $option', ({ option, value }) => {
const config = makeWebpackConfig({ [option]: value });
expect(config[option]).toBe(value);
});
});

describe('defaults', () => {
it.each`
key | value
${'mode'} | ${'development'}
${'target'} | ${'web'}
${'entry'} | ${undefined}
${'output'} | ${undefined}
${'devtool'} | ${undefined}
${'exclude'} | ${undefined}
key | value
${'mode'} | ${'development'}
${'target'} | ${'web'}
${'serve'} | ${undefined}
${'stats'} | ${undefined}
${'entry'} | ${undefined}
${'output'} | ${undefined}
${'devtool'} | ${undefined}
${'plugins'} | ${undefined}
${'resolve'} | ${undefined}
${'externals'} | ${undefined}
${'devServer'} | ${undefined}
${'performance'} | ${undefined}
`('$key is $value', ({ key, value }) => {
expect(config[key]).toBe(value);
});
Expand Down
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ const defaultWebpackRules = [makeJS(), makeCSS()];
const makeWebpackConfig = ({
js,
css,
serve,
stats,
entry,
output,
resolve,
devtool,
exclude,
plugins,
externals,
devServer,
performance,
target = 'web',
mode = 'development',
rules = defaultWebpackRules,
Expand All @@ -146,11 +152,17 @@ const makeWebpackConfig = ({

return {
mode,
serve,
stats,
entry,
output,
target,
resolve,
devtool,
exclude,
plugins,
externals,
devServer,
performance,
module: {
rules: customRules,
},
Expand Down

0 comments on commit 5e3c92f

Please sign in to comment.