Skip to content

Commit e9c4ceb

Browse files
committed
Add initial webpack-dev-server options validation.
Relies on this PR in webpack: webpack/webpack#3218
1 parent b0ef612 commit e9c4ceb

File tree

2 files changed

+216
-0
lines changed

2 files changed

+216
-0
lines changed

lib/Server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ var spdy = require("spdy");
1010
var httpProxyMiddleware = require("http-proxy-middleware");
1111
var serveIndex = require("serve-index");
1212
var historyApiFallback = require("connect-history-api-fallback");
13+
var webpack = require("webpack");
14+
var WebpackOptionsValidationError = require("webpack/lib/WebpackOptionsValidationError");
15+
var optionsSchema = require("./optionsSchema.json");
1316

1417
function Server(compiler, options) {
1518
// Default options
1619
if(!options) options = {};
1720

21+
var validationErrors = webpack.validateSchema(optionsSchema, options);
22+
if(validationErrors.length) {
23+
throw new WebpackOptionsValidationError(validationErrors);
24+
}
25+
1826
if(options.lazy && !options.filename) {
1927
throw new Error("'filename' option must be set in lazy mode.");
2028
}

lib/optionsSchema.json

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
{
2+
"additionalProperties": false,
3+
"properties": {
4+
"hot": {
5+
"description": "TODO.",
6+
"type": "boolean"
7+
},
8+
"hotOnly": {
9+
"description": "TODO.",
10+
"type": "boolean"
11+
},
12+
"lazy": {
13+
"description": "TODO.",
14+
"type": "boolean"
15+
},
16+
"host": {
17+
"description": "TODO.",
18+
"type": "string"
19+
},
20+
"filename": {
21+
"description": "TODO.",
22+
"type": "string"
23+
},
24+
"outputPath": {
25+
"description": "TODO.",
26+
"type": "string"
27+
},
28+
"publicPath": {
29+
"description": "TODO.",
30+
"type": "string"
31+
},
32+
"port": {
33+
"description": "TODO.",
34+
"type": "number"
35+
},
36+
"socket": {
37+
"description": "TODO.",
38+
"type": "string"
39+
},
40+
"watchOptions": {
41+
"description": "TODO.",
42+
"type": "object"
43+
},
44+
"headers": {
45+
"description": "TODO.",
46+
"type": "object"
47+
},
48+
"clientLogLevel": {
49+
"description": "TODO.",
50+
"enum": [
51+
"info",
52+
"warning",
53+
"error"
54+
]
55+
},
56+
"key": {
57+
"description": "TODO.",
58+
"anyOf": [
59+
{
60+
"type": "string"
61+
},
62+
{
63+
"instanceof": "Buffer"
64+
}
65+
]
66+
},
67+
"cert": {
68+
"description": "TODO.",
69+
"anyOf": [
70+
{
71+
"type": "string"
72+
},
73+
{
74+
"instanceof": "Buffer"
75+
}
76+
]
77+
},
78+
"ca": {
79+
"description": "TODO.",
80+
"anyOf": [
81+
{
82+
"type": "string"
83+
},
84+
{
85+
"instanceof": "Buffer"
86+
}
87+
]
88+
},
89+
"pfx": {
90+
"description": "TODO.",
91+
"anyOf": [
92+
{
93+
"type": "string"
94+
},
95+
{
96+
"instanceof": "Buffer"
97+
}
98+
]
99+
},
100+
"pfxPassphrase": {
101+
"description": "TODO.",
102+
"type": "string"
103+
},
104+
"inline": {
105+
"description": "TODO.",
106+
"type": "boolean"
107+
},
108+
"public": {
109+
"description": "TODO.",
110+
"type": "string"
111+
},
112+
"https": {
113+
"description": "TODO.",
114+
"anyOf": [
115+
{
116+
"type": "object"
117+
},
118+
{
119+
"type": "boolean"
120+
}
121+
]
122+
},
123+
"contentBase": {
124+
"description": "TODO.",
125+
"anyOf": [
126+
{
127+
"type": "array"
128+
},
129+
{
130+
"type": "number"
131+
},
132+
{
133+
"type": "string"
134+
}
135+
]
136+
},
137+
"watchContentBase": {
138+
"description": "TODO.",
139+
"type": "boolean"
140+
},
141+
"open": {
142+
"description": "TODO.",
143+
"type": "boolean"
144+
},
145+
"features": {
146+
"description": "TODO.",
147+
"type": "array"
148+
},
149+
"compress": {
150+
"description": "TODO.",
151+
"type": "boolean"
152+
},
153+
"proxy": {
154+
"description": "TODO.",
155+
"anyOf": [
156+
{
157+
"type": "string"
158+
},
159+
{
160+
"type": "array"
161+
},
162+
{
163+
"type": "object"
164+
}
165+
]
166+
},
167+
"historyApiFallback": {
168+
"description": "TODO.",
169+
"anyOf": [
170+
{
171+
"type": "boolean"
172+
},
173+
{
174+
"type": "object"
175+
}
176+
]
177+
},
178+
"staticOptions": {
179+
"description": "TODO.",
180+
"type": "object"
181+
},
182+
"setup": {
183+
"description": "TODO.",
184+
"instanceof": "Function"
185+
},
186+
"stats": {
187+
"description": "Used by the webpack CLI program to pass stats options.",
188+
"anyOf": [
189+
{
190+
"type": "object"
191+
},
192+
{
193+
"type": "boolean"
194+
},
195+
{
196+
"enum": [
197+
"none",
198+
"errors-only",
199+
"minimal",
200+
"normal",
201+
"verbose"
202+
]
203+
}
204+
]
205+
}
206+
},
207+
"type": "object"
208+
}

0 commit comments

Comments
 (0)