Skip to content

Commit 0c4e49c

Browse files
committed
refactor: 适配 vite@2.7.x
1 parent 2cabb5a commit 0c4e49c

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

src/Bootstrap.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/* eslint-disable import/no-dynamic-require */
21
import assert from 'assert';
32
import { join } from 'path';
43

54
import * as fs from 'fs-extra';
65

7-
import { debounce } from 'lodash';
6+
import debounce from 'lodash/debounce';
87
import * as esbuild from 'esbuild';
98

109
import { Service } from './core';

src/core/server/capability/Logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ora from 'ora';
1+
import ora, { Ora } from 'ora';
22
import type { ForegroundColor } from 'chalk';
33
import chalk from 'chalk';
44

@@ -21,7 +21,7 @@ function outputLogText(opts = {} as Partial<{ type: LogType; color: typeof Foreg
2121
}
2222

2323
class Spinner {
24-
private spinnerInstance: ora.Ora | undefined;
24+
private spinnerInstance: Ora | undefined;
2525

2626
init(text = '即将开始启动自动生成业务配置代码,请稍等~\n') {
2727
this.spinnerInstance = ora(outputLogText()(text));

src/core/typings/server.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export type Config = {
1212
*/
1313
loading?: string;
1414
delay?: number;
15-
webpackPreload?: boolean;
1615
};
1716
// https://umijs.org/zh-CN/plugins/plugin-locale#umijsplugin-locale
1817
locale?: {

src/core/util/childProcess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const PromiseWrapper = (cmdType: keyof typeof childProcess) => (
66
isConsoleLog = true,
77
) =>
88
new Promise((resolve, reject) => {
9-
const result = childProcess[cmdType](options) as childProcess.ChildProcessByStdio<
9+
const result = childProcess[cmdType as 'spawn'](options) as childProcess.ChildProcessByStdio<
1010
Writable,
1111
Readable,
1212
Readable

src/plugins.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import type { Options as reactRefreshOptions } from '@vitejs/plugin-react-refresh';
2-
import reactRefresh from '@vitejs/plugin-react-refresh';
3-
import reactJsx from 'vite-react-jsx';
1+
import react, { Options as ReactOptions } from '@vitejs/plugin-react'
42
import WindiCSS from 'vite-plugin-windicss';
53

64
import type { VitePluginOptions } from 'vite-plugin-style-import';
@@ -16,7 +14,7 @@ import { Bootstrap } from './Bootstrap';
1614

1715
type Options = {
1816
styleImport?: VitePluginOptions;
19-
reactRefresh?: reactRefreshOptions;
17+
react?: ReactOptions;
2018
mkcert?: ViteCertificateOptions;
2119
};
2220

@@ -28,15 +26,15 @@ export const reactAutoConfig = async (options: Options = {}) => {
2826

2927
const { userConfig } = bootstrap.getServer();
3028

31-
const plugins = [reactJsx(), reactAutoConfigPluginConfig(bootstrap)] as (
29+
const plugins = [
30+
// todo: 待替换成 https://github.com/iheyunfei/vite-on-swc
31+
react(options.react),
32+
reactAutoConfigPluginConfig(bootstrap)
33+
] as (
3234
| PluginOption
3335
| PluginOption[]
3436
)[];
3537

36-
if (userConfig.fastRefresh !== false) {
37-
plugins.push(reactRefresh(options.reactRefresh));
38-
}
39-
4038
if (userConfig.antd) {
4139
const { styleImport } = options;
4240

0 commit comments

Comments
 (0)