From b9e6b43ca822295a9108e933511e7a125a43e8ab Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Tue, 11 Oct 2022 23:32:22 -0700 Subject: [PATCH] fix(plugin-webpack): better webpack-dev-server types --- packages/plugin/webpack/src/Config.ts | 4 ++-- packages/plugin/webpack/src/WebpackPlugin.ts | 6 +++--- typings/webpack-dev-server/index.d.ts | 14 -------------- 3 files changed, 5 insertions(+), 19 deletions(-) delete mode 100644 typings/webpack-dev-server/index.d.ts diff --git a/packages/plugin/webpack/src/Config.ts b/packages/plugin/webpack/src/Config.ts index 3ddd85136e..f0621176fc 100644 --- a/packages/plugin/webpack/src/Config.ts +++ b/packages/plugin/webpack/src/Config.ts @@ -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 { @@ -151,8 +152,7 @@ export interface WebpackPluginConfig { * * `setupExitSignals` * * `headers.Content-Security-Policy` (use the `devContentSecurityPolicy` config option) */ - devServer?: Record; - // TODO: use webpack-dev-server.Configuration when @types/webpack-dev-server upgrades to v4 + devServer?: Omit; } export type WebpackConfiguration = RawWebpackConfiguration | WebpackConfigurationFactory; diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index b70416ee80..33d2dd1e0d 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -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 () => { @@ -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 = { hot: true, devMiddleware: { writeToDisk: true, }, historyApiFallback: true, }; - const overrides = { + const overrides: Partial = { port: this.port, setupExitSignals: true, static: path.resolve(this.baseDir, 'renderer'), diff --git a/typings/webpack-dev-server/index.d.ts b/typings/webpack-dev-server/index.d.ts deleted file mode 100644 index 25a2df1582..0000000000 --- a/typings/webpack-dev-server/index.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -// TODO: Replace with @types/webpack-dev-server when it no longer depends on @types/webpack -// See: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55300#issuecomment-904636931 -declare module 'webpack-dev-server' { - import { Server } from 'http'; - import { Compiler, MultiCompiler } from 'webpack'; - class WebpackDevServer { - constructor(options: {}, compiler: Compiler); - constructor(options: {}, compiler: MultiCompiler); - server: Server; - start(): Promise; - close(): void; - } - export default WebpackDevServer; -}