Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Commit d76ff98

Browse files
feat(index): add options validation
1 parent 63a590f commit d76ff98

File tree

4 files changed

+92
-37
lines changed

4 files changed

+92
-37
lines changed

package-lock.json

Lines changed: 46 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"webpack-defaults": "webpack-defaults"
3131
},
3232
"dependencies": {
33+
"schema-utils": "^0.3.0",
3334
"source-map": "^0.5.6",
3435
"uglify-js": "^2.8.29",
3536
"webpack-sources": "^1.0.1"

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ import { ConcatSource, RawSource, SourceMapSource } from 'webpack-sources';
1616
import RequestShortener from 'webpack/lib/RequestShortener';
1717
import ModuleFilenameHelpers from 'webpack/lib/ModuleFilenameHelpers';
1818

19+
import validateOptions from 'schema-utils';
20+
1921
import uglify from 'uglify-js';
2022

2123
class UglifyJsPlugin {
2224
constructor(options) {
2325
if (typeof options !== 'object' || Array.isArray(options)) {
2426
options = {};
2527
}
28+
29+
// eslint-disable-next-line
30+
validateOptions(require('./options.json'), options, 'UglifyJS Plugin');
31+
2632
if (typeof options.compressor !== 'undefined') {
2733
options.compress = options.compressor;
2834
}

src/options.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"test": {
5+
"type": "object"
6+
},
7+
"output": {
8+
"type": "object"
9+
},
10+
"mangle": {
11+
"type": ["boolean", "object"]
12+
},
13+
"compress": {
14+
"type": ["boolean", "object"]
15+
},
16+
"beautify": {
17+
"type": "boolean"
18+
},
19+
"comments": {
20+
"type": ["boolean", "object"]
21+
},
22+
"extractComments": {
23+
"type": ["boolean", "object"]
24+
},
25+
"warningsFilter": {
26+
"type": "object"
27+
},
28+
"include": {
29+
"type": "object"
30+
},
31+
"exclude": {
32+
"type": "object"
33+
},
34+
"sourceMap": {
35+
"type": "boolean"
36+
}
37+
},
38+
"additionalProperties": true
39+
}

0 commit comments

Comments
 (0)