@qse/edu-scripts 1.14.17 → 2.0.0
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/CHANGELOG.md +2 -483
- package/asset/rspack-dev-server-client.js +534 -0
- package/{src/asset → asset}/template/edu-scripts.override.js.tpl +2 -2
- package/{lib/asset → asset}/template/tailwind.config.js.tpl +1 -1
- package/babel.config.json +6 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1426 -0
- package/dist/index.d.mts +83 -0
- package/dist/index.mjs +13 -0
- package/eslint.config.mjs +3 -0
- package/{jest.config.js → jest.config.mjs} +8 -4
- package/package.json +52 -57
- package/src/{auto-refactor.js → auto-refactor.ts} +51 -59
- package/src/{build.js → build.ts} +22 -16
- package/src/{cli.js → cli.ts} +25 -21
- package/src/{commit-dist.js → commit-dist.ts} +28 -21
- package/src/config/paths.ts +52 -0
- package/src/config/plugins/mock-server/{index.js → index.ts} +30 -41
- package/src/config/plugins/{postcss-safe-area.js → postcss-safe-area.ts} +4 -2
- package/src/config/{webpackConfig.js → webpackConfig.ts} +152 -126
- package/src/config/{webpackDevServerConfig.js → webpackDevServerConfig.ts} +18 -18
- package/src/{deploy.js → deploy.ts} +36 -25
- package/src/{generator.js → generator.ts} +5 -14
- package/src/start.ts +52 -0
- package/src/utils/FileSizeReporter.ts +166 -0
- package/src/utils/{appConfig.js → appConfig.ts} +5 -4
- package/src/utils/{beforeStart.js → beforeStart.ts} +18 -29
- package/src/utils/{changeDeployVersion.js → changeDeployVersion.ts} +43 -48
- package/src/utils/defineConfig.ts +19 -36
- package/src/utils/{exec.js → exec.ts} +3 -3
- package/src/utils/{getConfig.js → getConfig.ts} +7 -5
- package/src/utils/getOverride.ts +32 -0
- package/src/utils/resolveModule.ts +3 -0
- package/tsconfig.json +3 -15
- package/tsdown.config.ts +5 -0
- package/docs/changelog.md +0 -5
- package/docs/debug.md +0 -17
- package/docs/deploy.md +0 -54
- package/docs/faq.md +0 -144
- package/docs/feat.md +0 -167
- package/docs/grayscale.md +0 -31
- package/docs/index.md +0 -5
- package/docs/mode.md +0 -42
- package/docs/override.md +0 -193
- package/docs/refactor-react-16.md +0 -37
- package/docs/refactor.md +0 -67
- package/docs/static.md +0 -24
- package/lib/asset/template/edu-scripts.override.js.tpl +0 -7
- package/lib/auto-refactor.js +0 -151
- package/lib/build.js +0 -59
- package/lib/cli.js +0 -66
- package/lib/commit-dist.js +0 -79
- package/lib/config/babel.dependencies.js +0 -79
- package/lib/config/babel.js +0 -107
- package/lib/config/paths.js +0 -36
- package/lib/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -31
- package/lib/config/plugins/mock-server/defineMock.d.ts +0 -6
- package/lib/config/plugins/mock-server/defineMock.js +0 -31
- package/lib/config/plugins/mock-server/index.js +0 -122
- package/lib/config/plugins/postcss-safe-area.js +0 -19
- package/lib/config/plugins/ws-utils-createSocketURL.js +0 -118
- package/lib/config/webpackConfig.js +0 -462
- package/lib/config/webpackDevServerConfig.js +0 -72
- package/lib/deploy.js +0 -143
- package/lib/generator.js +0 -50
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -32
- package/lib/start.js +0 -36
- package/lib/utils/FileSizeReporter.js +0 -107
- package/lib/utils/appConfig.js +0 -32
- package/lib/utils/beforeStart.js +0 -62
- package/lib/utils/changeDeployVersion.js +0 -89
- package/lib/utils/defineConfig.d.ts +0 -93
- package/lib/utils/defineConfig.js +0 -31
- package/lib/utils/exec.js +0 -7
- package/lib/utils/getConfig.js +0 -20
- package/lib/utils/getOverride.js +0 -61
- package/src/asset/dll/libcommon3-manifest.json +0 -181
- package/src/asset/template/edu-app-env.d.ts.tpl +0 -20
- package/src/asset/template/tailwind.config.js.tpl +0 -11
- package/src/asset/template/tsconfig.json.tpl +0 -24
- package/src/config/babel.dependencies.js +0 -66
- package/src/config/babel.js +0 -94
- package/src/config/paths.js +0 -38
- package/src/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -55
- package/src/config/plugins/ws-utils-createSocketURL.js +0 -140
- package/src/start.js +0 -44
- package/src/utils/FileSizeReporter.js +0 -151
- package/src/utils/getOverride.js +0 -48
- /package/{lib/asset → asset}/dll/libcommon3-manifest.json +0 -0
- /package/{lib/asset → asset}/template/edu-app-env.d.ts.tpl +0 -0
- /package/{lib/asset → asset}/template/tsconfig.json.tpl +0 -0
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
|
|
2
|
+
import { rspack } from '@rspack/core'
|
|
3
|
+
import type { Configuration, Compiler, RuleSetRule, SwcLoaderOptions } from '@rspack/core'
|
|
4
|
+
import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
import fs from 'fs-extra'
|
|
7
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
8
|
+
import { createRequire } from 'node:module'
|
|
9
|
+
import appConfig from '../utils/appConfig'
|
|
10
|
+
import type { Configuration as CustomConfiguration } from '../utils/defineConfig'
|
|
11
|
+
import paths from './paths'
|
|
12
|
+
import PostcssSafeAreaPlugin from './plugins/postcss-safe-area'
|
|
13
|
+
import { resolveModule } from '@/utils/resolveModule'
|
|
14
|
+
|
|
15
|
+
const require = createRequire(import.meta.url)
|
|
16
|
+
const appPkg = fs.readJsonSync(paths.package) as { name: string; version: string }
|
|
14
17
|
|
|
15
18
|
const jsMainPath = appConfig.grayscale
|
|
16
19
|
? `${appPkg.name}/beta/${appPkg.name}`
|
|
@@ -26,10 +29,19 @@ const lessModuleRegex = /\.module\.less$/
|
|
|
26
29
|
|
|
27
30
|
const imageInlineSizeLimit = 10 * 1024
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
interface QseCDN {
|
|
33
|
+
isUseCommon: boolean
|
|
34
|
+
isUseAxios: boolean
|
|
35
|
+
isUseMoment: boolean
|
|
36
|
+
isUseAntd: boolean
|
|
37
|
+
isUseQsbAntd: boolean
|
|
38
|
+
isUseQsbSchemeRender: boolean
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const qseCDN: QseCDN = (() => {
|
|
30
42
|
const contents = paths.indexHTML.map((url) => fs.readFileSync(url, 'utf-8'))
|
|
31
43
|
|
|
32
|
-
function include(pattern) {
|
|
44
|
+
function include(pattern: string | RegExp): boolean {
|
|
33
45
|
const regexp = new RegExp(pattern)
|
|
34
46
|
return contents.some((content) => regexp.test(content))
|
|
35
47
|
}
|
|
@@ -44,16 +56,21 @@ const qseCDN = (() => {
|
|
|
44
56
|
}
|
|
45
57
|
})()
|
|
46
58
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
interface CSSLoaderOptions {
|
|
60
|
+
importLoaders: number
|
|
61
|
+
sourceMap: boolean
|
|
62
|
+
modules: {
|
|
63
|
+
mode: 'global' | 'local'
|
|
64
|
+
localIdentName: string
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default function getWebpackConfig(args: any, override: CustomConfiguration): Configuration {
|
|
52
69
|
const isDev = process.env.NODE_ENV === 'development'
|
|
53
70
|
const isProd = process.env.NODE_ENV === 'production'
|
|
54
71
|
|
|
55
72
|
// common function to get style loaders
|
|
56
|
-
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
73
|
+
const getStyleLoaders = (cssOptions: CSSLoaderOptions, preProcessor?: string) => {
|
|
57
74
|
const loaders = [
|
|
58
75
|
{
|
|
59
76
|
loader: require.resolve('style-loader'),
|
|
@@ -87,10 +104,10 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
87
104
|
// https://preset-env.cssdb.org/features/#stage-2
|
|
88
105
|
},
|
|
89
106
|
],
|
|
90
|
-
isProd &&
|
|
107
|
+
isProd && PostcssSafeAreaPlugin(),
|
|
91
108
|
isProd && [require.resolve('postcss-momentum-scrolling'), ['scroll', 'auto']],
|
|
92
109
|
require.resolve('postcss-normalize'),
|
|
93
|
-
...override.extraPostCSSPlugins,
|
|
110
|
+
...(override.extraPostCSSPlugins || []),
|
|
94
111
|
].filter(Boolean),
|
|
95
112
|
},
|
|
96
113
|
sourceMap: isDev,
|
|
@@ -103,19 +120,20 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
103
120
|
options: {
|
|
104
121
|
lessOptions: {
|
|
105
122
|
javascriptEnabled: true,
|
|
106
|
-
modifyVars: fs.existsSync(paths.theme)
|
|
123
|
+
modifyVars: fs.existsSync(paths.theme)
|
|
124
|
+
? resolveModule(require(paths.theme))
|
|
125
|
+
: undefined,
|
|
107
126
|
},
|
|
108
127
|
sourceMap: true,
|
|
109
128
|
},
|
|
110
|
-
})
|
|
129
|
+
} as any)
|
|
111
130
|
}
|
|
112
131
|
return loaders
|
|
113
132
|
}
|
|
114
133
|
|
|
115
|
-
|
|
116
|
-
const config = {
|
|
134
|
+
const config: Configuration = {
|
|
117
135
|
context: process.cwd(),
|
|
118
|
-
mode: process.env.NODE_ENV,
|
|
136
|
+
mode: process.env.NODE_ENV as 'development' | 'production' | 'none',
|
|
119
137
|
entry: './src/index',
|
|
120
138
|
target: 'browserslist',
|
|
121
139
|
output: {
|
|
@@ -185,20 +203,14 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
185
203
|
...override.alias,
|
|
186
204
|
},
|
|
187
205
|
extensions: ['.web.js', '.web.mjs', '.js', '.mjs', '.jsx', '.ts', '.tsx', '.json', '.wasm'],
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
cache: {
|
|
192
|
-
type: 'filesystem',
|
|
193
|
-
version: require('../../package.json').version,
|
|
194
|
-
buildDependencies: {
|
|
195
|
-
config: [__filename],
|
|
196
|
-
override: [paths.override, paths.theme].filter((f) => fs.existsSync(f)),
|
|
197
|
-
tsconfig: [paths.tsconfig, paths.jsconfig].filter((f) => fs.existsSync(f)),
|
|
206
|
+
tsConfig: {
|
|
207
|
+
configFile: paths.tsconfig,
|
|
208
|
+
references: 'auto',
|
|
198
209
|
},
|
|
199
210
|
},
|
|
211
|
+
stats: false,
|
|
212
|
+
devtool: isDev ? 'cheap-module-source-map' : false,
|
|
200
213
|
module: {
|
|
201
|
-
parser: { javascript: { exportsPresence: 'error' } },
|
|
202
214
|
rules: [
|
|
203
215
|
{
|
|
204
216
|
oneOf: [
|
|
@@ -207,16 +219,62 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
207
219
|
type: 'asset/source',
|
|
208
220
|
},
|
|
209
221
|
{
|
|
210
|
-
test: /\.
|
|
211
|
-
loader: require.resolve('babel-loader'),
|
|
222
|
+
test: /\.[cm]?[jt]sx?$/,
|
|
212
223
|
exclude: /node_modules/,
|
|
213
|
-
|
|
224
|
+
use: [
|
|
225
|
+
{
|
|
226
|
+
loader: 'builtin:swc-loader',
|
|
227
|
+
options: {
|
|
228
|
+
env: { targets: process.env.BROWSERSLIST },
|
|
229
|
+
rspackExperiments: {
|
|
230
|
+
import: [
|
|
231
|
+
{
|
|
232
|
+
libraryName: 'lodash',
|
|
233
|
+
libraryDirectory: '',
|
|
234
|
+
camelToDashComponentName: false,
|
|
235
|
+
},
|
|
236
|
+
...(override.import || []),
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
isModule: 'unknown',
|
|
240
|
+
jsc: {
|
|
241
|
+
parser: {
|
|
242
|
+
syntax: 'typescript',
|
|
243
|
+
tsx: true,
|
|
244
|
+
decorators: override.decorators,
|
|
245
|
+
},
|
|
246
|
+
externalHelpers: true,
|
|
247
|
+
transform: {
|
|
248
|
+
legacyDecorator: override.decorators,
|
|
249
|
+
react: {
|
|
250
|
+
runtime: 'automatic',
|
|
251
|
+
development: isDev,
|
|
252
|
+
refresh: isDev,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
} satisfies SwcLoaderOptions,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
214
259
|
},
|
|
215
|
-
|
|
216
|
-
test: /\.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
260
|
+
{
|
|
261
|
+
test: /\.[cm]?jsx?$/,
|
|
262
|
+
exclude: /node_modules[\\/](core-js|@swc[\\/]helpers)([\\/]|$)/,
|
|
263
|
+
use: [
|
|
264
|
+
{
|
|
265
|
+
loader: 'builtin:swc-loader',
|
|
266
|
+
options: {
|
|
267
|
+
env: { targets: process.env.BROWSERSLIST },
|
|
268
|
+
isModule: 'unknown',
|
|
269
|
+
jsc: {
|
|
270
|
+
parser: {
|
|
271
|
+
syntax: 'ecmascript',
|
|
272
|
+
},
|
|
273
|
+
externalHelpers: true,
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
],
|
|
220
278
|
},
|
|
221
279
|
{
|
|
222
280
|
test: cssRegex,
|
|
@@ -328,41 +386,38 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
328
386
|
// its runtime that would otherwise be processed through "file" loader.
|
|
329
387
|
// Also exclude `html` and `json` extensions so they get processed
|
|
330
388
|
// by webpacks internal loaders.
|
|
331
|
-
|
|
389
|
+
test: /\.(?!(?:js|mjs|jsx|ts|tsx|html|json)$)[^.]+$/,
|
|
332
390
|
type: 'asset/resource',
|
|
333
391
|
},
|
|
334
|
-
].filter(Boolean),
|
|
392
|
+
].filter(Boolean) as RuleSetRule[],
|
|
335
393
|
},
|
|
336
394
|
],
|
|
337
395
|
},
|
|
338
396
|
plugins: [
|
|
339
397
|
qseCDN.isUseCommon &&
|
|
340
|
-
new
|
|
341
|
-
manifest:
|
|
398
|
+
new rspack.DllReferencePlugin({
|
|
399
|
+
manifest: fs.readJsonSync(paths.resolveOwn('asset', 'dll', 'libcommon3-manifest.json')),
|
|
342
400
|
}),
|
|
343
|
-
new
|
|
344
|
-
|
|
345
|
-
|
|
401
|
+
new rspack.NormalModuleReplacementPlugin(
|
|
402
|
+
/@rspack\/dev-server\/client\/index\.js/,
|
|
403
|
+
(resource) => {
|
|
404
|
+
const myClientPath = paths.resolveOwn('asset', 'rspack-dev-server-client.js')
|
|
405
|
+
resource.request = resource.request.replace(/.*dev-server\/client\/index\.js/, myClientPath)
|
|
346
406
|
}
|
|
347
|
-
|
|
348
|
-
new
|
|
407
|
+
),
|
|
408
|
+
new rspack.IgnorePlugin({
|
|
349
409
|
resourceRegExp: /^\.\/locale$/,
|
|
350
410
|
contextRegExp: /moment$/,
|
|
351
411
|
}),
|
|
352
|
-
new
|
|
353
|
-
maxRetries: 3,
|
|
354
|
-
retryDelay: 300,
|
|
355
|
-
lastResortScript: `setTimeout(function() { window.location.reload(); }, 2000)`,
|
|
356
|
-
}),
|
|
357
|
-
new webpack.DefinePlugin({
|
|
412
|
+
new rspack.DefinePlugin({
|
|
358
413
|
'process.env.APP_NAME': JSON.stringify(appPkg.name),
|
|
359
414
|
'process.env.APP_VERSION': JSON.stringify(appPkg.version),
|
|
360
415
|
'process.env.BABEL_ENV': JSON.stringify(process.env.BABEL_ENV),
|
|
361
416
|
'process.env.BROWSERSLIST': JSON.stringify(process.env.BROWSERSLIST),
|
|
362
417
|
...override.define,
|
|
363
418
|
}),
|
|
364
|
-
new
|
|
365
|
-
isDev && new
|
|
419
|
+
new rspack.ProgressPlugin(),
|
|
420
|
+
isDev && new rspack.CaseSensitivePlugin(),
|
|
366
421
|
isDev && new ReactRefreshPlugin({ overlay: false }),
|
|
367
422
|
...(isDev || process.env.OUTPUT_HTML || appConfig.single || appConfig.mainProject
|
|
368
423
|
? paths.indexHTML.map(
|
|
@@ -386,82 +441,53 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
386
441
|
})
|
|
387
442
|
)
|
|
388
443
|
: []),
|
|
389
|
-
process.env.ANALYZE && isProd && new
|
|
444
|
+
process.env.ANALYZE && isProd && new RsdoctorRspackPlugin(),
|
|
390
445
|
isDev &&
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
compiler.hooks.afterDone.tap(
|
|
394
|
-
|
|
395
|
-
|
|
446
|
+
((compiler: Compiler) => {
|
|
447
|
+
let isFirst = true
|
|
448
|
+
compiler.hooks.afterDone.tap('edu-scripts-startup', (stats) => {
|
|
449
|
+
if (!isFirst) console.clear()
|
|
450
|
+
isFirst = false
|
|
451
|
+
|
|
452
|
+
if (override.startup) {
|
|
396
453
|
const logger = compiler.getInfrastructureLogger('edu-scripts')
|
|
397
|
-
override.startup({ logger, chalk
|
|
398
|
-
}
|
|
399
|
-
|
|
454
|
+
override.startup({ logger, chalk, compiler })
|
|
455
|
+
}
|
|
456
|
+
console.log(stats.toString({ preset: 'errors-warnings', timings: true, colors: true }))
|
|
457
|
+
})
|
|
400
458
|
}),
|
|
401
459
|
].filter(Boolean),
|
|
402
460
|
optimization: {
|
|
403
461
|
minimize: isProd && override.minify !== false,
|
|
404
462
|
minimizer: [
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// sections only apply transformations that are ecma 5 safe
|
|
423
|
-
// https://github.com/facebook/create-react-app/pull/4234
|
|
424
|
-
ecma: 8,
|
|
425
|
-
},
|
|
426
|
-
compress: {
|
|
427
|
-
pure_funcs: override.pure_funcs ?? ['console.log'],
|
|
428
|
-
drop_debugger: true,
|
|
429
|
-
ecma: 5,
|
|
430
|
-
warnings: false,
|
|
431
|
-
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
432
|
-
// https://github.com/facebook/create-react-app/issues/2376
|
|
433
|
-
// Pending further investigation:
|
|
434
|
-
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
435
|
-
comparisons: false,
|
|
436
|
-
// Disabled because of an issue with Terser breaking valid code:
|
|
437
|
-
// https://github.com/facebook/create-react-app/issues/5250
|
|
438
|
-
// Pending further investigation:
|
|
439
|
-
// https://github.com/terser-js/terser/issues/120
|
|
440
|
-
inline: 2,
|
|
441
|
-
},
|
|
442
|
-
mangle: {
|
|
443
|
-
safari10: true,
|
|
444
|
-
},
|
|
445
|
-
// Added for profiling in devtools
|
|
446
|
-
keep_classnames: false,
|
|
447
|
-
keep_fnames: false,
|
|
448
|
-
output: {
|
|
449
|
-
ecma: 5,
|
|
450
|
-
comments: false,
|
|
451
|
-
// Turned on because emoji and regex is not minified properly using default
|
|
452
|
-
// https://github.com/facebook/create-react-app/issues/2488
|
|
453
|
-
ascii_only: true,
|
|
454
|
-
},
|
|
463
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
464
|
+
minimizerOptions: {
|
|
465
|
+
ecma: 5,
|
|
466
|
+
compress: {
|
|
467
|
+
pure_funcs: override.pure_funcs,
|
|
468
|
+
drop_debugger: true,
|
|
469
|
+
ecma: 5,
|
|
470
|
+
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
471
|
+
// https://github.com/facebook/create-react-app/issues/2376
|
|
472
|
+
// Pending further investigation:
|
|
473
|
+
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
474
|
+
comparisons: false,
|
|
475
|
+
// Disabled because of an issue with Terser breaking valid code:
|
|
476
|
+
// https://github.com/facebook/create-react-app/issues/5250
|
|
477
|
+
// Pending further investigation:
|
|
478
|
+
// https://github.com/terser-js/terser/issues/120
|
|
479
|
+
inline: 2,
|
|
455
480
|
},
|
|
456
|
-
}
|
|
457
|
-
|
|
481
|
+
},
|
|
482
|
+
}),
|
|
483
|
+
],
|
|
458
484
|
splitChunks: {
|
|
459
485
|
minChunks: 2,
|
|
460
486
|
},
|
|
461
487
|
},
|
|
462
488
|
performance: {
|
|
463
489
|
maxEntrypointSize: appConfig.single ? 1024 * 1024 : 30 * 1024,
|
|
464
|
-
maxAssetSize: 1024 * 1024,
|
|
490
|
+
maxAssetSize: 2 * 1024 * 1024,
|
|
465
491
|
},
|
|
466
492
|
}
|
|
467
493
|
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { Configuration } from '@rspack/dev-server'
|
|
2
|
+
import type { Configuration as CustomConfiguration } from '../utils/defineConfig'
|
|
3
|
+
import setupMockServer from './plugins/mock-server'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
interface ProxyConfig {
|
|
6
|
+
context: string[]
|
|
7
|
+
target: string
|
|
8
|
+
changeOrigin: boolean
|
|
9
|
+
onProxyReq: (proxyReq: any) => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function createProxy(context: string, target: string, origin?: string): ProxyConfig {
|
|
6
13
|
const url = new URL(origin || target)
|
|
7
14
|
|
|
8
15
|
return {
|
|
@@ -17,20 +24,13 @@ function createProxy(context, target, origin) {
|
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
* @param {*} args
|
|
22
|
-
* @param {import('../utils/defineConfig').Config} override
|
|
23
|
-
*/
|
|
24
|
-
module.exports = function getWebpackDevServerConfig(args, override) {
|
|
27
|
+
export default function getWebpackDevServerConfig(args: any, override: CustomConfiguration): Configuration {
|
|
25
28
|
const host = process.env.HOST || '0.0.0.0'
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
const devServer = {
|
|
29
|
-
hot: true,
|
|
30
|
+
const devServer: Configuration = {
|
|
30
31
|
allowedHosts: 'all',
|
|
31
32
|
historyApiFallback: true,
|
|
32
33
|
port: args.port,
|
|
33
|
-
open: args.open,
|
|
34
34
|
host,
|
|
35
35
|
client: {
|
|
36
36
|
webSocketURL: 'auto://0.0.0.0:0/ws',
|
|
@@ -60,19 +60,19 @@ module.exports = function getWebpackDevServerConfig(args, override) {
|
|
|
60
60
|
|
|
61
61
|
if (override.proxy) {
|
|
62
62
|
if (Array.isArray(override.proxy)) {
|
|
63
|
-
devServer.proxy = [...override.proxy, ...devServer.proxy]
|
|
63
|
+
devServer.proxy = [...override.proxy, ...(devServer.proxy || [])]
|
|
64
64
|
} else if (typeof override.proxy === 'object') {
|
|
65
65
|
const proxies = Object.entries(override.proxy).map(([context, target]) => {
|
|
66
|
-
return createProxy(context, target)
|
|
66
|
+
return createProxy(context, target as string)
|
|
67
67
|
})
|
|
68
|
-
devServer.proxy = [...proxies, ...devServer.proxy]
|
|
68
|
+
devServer.proxy = [...proxies, ...(devServer.proxy || [])]
|
|
69
69
|
} else {
|
|
70
70
|
throw new Error('proxy 必须是数组或对象')
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// 清理重复的代理配置
|
|
74
|
-
const proxyMap = new Map()
|
|
75
|
-
devServer.proxy = devServer.proxy.filter((item) => {
|
|
74
|
+
const proxyMap = new Map<string, boolean>()
|
|
75
|
+
devServer.proxy = (devServer.proxy as ProxyConfig[]).filter((item) => {
|
|
76
76
|
const key = JSON.stringify([...item.context].sort())
|
|
77
77
|
if (!proxyMap.has(key)) {
|
|
78
78
|
proxyMap.set(key, true)
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { sshSftp } from '@qse/ssh-sftp'
|
|
3
|
+
import paths from './config/paths.js'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import fs from 'fs-extra'
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import changeDeployVersion from './utils/changeDeployVersion'
|
|
8
|
+
import ora from 'ora'
|
|
9
|
+
import appConfig from './utils/appConfig.js'
|
|
10
|
+
import { format } from 'prettier'
|
|
11
|
+
|
|
12
|
+
const appPkg = fs.readJsonSync(paths.package)
|
|
10
13
|
|
|
11
14
|
const baseConfig = {
|
|
12
15
|
localPath: 'dist',
|
|
@@ -17,8 +20,8 @@ const baseConfig = {
|
|
|
17
20
|
noWarn: true,
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
async function normalDeploy(args) {
|
|
21
|
-
const resolve =
|
|
23
|
+
async function normalDeploy(args: DeployArgs) {
|
|
24
|
+
const resolve = paths.resolveApp
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* 生成路径
|
|
@@ -28,7 +31,7 @@ async function normalDeploy(args) {
|
|
|
28
31
|
* @name tmpBase 本地临时文件夹 到`__tmp__`层
|
|
29
32
|
* @param {string} remoteFilePath 远程文件相对`opts.remotePath`地址
|
|
30
33
|
*/
|
|
31
|
-
function getLocalAndRemoteFilePath(remoteFilePath, opts) {
|
|
34
|
+
function getLocalAndRemoteFilePath(remoteFilePath: string, opts: any) {
|
|
32
35
|
const splited = remoteFilePath.split('/')
|
|
33
36
|
const fileName = splited[splited.length - 1]
|
|
34
37
|
const tmpBase = resolve(opts.localPath, '__tmp__')
|
|
@@ -45,13 +48,13 @@ async function normalDeploy(args) {
|
|
|
45
48
|
date = new Date(date.getTime() - date.getTimezoneOffset() * 60000)
|
|
46
49
|
return date.toISOString().replace(/T/, ' ').replace(/\..+/, '')
|
|
47
50
|
}
|
|
48
|
-
function updateLogContent(content, info) {
|
|
51
|
+
function updateLogContent(content: string, info: any) {
|
|
49
52
|
const lines = content.trim().split('\n')
|
|
50
53
|
lines.push(`[${dateTime()}] ${JSON.stringify(info)}\n`)
|
|
51
54
|
return lines.slice(-50).join('\n')
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
async function upload(opts) {
|
|
57
|
+
async function upload(opts: any) {
|
|
55
58
|
// 上传dist文件
|
|
56
59
|
const { sftp, opts: fullOpts } = await sshSftp(opts)
|
|
57
60
|
|
|
@@ -66,8 +69,8 @@ async function normalDeploy(args) {
|
|
|
66
69
|
fs.mkdirSync(tmpDir, { recursive: true })
|
|
67
70
|
|
|
68
71
|
const info = {
|
|
69
|
-
name:
|
|
70
|
-
version:
|
|
72
|
+
name: appPkg.name,
|
|
73
|
+
version: appPkg.version,
|
|
71
74
|
grayscale: appConfig.grayscale,
|
|
72
75
|
}
|
|
73
76
|
|
|
@@ -77,7 +80,8 @@ async function normalDeploy(args) {
|
|
|
77
80
|
|
|
78
81
|
// 读取本地文件内容
|
|
79
82
|
let code = await fs.readFile(tmpFile, { encoding: 'utf-8' })
|
|
80
|
-
code = changeDeployVersion(code, info)
|
|
83
|
+
code = await changeDeployVersion(code, info)
|
|
84
|
+
code = await format(code, { parser: 'babel', printWidth: 120 })
|
|
81
85
|
|
|
82
86
|
await sftp.fastPut(tmpFile, remoteFile + '.bak')
|
|
83
87
|
await fs.writeFile(tmpFile, code)
|
|
@@ -92,14 +96,14 @@ async function normalDeploy(args) {
|
|
|
92
96
|
try {
|
|
93
97
|
await sftp.fastGet(remoteLogFile, tmpLogFile)
|
|
94
98
|
content = await fs.readFile(tmpLogFile, 'utf-8')
|
|
95
|
-
} catch
|
|
99
|
+
} catch {}
|
|
96
100
|
content = updateLogContent(content, info)
|
|
97
101
|
await fs.writeFile(tmpLogFile, content)
|
|
98
102
|
await sftp.fastPut(tmpLogFile, remoteLogFile)
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
spinner.succeed('已更新 ver.js 版本配置')
|
|
102
|
-
} catch (e) {
|
|
106
|
+
} catch (e: any) {
|
|
103
107
|
spinner.fail(`自动修改 ver.js 失败,请手动修改`)
|
|
104
108
|
console.log(chalk.bgRed(e.message))
|
|
105
109
|
} finally {
|
|
@@ -120,19 +124,19 @@ async function normalDeploy(args) {
|
|
|
120
124
|
},
|
|
121
125
|
}
|
|
122
126
|
const uploadSftpConfigs = []
|
|
123
|
-
if (args.
|
|
127
|
+
if (args.bureau) {
|
|
124
128
|
uploadSftpConfigs.push(presetConfig.b)
|
|
125
129
|
}
|
|
126
|
-
if (args.
|
|
130
|
+
if (args.school) {
|
|
127
131
|
uploadSftpConfigs.push(presetConfig.s)
|
|
128
132
|
}
|
|
129
|
-
if (args.
|
|
133
|
+
if (args.documentshelves) {
|
|
130
134
|
uploadSftpConfigs.push(presetConfig.d)
|
|
131
135
|
}
|
|
132
|
-
if (args.
|
|
136
|
+
if (args.compositionshelves) {
|
|
133
137
|
uploadSftpConfigs.push(presetConfig.c)
|
|
134
138
|
}
|
|
135
|
-
if (args.
|
|
139
|
+
if (args.compositionshelvesDingtalk) {
|
|
136
140
|
uploadSftpConfigs.push(presetConfig.cd)
|
|
137
141
|
}
|
|
138
142
|
if (uploadSftpConfigs.length === 0) {
|
|
@@ -170,7 +174,14 @@ async function singleDeploy() {
|
|
|
170
174
|
sshSftp(config)
|
|
171
175
|
}
|
|
172
176
|
|
|
173
|
-
|
|
177
|
+
interface DeployArgs {
|
|
178
|
+
school?: boolean
|
|
179
|
+
bureau?: boolean
|
|
180
|
+
documentshelves?: boolean
|
|
181
|
+
compositionshelves?: boolean
|
|
182
|
+
compositionshelvesDingtalk?: boolean
|
|
183
|
+
}
|
|
184
|
+
export default function deploy(args: DeployArgs) {
|
|
174
185
|
if (appConfig.single) {
|
|
175
186
|
singleDeploy()
|
|
176
187
|
} else {
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const chalk = require('chalk')
|
|
1
|
+
import fs from 'fs-extra'
|
|
2
|
+
import paths from './config/paths'
|
|
3
|
+
import chalk from 'chalk'
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
* @param {string[]} args
|
|
8
|
-
* @returns {string}
|
|
9
|
-
*/
|
|
10
|
-
const getTmpPath = (...args) => path.resolve(__dirname, 'asset', 'template', ...args)
|
|
5
|
+
const getTmpPath = (...args: string[]) => paths.resolveOwn('asset', 'template', ...args)
|
|
11
6
|
|
|
12
7
|
async function generatorOverride() {
|
|
13
8
|
if (fs.existsSync(paths.override)) {
|
|
@@ -61,8 +56,4 @@ async function generatorTailwind() {
|
|
|
61
56
|
)
|
|
62
57
|
}
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
override: generatorOverride,
|
|
66
|
-
ts: generatorTsconfig,
|
|
67
|
-
tailwind: generatorTailwind,
|
|
68
|
-
}
|
|
59
|
+
export { generatorOverride as override, generatorTsconfig as ts, generatorTailwind as tailwind }
|