diff --git a/README.md b/README.md index 20ae37cf..9b0eba0c 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ to add one — start with [Travis CI](https://github.com/dwyl/learn-travis). ## Config -Size Limits supports 2 ways to define config. +Size Limits supports 3 ways to define config. 1. `size-limit` section to `package.json`: @@ -162,6 +162,17 @@ Size Limits supports 2 ways to define config. ] ``` +3. or more flexible `.size-limit.js` config file: + + ```js + module.exports = [ + { + path: "index.js", + limit: "9 KB" + } + ] + ``` + Each section in config could have options: * **path**: relative paths to files. The only mandatory option. diff --git a/cli.js b/cli.js index 2e2eaf0b..379000e3 100755 --- a/cli.js +++ b/cli.js @@ -177,7 +177,7 @@ function getConfig () { searchPlaces: [ 'package.json', '.size-limit', - 'size-limit.config.js' + '.size-limit.js' ] }) return explorer diff --git a/test/cli.test.js b/test/cli.test.js index e3d2ddcc..e2982319 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -114,6 +114,17 @@ it('uses .size-limit file config', () => { }) }) +it('uses .size-limit.js file config', () => { + return run([], { cwd: fixture('js') }).then(result => { + expect(result.out).toEqual('\n' + + ' Package size: 19 B\n' + + ' Size limit: 1 KB\n' + + ' With all dependencies, minified and gzipped\n' + + '\n') + expect(result.code).toEqual(0) + }) +}) + it('overrides config by limit argument', () => { return run(['--limit', '18B'], { cwd: fixture('config') }).then(result => { expect(result.out).toContain('Size limit: 18 B\n') diff --git a/test/fixtures/js/.size-limit.js b/test/fixtures/js/.size-limit.js new file mode 100644 index 00000000..4258896d --- /dev/null +++ b/test/fixtures/js/.size-limit.js @@ -0,0 +1,6 @@ +module.exports = [ + { + path: "index.js", + limit: "1 KB" + } +] diff --git a/test/fixtures/js/index.js b/test/fixtures/js/index.js new file mode 100644 index 00000000..a37e6e10 --- /dev/null +++ b/test/fixtures/js/index.js @@ -0,0 +1,3 @@ +'use strict' + +console.log(2)