Skip to content

Commit

Permalink
fix(plugin-webpack): better webpack-dev-server types
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao committed Oct 12, 2022
1 parent d5cf1f2 commit b9e6b43
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/plugin/webpack/src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Configuration as RawWebpackConfiguration } from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import { ConfigurationFactory as WebpackConfigurationFactory } from './WebpackConfig';

export interface WebpackPluginEntryPoint {
Expand Down Expand Up @@ -151,8 +152,7 @@ export interface WebpackPluginConfig {
* * `setupExitSignals`
* * `headers.Content-Security-Policy` (use the `devContentSecurityPolicy` config option)
*/
devServer?: Record<string, unknown>;
// TODO: use webpack-dev-server.Configuration when @types/webpack-dev-server upgrades to v4
devServer?: Omit<WebpackDevServer.Configuration, 'port' | 'static' | 'setupExitSignals' | 'Content-Security-Policy'>;
}

export type WebpackConfiguration = RawWebpackConfiguration | WebpackConfigurationFactory;
6 changes: 3 additions & 3 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ the generated files). Instead, it is ${JSON.stringify(pj.main)}`);
const compiler = webpack(config);
const webpackDevServer = new WebpackDevServer(this.devServerOptions(), compiler);
await webpackDevServer.start();
this.servers.push(webpackDevServer.server);
this.servers.push(webpackDevServer.server!);
});

await asyncOra('Compiling Preload Scripts', async () => {
Expand Down Expand Up @@ -365,14 +365,14 @@ the generated files). Instead, it is ${JSON.stringify(pj.main)}`);
const cspDirectives =
this.config.devContentSecurityPolicy ?? "default-src 'self' 'unsafe-inline' data:; script-src 'self' 'unsafe-eval' 'unsafe-inline' data:";

const defaults = {
const defaults: Partial<WebpackDevServer.Configuration> = {
hot: true,
devMiddleware: {
writeToDisk: true,
},
historyApiFallback: true,
};
const overrides = {
const overrides: Partial<WebpackDevServer.Configuration> = {
port: this.port,
setupExitSignals: true,
static: path.resolve(this.baseDir, 'renderer'),
Expand Down
14 changes: 0 additions & 14 deletions typings/webpack-dev-server/index.d.ts

This file was deleted.

0 comments on commit b9e6b43

Please sign in to comment.