@qse/edu-scripts 1.15.0 → 2.0.1
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 +4 -489
- 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 +1432 -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 +67 -67
- package/pnpm-workspace.yaml +2 -0
- package/src/{auto-refactor.js → auto-refactor.ts} +51 -59
- package/src/{build.js → build.ts} +22 -16
- package/src/{cli.js → cli.ts} +26 -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} +157 -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} +19 -7
- package/src/utils/{changeDeployVersion.js → changeDeployVersion.ts} +43 -48
- package/src/utils/defineConfig.ts +19 -36
- package/src/utils/esm-register.ts +6 -0
- 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 -50
- 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,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { resolveModule } from '@/utils/resolveModule'
|
|
2
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
|
|
3
|
+
import type { Compiler, Configuration, RuleSetRule, SwcLoaderOptions } from '@rspack/core'
|
|
4
|
+
import { rspack } from '@rspack/core'
|
|
5
|
+
import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
|
|
6
|
+
import chalk from 'chalk'
|
|
7
|
+
import fs from 'fs-extra'
|
|
8
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
9
|
+
import { createRequire } from 'node:module'
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
import appConfig from '../utils/appConfig'
|
|
12
|
+
import type { Configuration as CustomConfiguration } from '../utils/defineConfig'
|
|
13
|
+
import paths from './paths'
|
|
14
|
+
import PostcssSafeAreaPlugin from './plugins/postcss-safe-area'
|
|
15
|
+
|
|
16
|
+
const require = createRequire(import.meta.url)
|
|
17
|
+
const appPkg = fs.readJsonSync(paths.package) as { name: string; version: string }
|
|
14
18
|
|
|
15
19
|
const jsMainPath = appConfig.grayscale
|
|
16
20
|
? `${appPkg.name}/beta/${appPkg.name}`
|
|
@@ -26,10 +30,19 @@ const lessModuleRegex = /\.module\.less$/
|
|
|
26
30
|
|
|
27
31
|
const imageInlineSizeLimit = 10 * 1024
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
interface QseCDN {
|
|
34
|
+
isUseCommon: boolean
|
|
35
|
+
isUseAxios: boolean
|
|
36
|
+
isUseMoment: boolean
|
|
37
|
+
isUseAntd: boolean
|
|
38
|
+
isUseQsbAntd: boolean
|
|
39
|
+
isUseQsbSchemeRender: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const qseCDN: QseCDN = (() => {
|
|
30
43
|
const contents = paths.indexHTML.map((url) => fs.readFileSync(url, 'utf-8'))
|
|
31
44
|
|
|
32
|
-
function include(pattern) {
|
|
45
|
+
function include(pattern: string | RegExp): boolean {
|
|
33
46
|
const regexp = new RegExp(pattern)
|
|
34
47
|
return contents.some((content) => regexp.test(content))
|
|
35
48
|
}
|
|
@@ -44,16 +57,21 @@ const qseCDN = (() => {
|
|
|
44
57
|
}
|
|
45
58
|
})()
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
interface CSSLoaderOptions {
|
|
61
|
+
importLoaders: number
|
|
62
|
+
sourceMap: boolean
|
|
63
|
+
modules: {
|
|
64
|
+
mode: 'global' | 'local'
|
|
65
|
+
localIdentName: string
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default function getWebpackConfig(args: any, override: CustomConfiguration): Configuration {
|
|
52
70
|
const isDev = process.env.NODE_ENV === 'development'
|
|
53
71
|
const isProd = process.env.NODE_ENV === 'production'
|
|
54
72
|
|
|
55
73
|
// common function to get style loaders
|
|
56
|
-
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
74
|
+
const getStyleLoaders = (cssOptions: CSSLoaderOptions, preProcessor?: string) => {
|
|
57
75
|
const loaders = [
|
|
58
76
|
{
|
|
59
77
|
loader: require.resolve('style-loader'),
|
|
@@ -87,10 +105,10 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
87
105
|
// https://preset-env.cssdb.org/features/#stage-2
|
|
88
106
|
},
|
|
89
107
|
],
|
|
90
|
-
isProd &&
|
|
108
|
+
isProd && PostcssSafeAreaPlugin(),
|
|
91
109
|
isProd && [require.resolve('postcss-momentum-scrolling'), ['scroll', 'auto']],
|
|
92
110
|
require.resolve('postcss-normalize'),
|
|
93
|
-
...override.extraPostCSSPlugins,
|
|
111
|
+
...(override.extraPostCSSPlugins || []),
|
|
94
112
|
].filter(Boolean),
|
|
95
113
|
},
|
|
96
114
|
sourceMap: isDev,
|
|
@@ -103,19 +121,20 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
103
121
|
options: {
|
|
104
122
|
lessOptions: {
|
|
105
123
|
javascriptEnabled: true,
|
|
106
|
-
modifyVars: fs.existsSync(paths.theme)
|
|
124
|
+
modifyVars: fs.existsSync(paths.theme)
|
|
125
|
+
? resolveModule(require(paths.theme))
|
|
126
|
+
: undefined,
|
|
107
127
|
},
|
|
108
128
|
sourceMap: true,
|
|
109
129
|
},
|
|
110
|
-
})
|
|
130
|
+
} as any)
|
|
111
131
|
}
|
|
112
132
|
return loaders
|
|
113
133
|
}
|
|
114
134
|
|
|
115
|
-
|
|
116
|
-
const config = {
|
|
135
|
+
const config: Configuration = {
|
|
117
136
|
context: process.cwd(),
|
|
118
|
-
mode: process.env.NODE_ENV,
|
|
137
|
+
mode: process.env.NODE_ENV as 'development' | 'production' | 'none',
|
|
119
138
|
entry: './src/index',
|
|
120
139
|
target: 'browserslist',
|
|
121
140
|
output: {
|
|
@@ -182,23 +201,18 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
182
201
|
resolve: {
|
|
183
202
|
alias: {
|
|
184
203
|
'@': paths.src,
|
|
204
|
+
'@swc/helpers': path.dirname(require.resolve('@swc/helpers/package.json')),
|
|
185
205
|
...override.alias,
|
|
186
206
|
},
|
|
187
207
|
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)),
|
|
208
|
+
tsConfig: {
|
|
209
|
+
configFile: paths.tsconfig,
|
|
210
|
+
references: 'auto',
|
|
198
211
|
},
|
|
199
212
|
},
|
|
213
|
+
stats: false,
|
|
214
|
+
devtool: isDev ? 'cheap-module-source-map' : false,
|
|
200
215
|
module: {
|
|
201
|
-
parser: { javascript: { exportsPresence: 'error' } },
|
|
202
216
|
rules: [
|
|
203
217
|
{
|
|
204
218
|
oneOf: [
|
|
@@ -207,16 +221,62 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
207
221
|
type: 'asset/source',
|
|
208
222
|
},
|
|
209
223
|
{
|
|
210
|
-
test: /\.
|
|
211
|
-
loader: require.resolve('babel-loader'),
|
|
224
|
+
test: /\.[cm]?[jt]sx?$/,
|
|
212
225
|
exclude: /node_modules/,
|
|
213
|
-
|
|
226
|
+
use: [
|
|
227
|
+
{
|
|
228
|
+
loader: 'builtin:swc-loader',
|
|
229
|
+
options: {
|
|
230
|
+
env: { targets: process.env.BROWSERSLIST },
|
|
231
|
+
rspackExperiments: {
|
|
232
|
+
import: [
|
|
233
|
+
{
|
|
234
|
+
libraryName: 'lodash',
|
|
235
|
+
libraryDirectory: '',
|
|
236
|
+
camelToDashComponentName: false,
|
|
237
|
+
},
|
|
238
|
+
...(override.import || []),
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
isModule: 'unknown',
|
|
242
|
+
jsc: {
|
|
243
|
+
parser: {
|
|
244
|
+
syntax: 'typescript',
|
|
245
|
+
tsx: true,
|
|
246
|
+
decorators: override.decorators,
|
|
247
|
+
},
|
|
248
|
+
externalHelpers: true,
|
|
249
|
+
transform: {
|
|
250
|
+
legacyDecorator: override.decorators,
|
|
251
|
+
react: {
|
|
252
|
+
runtime: 'automatic',
|
|
253
|
+
development: isDev,
|
|
254
|
+
refresh: isDev,
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
} satisfies SwcLoaderOptions,
|
|
259
|
+
},
|
|
260
|
+
],
|
|
214
261
|
},
|
|
215
|
-
|
|
216
|
-
test: /\.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
262
|
+
{
|
|
263
|
+
test: /\.[cm]?jsx?$/,
|
|
264
|
+
exclude: /node_modules[\\/](core-js|@swc[\\/]helpers)([\\/]|$)/,
|
|
265
|
+
use: [
|
|
266
|
+
{
|
|
267
|
+
loader: 'builtin:swc-loader',
|
|
268
|
+
options: {
|
|
269
|
+
env: { targets: process.env.BROWSERSLIST },
|
|
270
|
+
isModule: 'unknown',
|
|
271
|
+
jsc: {
|
|
272
|
+
parser: {
|
|
273
|
+
syntax: 'ecmascript',
|
|
274
|
+
},
|
|
275
|
+
externalHelpers: true,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
],
|
|
220
280
|
},
|
|
221
281
|
{
|
|
222
282
|
test: cssRegex,
|
|
@@ -328,41 +388,41 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
328
388
|
// its runtime that would otherwise be processed through "file" loader.
|
|
329
389
|
// Also exclude `html` and `json` extensions so they get processed
|
|
330
390
|
// by webpacks internal loaders.
|
|
331
|
-
|
|
391
|
+
test: /\.(?!(?:js|mjs|jsx|ts|tsx|html|json)$)[^.]+$/,
|
|
332
392
|
type: 'asset/resource',
|
|
333
393
|
},
|
|
334
|
-
].filter(Boolean),
|
|
394
|
+
].filter(Boolean) as RuleSetRule[],
|
|
335
395
|
},
|
|
336
396
|
],
|
|
337
397
|
},
|
|
338
398
|
plugins: [
|
|
339
399
|
qseCDN.isUseCommon &&
|
|
340
|
-
new
|
|
341
|
-
manifest:
|
|
400
|
+
new rspack.DllReferencePlugin({
|
|
401
|
+
manifest: fs.readJsonSync(paths.resolveOwn('asset', 'dll', 'libcommon3-manifest.json')),
|
|
342
402
|
}),
|
|
343
|
-
new
|
|
344
|
-
|
|
345
|
-
|
|
403
|
+
new rspack.NormalModuleReplacementPlugin(
|
|
404
|
+
/@rspack\/dev-server\/client\/index\.js/,
|
|
405
|
+
(resource) => {
|
|
406
|
+
const myClientPath = paths.resolveOwn('asset', 'rspack-dev-server-client.js')
|
|
407
|
+
resource.request = resource.request.replace(
|
|
408
|
+
/.*dev-server\/client\/index\.js/,
|
|
409
|
+
myClientPath
|
|
410
|
+
)
|
|
346
411
|
}
|
|
347
|
-
|
|
348
|
-
new
|
|
412
|
+
),
|
|
413
|
+
new rspack.IgnorePlugin({
|
|
349
414
|
resourceRegExp: /^\.\/locale$/,
|
|
350
415
|
contextRegExp: /moment$/,
|
|
351
416
|
}),
|
|
352
|
-
new
|
|
353
|
-
maxRetries: 3,
|
|
354
|
-
retryDelay: 300,
|
|
355
|
-
lastResortScript: `setTimeout(function() { window.location.reload(); }, 2000)`,
|
|
356
|
-
}),
|
|
357
|
-
new webpack.DefinePlugin({
|
|
417
|
+
new rspack.DefinePlugin({
|
|
358
418
|
'process.env.APP_NAME': JSON.stringify(appPkg.name),
|
|
359
419
|
'process.env.APP_VERSION': JSON.stringify(appPkg.version),
|
|
360
420
|
'process.env.BABEL_ENV': JSON.stringify(process.env.BABEL_ENV),
|
|
361
421
|
'process.env.BROWSERSLIST': JSON.stringify(process.env.BROWSERSLIST),
|
|
362
422
|
...override.define,
|
|
363
423
|
}),
|
|
364
|
-
new
|
|
365
|
-
isDev && new
|
|
424
|
+
new rspack.ProgressPlugin(),
|
|
425
|
+
isDev && new rspack.CaseSensitivePlugin(),
|
|
366
426
|
isDev && new ReactRefreshPlugin({ overlay: false }),
|
|
367
427
|
...(isDev || process.env.OUTPUT_HTML || appConfig.single || appConfig.mainProject
|
|
368
428
|
? paths.indexHTML.map(
|
|
@@ -386,82 +446,53 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
386
446
|
})
|
|
387
447
|
)
|
|
388
448
|
: []),
|
|
389
|
-
process.env.ANALYZE && isProd && new
|
|
449
|
+
process.env.ANALYZE && isProd && new RsdoctorRspackPlugin(),
|
|
390
450
|
isDev &&
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
compiler.hooks.afterDone.tap(
|
|
394
|
-
|
|
395
|
-
|
|
451
|
+
((compiler: Compiler) => {
|
|
452
|
+
let isFirst = true
|
|
453
|
+
compiler.hooks.afterDone.tap('edu-scripts-startup', (stats) => {
|
|
454
|
+
if (!isFirst) console.clear()
|
|
455
|
+
isFirst = false
|
|
456
|
+
|
|
457
|
+
if (override.startup) {
|
|
396
458
|
const logger = compiler.getInfrastructureLogger('edu-scripts')
|
|
397
|
-
override.startup({ logger, chalk
|
|
398
|
-
}
|
|
399
|
-
|
|
459
|
+
override.startup({ logger, chalk, compiler })
|
|
460
|
+
}
|
|
461
|
+
console.log(stats.toString({ preset: 'errors-warnings', timings: true, colors: true }))
|
|
462
|
+
})
|
|
400
463
|
}),
|
|
401
464
|
].filter(Boolean),
|
|
402
465
|
optimization: {
|
|
403
466
|
minimize: isProd && override.minify !== false,
|
|
404
467
|
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
|
-
},
|
|
468
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
469
|
+
minimizerOptions: {
|
|
470
|
+
ecma: 5,
|
|
471
|
+
compress: {
|
|
472
|
+
pure_funcs: override.pure_funcs,
|
|
473
|
+
drop_debugger: true,
|
|
474
|
+
ecma: 5,
|
|
475
|
+
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
476
|
+
// https://github.com/facebook/create-react-app/issues/2376
|
|
477
|
+
// Pending further investigation:
|
|
478
|
+
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
479
|
+
comparisons: false,
|
|
480
|
+
// Disabled because of an issue with Terser breaking valid code:
|
|
481
|
+
// https://github.com/facebook/create-react-app/issues/5250
|
|
482
|
+
// Pending further investigation:
|
|
483
|
+
// https://github.com/terser-js/terser/issues/120
|
|
484
|
+
inline: 2,
|
|
455
485
|
},
|
|
456
|
-
}
|
|
457
|
-
|
|
486
|
+
},
|
|
487
|
+
}),
|
|
488
|
+
],
|
|
458
489
|
splitChunks: {
|
|
459
490
|
minChunks: 2,
|
|
460
491
|
},
|
|
461
492
|
},
|
|
462
493
|
performance: {
|
|
463
494
|
maxEntrypointSize: appConfig.single ? 1024 * 1024 : 30 * 1024,
|
|
464
|
-
maxAssetSize: 1024 * 1024,
|
|
495
|
+
maxAssetSize: 2 * 1024 * 1024,
|
|
465
496
|
},
|
|
466
497
|
}
|
|
467
498
|
|
|
@@ -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 }
|