@qse/edu-scripts 0.0.0-beta.0 → 0.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/config/webpackConfig.js +14 -11
- package/es/start.js +9 -0
- package/es/utils/defineConfig.d.ts +12 -5
- package/package.json +2 -1
- package/src/config/plugins/mock-server/index.js +2 -2
- package/src/config/webpackConfig.js +13 -11
- package/src/start.js +9 -0
- package/src/utils/defineConfig.ts +12 -5
|
@@ -6,8 +6,8 @@ import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
|
6
6
|
import ReactRefreshPlugin from "@rspack/plugin-react-refresh";
|
|
7
7
|
import paths from "./paths.js";
|
|
8
8
|
import appConfig from "../utils/appConfig.js";
|
|
9
|
-
import { once } from "lodash-es";
|
|
10
9
|
import { createRequire } from "node:module";
|
|
10
|
+
import chalk from "chalk";
|
|
11
11
|
var require2 = createRequire(import.meta.url);
|
|
12
12
|
var appPkg = fs.readJsonSync(paths.package);
|
|
13
13
|
var jsMainPath = appConfig.grayscale ? `${appPkg.name}/beta/${appPkg.name}` : `${appPkg.name}/${appPkg.name}`;
|
|
@@ -161,7 +161,7 @@ function getWebpackConfig(args, override) {
|
|
|
161
161
|
},
|
|
162
162
|
extensions: [".web.js", ".web.mjs", ".js", ".mjs", ".jsx", ".ts", ".tsx", ".json", ".wasm"]
|
|
163
163
|
},
|
|
164
|
-
stats:
|
|
164
|
+
stats: false,
|
|
165
165
|
devtool: isDev ? "cheap-module-source-map" : false,
|
|
166
166
|
module: {
|
|
167
167
|
rules: [
|
|
@@ -181,8 +181,7 @@ function getWebpackConfig(args, override) {
|
|
|
181
181
|
import: [
|
|
182
182
|
{
|
|
183
183
|
libraryName: "lodash",
|
|
184
|
-
|
|
185
|
-
camel2DashComponentName: false
|
|
184
|
+
customName: "lodash/{{member}}"
|
|
186
185
|
},
|
|
187
186
|
...override.import
|
|
188
187
|
]
|
|
@@ -368,14 +367,18 @@ function getWebpackConfig(args, override) {
|
|
|
368
367
|
})
|
|
369
368
|
) : [],
|
|
370
369
|
process.env.ANALYZE && isProd && new BundleAnalyzerPlugin(),
|
|
371
|
-
isDev &&
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
370
|
+
isDev && ((compiler) => {
|
|
371
|
+
let isFirst = true;
|
|
372
|
+
compiler.hooks.afterDone.tap("edu-scripts-startup", (stats) => {
|
|
373
|
+
if (!isFirst)
|
|
374
|
+
console.clear();
|
|
375
|
+
isFirst = false;
|
|
376
|
+
if (override.startup) {
|
|
375
377
|
const logger = compiler.getInfrastructureLogger("edu-scripts");
|
|
376
|
-
override.startup({ logger, chalk
|
|
377
|
-
}
|
|
378
|
-
|
|
378
|
+
override.startup({ logger, chalk, compiler });
|
|
379
|
+
}
|
|
380
|
+
console.log(stats.toString({ preset: "errors-warnings", timings: true, colors: true }));
|
|
381
|
+
});
|
|
379
382
|
})
|
|
380
383
|
].filter(Boolean),
|
|
381
384
|
optimization: {
|
package/es/start.js
CHANGED
|
@@ -16,6 +16,15 @@ async function start(args) {
|
|
|
16
16
|
args.port = port;
|
|
17
17
|
process.env.PORT = port;
|
|
18
18
|
const compiler = rspack(getConfig(args));
|
|
19
|
+
const middleware = rspack.lazyCompilationMiddleware(compiler);
|
|
20
|
+
const oldSetupMiddlewares = compiler.options.devServer.setupMiddlewares;
|
|
21
|
+
compiler.options.devServer.setupMiddlewares = (middlewares, devServer2) => {
|
|
22
|
+
if (oldSetupMiddlewares) {
|
|
23
|
+
middlewares = oldSetupMiddlewares(middlewares, devServer2);
|
|
24
|
+
}
|
|
25
|
+
middlewares.unshift(middleware);
|
|
26
|
+
return middlewares;
|
|
27
|
+
};
|
|
19
28
|
const devServer = new RspackDevServer(compiler.options.devServer, compiler);
|
|
20
29
|
devServer.start();
|
|
21
30
|
[("SIGINT", "SIGTERM")].forEach(function(sig) {
|
|
@@ -4,9 +4,9 @@ import type { Configuration as DevServerConfiguration } from '@rspack/dev-server
|
|
|
4
4
|
type ProxyConfigArray = NonNullable<DevServerConfiguration['proxy']>;
|
|
5
5
|
export type BabelImportPlugin = {
|
|
6
6
|
libraryName: string;
|
|
7
|
-
libraryDirectory
|
|
8
|
-
|
|
9
|
-
style?: boolean | 'css' |
|
|
7
|
+
libraryDirectory?: string;
|
|
8
|
+
customName?: string;
|
|
9
|
+
style?: boolean | 'css' | string;
|
|
10
10
|
};
|
|
11
11
|
export type Config = {
|
|
12
12
|
webpack?: (config: Configuration) => Configuration | undefined;
|
|
@@ -53,7 +53,7 @@ export type Config = {
|
|
|
53
53
|
*/
|
|
54
54
|
mock?: boolean;
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* 开发模式启动后用来展示启动后的提示信息,或者自定义的逻辑
|
|
57
57
|
*/
|
|
58
58
|
startup?: (params: {
|
|
59
59
|
/** 控制台输出内容 */
|
|
@@ -69,7 +69,14 @@ export type Config = {
|
|
|
69
69
|
* @default false
|
|
70
70
|
*/
|
|
71
71
|
decorators?: boolean;
|
|
72
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* 与 babel-plugin-import 类似,但是内部是 rspack 重构,libraryDirectory 默认值是 lib
|
|
74
|
+
*
|
|
75
|
+
* 如果 libraryDirectory 传 ’‘ 则必须使用 customName 来写
|
|
76
|
+
*
|
|
77
|
+
* @see https://rspack.rs/zh/guide/features/builtin-swc-loader#rspackexperimentsimport
|
|
78
|
+
* @default [{libraryName: 'lodash', customName: 'lodash/{{member}}'}]
|
|
79
|
+
*/
|
|
73
80
|
import?: BabelImportPlugin[];
|
|
74
81
|
};
|
|
75
82
|
export declare function defineConfig(config: Config): Config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qse/edu-scripts",
|
|
3
|
-
"version": "0.0.0-beta.
|
|
3
|
+
"version": "0.0.0-beta.2",
|
|
4
4
|
"author": "Kinoko",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"@types/fs-extra": "^11.0.4",
|
|
87
87
|
"@types/jest": "^30.0.0",
|
|
88
88
|
"@types/yargs": "^17.0.35",
|
|
89
|
+
"eslint": "^9.39.3",
|
|
89
90
|
"eslint-config-qsb-react": "^2.0.4",
|
|
90
91
|
"father": "^4.5.2",
|
|
91
92
|
"jest": "^30.2.0",
|
|
@@ -125,8 +125,8 @@ function mockMiddlewave(req, res, next) {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
* @param {import('
|
|
129
|
-
* @param {import('
|
|
128
|
+
* @param {Parameters<import('@rspack/dev-server').Configuration['setupMiddlewares']>[0]} middelwaves
|
|
129
|
+
* @param {Parameters<import('@rspack/dev-server').Configuration['setupMiddlewares']>[1]} devServer
|
|
130
130
|
*/
|
|
131
131
|
function setupMockServer(middelwaves, devServer) {
|
|
132
132
|
if (!fs.existsSync(paths.mock)) return
|
|
@@ -5,8 +5,8 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
|
5
5
|
import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
|
|
6
6
|
import paths from './paths.js'
|
|
7
7
|
import appConfig from '../utils/appConfig.js'
|
|
8
|
-
import { once } from 'lodash-es'
|
|
9
8
|
import { createRequire } from 'node:module'
|
|
9
|
+
import chalk from 'chalk'
|
|
10
10
|
|
|
11
11
|
const require = createRequire(import.meta.url)
|
|
12
12
|
const appPkg = fs.readJsonSync(paths.package)
|
|
@@ -185,7 +185,7 @@ export default function getWebpackConfig(args, override) {
|
|
|
185
185
|
},
|
|
186
186
|
extensions: ['.web.js', '.web.mjs', '.js', '.mjs', '.jsx', '.ts', '.tsx', '.json', '.wasm'],
|
|
187
187
|
},
|
|
188
|
-
stats:
|
|
188
|
+
stats: false,
|
|
189
189
|
devtool: isDev ? 'cheap-module-source-map' : false,
|
|
190
190
|
module: {
|
|
191
191
|
rules: [
|
|
@@ -205,8 +205,7 @@ export default function getWebpackConfig(args, override) {
|
|
|
205
205
|
import: [
|
|
206
206
|
{
|
|
207
207
|
libraryName: 'lodash',
|
|
208
|
-
|
|
209
|
-
camel2DashComponentName: false,
|
|
208
|
+
customName: 'lodash/{{member}}',
|
|
210
209
|
},
|
|
211
210
|
...override.import,
|
|
212
211
|
],
|
|
@@ -395,15 +394,18 @@ export default function getWebpackConfig(args, override) {
|
|
|
395
394
|
: []),
|
|
396
395
|
process.env.ANALYZE && isProd && new BundleAnalyzerPlugin(),
|
|
397
396
|
isDev &&
|
|
398
|
-
!!override.startup &&
|
|
399
397
|
((compiler) => {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
398
|
+
let isFirst = true
|
|
399
|
+
compiler.hooks.afterDone.tap('edu-scripts-startup', (stats) => {
|
|
400
|
+
if (!isFirst) console.clear()
|
|
401
|
+
isFirst = false
|
|
402
|
+
|
|
403
|
+
if (override.startup) {
|
|
403
404
|
const logger = compiler.getInfrastructureLogger('edu-scripts')
|
|
404
|
-
override.startup({ logger, chalk
|
|
405
|
-
}
|
|
406
|
-
|
|
405
|
+
override.startup({ logger, chalk, compiler })
|
|
406
|
+
}
|
|
407
|
+
console.log(stats.toString({ preset: 'errors-warnings', timings: true, colors: true }))
|
|
408
|
+
})
|
|
407
409
|
}),
|
|
408
410
|
].filter(Boolean),
|
|
409
411
|
optimization: {
|
package/src/start.js
CHANGED
|
@@ -18,6 +18,15 @@ export default async function start(args) {
|
|
|
18
18
|
process.env.PORT = port
|
|
19
19
|
|
|
20
20
|
const compiler = rspack(getConfig(args))
|
|
21
|
+
const middleware = rspack.lazyCompilationMiddleware(compiler)
|
|
22
|
+
const oldSetupMiddlewares = compiler.options.devServer.setupMiddlewares
|
|
23
|
+
compiler.options.devServer.setupMiddlewares = (middlewares, devServer) => {
|
|
24
|
+
if (oldSetupMiddlewares) {
|
|
25
|
+
middlewares = oldSetupMiddlewares(middlewares, devServer)
|
|
26
|
+
}
|
|
27
|
+
middlewares.unshift(middleware)
|
|
28
|
+
return middlewares
|
|
29
|
+
}
|
|
21
30
|
const devServer = new RspackDevServer(compiler.options.devServer, compiler)
|
|
22
31
|
devServer.start()
|
|
23
32
|
;[('SIGINT', 'SIGTERM')].forEach(function (sig) {
|
|
@@ -6,9 +6,9 @@ type ProxyConfigArray = NonNullable<DevServerConfiguration['proxy']>
|
|
|
6
6
|
|
|
7
7
|
export type BabelImportPlugin = {
|
|
8
8
|
libraryName: string
|
|
9
|
-
libraryDirectory
|
|
10
|
-
|
|
11
|
-
style?: boolean | 'css' |
|
|
9
|
+
libraryDirectory?: string
|
|
10
|
+
customName?: string
|
|
11
|
+
style?: boolean | 'css' | string
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export type Config = {
|
|
@@ -56,7 +56,7 @@ export type Config = {
|
|
|
56
56
|
*/
|
|
57
57
|
mock?: boolean
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* 开发模式启动后用来展示启动后的提示信息,或者自定义的逻辑
|
|
60
60
|
*/
|
|
61
61
|
startup?: (params: {
|
|
62
62
|
/** 控制台输出内容 */
|
|
@@ -73,7 +73,14 @@ export type Config = {
|
|
|
73
73
|
* @default false
|
|
74
74
|
*/
|
|
75
75
|
decorators?: boolean
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* 与 babel-plugin-import 类似,但是内部是 rspack 重构,libraryDirectory 默认值是 lib
|
|
78
|
+
*
|
|
79
|
+
* 如果 libraryDirectory 传 ’‘ 则必须使用 customName 来写
|
|
80
|
+
*
|
|
81
|
+
* @see https://rspack.rs/zh/guide/features/builtin-swc-loader#rspackexperimentsimport
|
|
82
|
+
* @default [{libraryName: 'lodash', customName: 'lodash/{{member}}'}]
|
|
83
|
+
*/
|
|
77
84
|
import?: BabelImportPlugin[]
|
|
78
85
|
}
|
|
79
86
|
export function defineConfig(config: Config) {
|