You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| node-resolve | number | Resolve bare import imports using node resolve |
198
197
| compatibility | string | Compatibility mode for older browsers. Can be: `esm`, `modern` or `all`|
198
+
| node-resolve | number | Resolve bare import imports using node resolve |
199
199
| module-dirs | string/array | Directories to resolve modules from. Used by node-resolve |
200
200
| babel | number | Transform served code through babel. Requires .babelrc |
201
201
| file-extensions | number/array | Extra file extentions to use when transforming code. |
@@ -204,26 +204,32 @@ Click read more to view different strategies for setting up your project's folde
204
204
205
205
Most commands have an alias/shorthand. You can view them by using `--help`.
206
206
207
-
## Advanced usage
208
-
209
207
### Configuration files
210
208
We pick up an `es-dev-server.config.js` file automatically if it is present in the current working directory. You can specify a custom config path using the `config` flag.
211
-
<details>
212
-
<summary>Read more</summary>
213
209
214
-
The configuration file allows the same command line flags configured, using their camelCased names. Example:
215
-
```javascript
216
-
module.exports= {
217
-
port:8080,
218
-
appIndex:'demo/index.html',
219
-
moduleDirs: ['node_modules', 'custom-modules']
220
-
}
210
+
Configuration options are the same as command line flags, using their camelCased names. Example:
211
+
```javascript
212
+
module.exports= {
213
+
port:8080,
214
+
watch:true,
215
+
nodeResolve:true,
216
+
appIndex:'demo/index.html',
217
+
moduleDirs: ['node_modules', 'custom-modules']
218
+
}
221
219
```
222
-
</details>
220
+
221
+
In addition to the command line flags, the configuration file accepts these additional options:
| middlewares | array | Koa middlewares to add to the server, read more below. |
226
+
| babelConfig | object | Babel config to run with the server |
227
+
228
+
## Advanced usage
223
229
224
230
### Custom middlewares / proxy
225
231
226
-
You can install custom middlewares, using the `customMiddlewares` property.
232
+
You can install custom middlewares, using the `middlewares` property.
227
233
228
234
<details>
229
235
<summary>Read more</summary>
@@ -236,7 +242,7 @@ You can install custom middlewares, using the `customMiddlewares` property.
236
242
237
243
module.exports= {
238
244
port:9000,
239
-
customMiddlewares: [
245
+
middlewares: [
240
246
proxy('/api', {
241
247
target:'http://localhost:9001',
242
248
})
@@ -256,7 +262,7 @@ You can rewrite certain file requests using a simple custom middleware. This can
256
262
257
263
```javascript
258
264
module.exports= {
259
-
customMiddlewares: [
265
+
middlewares: [
260
266
functionrewriteIndex(context, next) {
261
267
if (context.url==='/'||context.url==='/index.html') {
262
268
context.url='/src/index.html';
@@ -374,6 +380,96 @@ Compatibility mode enables bundle-free development with features such as es modu
374
380
375
381
</details>
376
382
383
+
## Using es-dev-server programmatically
384
+
You can use different components from `es-dev-server` as a library and integrate it with other tools:
385
+
386
+
<details>
387
+
388
+
<summary>Read more</summary>
389
+
390
+
### createConfig
391
+
When using the server from javascript you are going to need a config object to tell the server what options to turn on and off. It's best to use `createConfig` for this as this converts the public API to an internal config structure and sets up default values.
392
+
393
+
By default all options besides static file serving is turned off, so it's easy to configure based on your own requirements.
394
+
395
+
The config structure is the same as the configuration explained in the [configuration files section](#configuration-files)
396
+
397
+
```javascript
398
+
import { createConfig } from'es-dev-server';
399
+
400
+
constconfig=createConfig({
401
+
http2:true,
402
+
babel:true,
403
+
open:true,
404
+
});
405
+
```
406
+
407
+
### createMiddlewares
408
+
`createMiddlewares` creates the dev server's middlewares based on your configuration. You can use this to hook them up to your own koa server.
`createServer` creates an instance of the dev server including all middlewares, but without starting the server. This is useful if you want to be in control of starting the server yourself.
427
+
428
+
Returns the koa app and a node http or http2 server.
`createMiddlewares` and `createServer` requires a chokidar fileWatcher if watch mode is enabled. You need to pass this separately because the watcher needs to be killed explicitly when the server closes.
0 commit comments