Skip to content

Commit 45e3f0d

Browse files
author
chengyu.chengyulia
committed
feat: support eslint in dev mode
1 parent e90d51f commit 45e3f0d

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/utils/define.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export class ProjectConfig {
142142
*/
143143
public title?: string = null;
144144

145+
/**
146+
* custom host
147+
*/
148+
public host? = 'localhost';
149+
145150
/**
146151
* Dev server port, when execute npm start.
147152
*/
@@ -306,9 +311,12 @@ export class ProjectConfig {
306311
public circularDetect?: ICircularDetectConfig;
307312

308313
/**
309-
* custom host
314+
* eslint linting in dev mode
310315
*/
311-
public host? = 'localhost';
316+
public eslintChecker?: {
317+
enabled: boolean;
318+
files: string | string[];
319+
};
312320
}
313321

314322
export type SetPipe = (pipeName: string, callback: PipeCallback) => void;

src/utils/webpack-dev-server.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import * as WebpackDevServer from 'webpack-dev-server';
1313
import * as SpeedMeasurePlugin from 'speed-measure-webpack-plugin';
1414
import * as ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
1515
import { globalState } from './global-state';
16-
import { tempPath } from './structor-config';
16+
import { tempPath, srcPath, packagesPath } from './structor-config';
1717
import { logInfo } from './log';
1818
import { getWebpackConfig, IOptions } from './webpack-config';
19-
import { pri } from '../node';
2019

2120
const smp = new SpeedMeasurePlugin();
2221

@@ -71,12 +70,20 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
7170
memoryLimit: 8192,
7271
mode: 'write-references',
7372
},
73+
eslint: {
74+
memoryLimit: 8192,
75+
enabled: globalState.sourceConfig.eslintChecker?.enabled ?? false,
76+
files: globalState.sourceConfig.eslintChecker?.files ?? [
77+
`./${srcPath.dir}/**/*.{ts,tsx}`,
78+
`./${packagesPath.dir}/**/*.{ts,tsx}`,
79+
],
80+
},
7481
}),
7582
);
7683
}
7784

7885
const webpackDevServerConfig: WebpackDevServer.Configuration = {
79-
host: pri.sourceConfig.host,
86+
host: globalState.sourceConfig.host,
8087
hot: opts.hot,
8188
hotOnly: opts.hot,
8289
publicPath: opts.publicPath,
@@ -124,16 +131,16 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
124131

125132
const devServer = new WebpackDevServer(compiler as any, webpackDevServerConfig);
126133

127-
devServer.listen(opts.devServerPort, pri.sourceConfig.host, () => {
134+
devServer.listen(opts.devServerPort, globalState.sourceConfig.host, () => {
128135
let devUrl: string = null;
129136
const localSuggestUrl = urlJoin(
130-
`${opts.https || globalState.sourceConfig.useHttps ? 'https' : 'http'}://${pri.sourceConfig.host}:${
137+
`${opts.https || globalState.sourceConfig.useHttps ? 'https' : 'http'}://${globalState.sourceConfig.host}:${
131138
opts.devServerPort
132139
}`,
133140
globalState.sourceConfig.baseHref,
134141
);
135142

136-
if (opts.devUrl === pri.sourceConfig.host) {
143+
if (opts.devUrl === globalState.sourceConfig.host) {
137144
devUrl = localSuggestUrl;
138145
} else if (opts.devUrl !== undefined) {
139146
({ devUrl } = opts);

0 commit comments

Comments
 (0)