DefinitelyTyped/types/webpack-dev-middleware/webpack-dev-middleware-tests.ts
Piotr Błażejewicz (Peter Blazejewicz) 4872b8c4d6
Update webpack-dev-middleware to 3.7 (#42573)
* feat(webpack-dev-middleware): update to v3.7

- v2 created
- update configuration options to v3.7

https://github.com/webpack/webpack-dev-middleware/tree/v3.7.2#options

Thanks!

* fix(webpack-serve): fix v1 tests errors

- `The types of 'dev.logLevel' are incompatible between these types`
- `Types of property 'dev' are incompatible`

Required to pass test for `webpack-dev-middleware` changes
2020-02-25 16:38:38 -08:00

61 lines
1.4 KiB
TypeScript

import express = require('express');
import webpack = require('webpack');
import webpackDevMiddleware = require('webpack-dev-middleware');
const compiler = webpack({});
let webpackDevMiddlewareInstance = webpackDevMiddleware(compiler);
webpackDevMiddlewareInstance = webpackDevMiddleware(compiler, {
logLevel: 'silent',
logTime: true,
lazy: true,
methods: ['GET', 'POST'],
mimeTypes: {
typeMap: { 'text/html': ['phtml'] },
force: true,
},
watchOptions: {
aggregateTimeout: 300,
poll: true,
},
publicPath: '/assets/',
index: 'index.html',
headers: {
'X-Custom-Header': 'yes',
},
stats: {
colors: true,
},
reporter: null,
serverSideRender: false,
writeToDisk: false,
});
const app = express();
app.use([webpackDevMiddlewareInstance]);
webpackDevMiddlewareInstance.close(() => {
console.log('closed');
});
webpackDevMiddlewareInstance.invalidate(stats => {
if (stats) {
console.log(stats.toJson());
}
});
webpackDevMiddlewareInstance.waitUntilValid(stats => {
if (stats) {
console.log('Package is in a valid state:' + stats.toJson());
}
});
const fs = webpackDevMiddlewareInstance.fileSystem;
fs.mkdirpSync('foo');
let filename = webpackDevMiddlewareInstance.getFilenameFromUrl('url');
if (filename !== false) {
filename = filename.substr(0);
}