Skip to content

Commit

Permalink
feat: #169 ko.config.js support devServer client (#170)
Browse files Browse the repository at this point in the history
* feat: #169 ko.config.js support devServer client

* docs(changeset): ko.config.js support devServer client
  • Loading branch information
liuxy0551 authored Oct 9, 2024
1 parent c189db4 commit df0754e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-fireants-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ko': patch
---

ko.config.js support devServer client
23 changes: 15 additions & 8 deletions packages/ko/src/actions/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,33 @@ class Dev extends ActionFactory {

private get devServerConfig(): DevServerConfiguration {
const { serve, publicPath } = this.service.config;
const { host, port, proxy, staticPath, historyApiFallback = false } = serve;
const {
host,
port,
proxy,
client = {
overlay: {
errors: true,
warnings: false,
runtimeErrors: true,
},
},
staticPath,
historyApiFallback = false,
} = serve;
return {
port,
host,
hot: true,
proxy,
client,
static: {
directory: staticPath,
watch: true,
publicPath,
},
setupExitSignals: false,
allowedHosts: 'all',
client: {
overlay: {
errors: true,
warnings: false,
runtimeErrors: true,
},
},
historyApiFallback,
};
}
Expand Down
3 changes: 3 additions & 0 deletions packages/ko/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Pattern } from 'copy-webpack-plugin';
import { Plugin } from 'postcss';
import { IKeys, IOpts } from 'ko-lints';
import { IOpts as AutoPolyfillsWebpackPluginOptions } from '@dtinsight/auto-polyfills-webpack-plugin';
import { ClientConfiguration } from 'webpack-dev-server';

export type IOptions = {
//common configs
Expand Down Expand Up @@ -86,13 +87,15 @@ export type IOptions = {
// dev, or serve configs
/**
* Options for the development server.
* Docs url: https://webpack.js.org/configuration/dev-server/
* @param {{proxy?: Record<string, any>, host: string, port: number, staticPath?: string, historyApiFallback?: any, compilationSuccessInfo?: { messages: string[]; notes?: string[] }}}
*/
serve: {
proxy?: Record<string, any>;
host: string;
port: number;
staticPath?: string;
client?: boolean | ClientConfiguration | undefined;
historyApiFallback?: any;
compilationSuccessInfo?: { messages: string[]; notes?: string[] };
};
Expand Down
3 changes: 3 additions & 0 deletions website/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ title: Configuration
You can custom ko's action via **ko.config.js**, below are supported configurations:

``` typescript
import { ClientConfiguration } from 'webpack-dev-server';

export type IOptions = {
//common configs
cwd: string; //current working directory
Expand All @@ -32,6 +34,7 @@ export type IOptions = {
host: string; // host of dev server
port: number; // port of dev server
staticPath?: string; // static path that will be watch of dev server
client?: boolean | ClientConfiguration | undefined; // client of dev server
compilationSuccessInfo?: { messages: string[]; notes?: string[] }; // log after successful compilation, as same as friendly-errors-webpack-plugin
};
// experimental features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type IOptions = {
host: string; // 开发服务器的主机名
port: number; // 开发服务器的端口
staticPath?: string; // 监视的资源路径
client?: boolean | ClientConfiguration | undefined; // 日志、错误捕获等配置项
compilationSuccessInfo?: { messages: string[]; notes?: string[] }; // 成功编译后的日志,与 friendly-errors-webpack-plugin 相同
};
// 实验性功能
Expand Down

0 comments on commit df0754e

Please sign in to comment.