@qse/edu-scripts 1.14.2 → 1.14.4

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.14.4 (2024-05-11)
4
+
5
+ - feat: 打包时自动压缩图片
6
+
7
+ ## 1.14.3 (2024-01-03)
8
+
9
+ - fix: 修复 app.d.ts html 文件类型错误
10
+ - feat: override transformNodeModules 默认 true,并且 production 模式下也可生效
11
+
12
+ ## 1.14.2 (2023-10-11)
13
+
14
+ - fix: 修复声明文件缺失
15
+
3
16
  ## 1.14.1 (2023-10-11)
4
17
 
5
18
  - fix: esbuild 压缩 target 改成 es5
package/app.d.ts CHANGED
@@ -16,11 +16,6 @@ declare module '*.bmp' {
16
16
  export default src
17
17
  }
18
18
 
19
- declare module '*.html' {
20
- const src: string
21
- export default src
22
- }
23
-
24
19
  declare module '*.gif' {
25
20
  const src: string
26
21
  export default src
package/docs/faq.md CHANGED
@@ -97,3 +97,48 @@ export default (callback) => {
97
97
  <!-- 引入 @qsb/antd -->
98
98
  <script src="//www.zhidianbao.cn:8088/qsxxwapdev/edu-scripts/qsb-antd.min.js"></script>
99
99
  ```
100
+
101
+ ## 钉钉遇到页面打开白屏
102
+
103
+ 这种情况多半是链接中带了 hash,导致页面跳转失败。(复制出来可能是新的链接,但页面其实是老的并未跳转)
104
+
105
+ 将下面两段代码分别加入对应的文件中,必须保证其位置在所有 `script` 最前面
106
+
107
+ 原理: 将 hash 转存至 localStorage,跳转后再取出
108
+
109
+ ```html
110
+ <!-- index.html -->
111
+ <script>
112
+ ;(function () {
113
+ var searchString = location.search
114
+ if (!/(\?|&)S=/.test(searchString)) {
115
+ var randomHexString = Math.random().toString(32).substring(2)
116
+ searchString = searchString.substring(1)
117
+ searchString = '?S=' + randomHexString + (searchString.length > 0 ? '&' + searchString : '')
118
+ }
119
+ if (location.hash) {
120
+ localStorage.setItem('qse:H', location.hash)
121
+ }
122
+ var pathnameArr = location.pathname.split('/')
123
+ var pathname = pathnameArr.slice(0, -1).concat('index1.html').join('/')
124
+ var __tmp_URL = location.origin + pathname + searchString
125
+ history.replaceState(null, document.title, __tmp_URL)
126
+ location.reload()
127
+ })()
128
+ </script>
129
+ ```
130
+
131
+ ```html
132
+ <!-- index1.html -->
133
+ <script>
134
+ ;(function () {
135
+ var hash = localStorage.getItem('qse:H')
136
+ if (hash) {
137
+ localStorage.removeItem('qse:H')
138
+ hash = /^#/.test(hash) ? hash : '#' + hash
139
+ var url = location.origin + location.pathname + location.search + hash
140
+ history.replaceState(history.state, null, url)
141
+ }
142
+ })()
143
+ </script>
144
+ ```
@@ -82,9 +82,9 @@ module.exports = function getBabelConfig(opts = {}) {
82
82
  }
83
83
  ],
84
84
  ["@babel/plugin-proposal-decorators", { legacy: true }],
85
- ["@babel/plugin-proposal-class-properties", { loose: true }],
86
- ["@babel/plugin-proposal-private-methods", { loose: true }],
87
- ["@babel/plugin-proposal-private-property-in-object", { loose: true }],
85
+ ["@babel/plugin-transform-class-properties", { loose: true }],
86
+ ["@babel/plugin-transform-private-methods", { loose: true }],
87
+ ["@babel/plugin-transform-private-property-in-object", { loose: true }],
88
88
  [
89
89
  "import",
90
90
  { libraryName: "lodash", libraryDirectory: "", camel2DashComponentName: false },
@@ -10,6 +10,7 @@ var CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
10
10
  var appPkg = require(paths.package);
11
11
  var appConfig = require("../utils/appConfig");
12
12
  var { ESBuildMinifyPlugin } = require("esbuild-loader");
13
+ var ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
13
14
  var jsMainPath = appConfig.grayscale ? `${appPkg.name}/beta/${appPkg.name}` : `${appPkg.name}/${appPkg.name}`;
14
15
  var assetPath = appConfig.grayscale ? `${appPkg.name}/beta/${appPkg.version}` : `${appPkg.name}/${appPkg.version}`;
15
16
  var cssRegex = /\.css$/;
@@ -187,7 +188,7 @@ module.exports = function getWebpackConfig(args, override) {
187
188
  exclude: /node_modules/,
188
189
  options: require("./babel")()
189
190
  },
190
- (override.transformNodeModules || isProd) && {
191
+ override.transformNodeModules && {
191
192
  test: /\.m?js$/,
192
193
  loader: "babel-loader",
193
194
  exclude: /@babel(?:\/|\\{1,2})runtime/,
@@ -356,6 +357,17 @@ module.exports = function getWebpackConfig(args, override) {
356
357
  optimization: {
357
358
  minimize: isProd && override.minify !== false,
358
359
  minimizer: [
360
+ override.minifyImage && new ImageMinimizerPlugin({
361
+ minimizer: {
362
+ implementation: ImageMinimizerPlugin.sharpMinify,
363
+ options: {
364
+ encodeOptions: {
365
+ // Your options for `sharp`
366
+ // https://sharp.pixelplumbing.com/api-output
367
+ }
368
+ }
369
+ }
370
+ }),
359
371
  override.minify === "esbuild" && new ESBuildMinifyPlugin({
360
372
  pure: override.pure_funcs ?? ["console.log"],
361
373
  drop: ["debugger"],
@@ -37,7 +37,6 @@ export type Config = {
37
37
  /**
38
38
  * 编译 node_modules 下文件
39
39
  *
40
- * 仅在 development 环境下生效。production 一定会编译 node_modules
41
40
  * @default true
42
41
  */
43
42
  transformNodeModules?: boolean;
@@ -47,6 +46,11 @@ export type Config = {
47
46
  * @default 'esbuild'
48
47
  */
49
48
  minify?: boolean | 'terser' | 'esbuild';
49
+ /**
50
+ * 打包时压缩图片资源
51
+ * @default true
52
+ */
53
+ minifyImage?: boolean;
50
54
  /** 自定义全局参数 */
51
55
  define?: Record<string, any>;
52
56
  /**
@@ -3,6 +3,7 @@ var fs = require("fs");
3
3
  var paths = require("../config/paths");
4
4
  var defaultOverride = {
5
5
  transformNodeModules: true,
6
+ minifyImage: true,
6
7
  minify: "esbuild",
7
8
  proxy: [],
8
9
  extraPostCSSPlugins: []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qse/edu-scripts",
3
- "version": "1.14.2",
3
+ "version": "1.14.4",
4
4
  "author": "Kinoko",
5
5
  "license": "MIT",
6
6
  "description": "教育工程化基础框架",
@@ -34,19 +34,19 @@
34
34
  "extends": "qsb-react"
35
35
  },
36
36
  "dependencies": {
37
- "@babel/core": "~7.18.13",
38
- "@babel/plugin-proposal-decorators": "~7.18.10",
39
- "@babel/plugin-transform-runtime": "~7.18.10",
40
- "@babel/preset-env": "~7.18.10",
41
- "@babel/preset-react": "~7.18.6",
42
- "@babel/preset-typescript": "~7.18.6",
43
- "@babel/register": "~7.18.0",
44
- "@babel/runtime": "~7.18.9",
37
+ "@babel/core": "~7.23.2",
38
+ "@babel/plugin-proposal-decorators": "~7.23.2",
39
+ "@babel/plugin-transform-runtime": "~7.23.2",
40
+ "@babel/preset-env": "~7.23.2",
41
+ "@babel/preset-react": "~7.23.2",
42
+ "@babel/preset-typescript": "~7.23.2",
43
+ "@babel/register": "~7.23.2",
44
+ "@babel/runtime": "~7.23.2",
45
45
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
46
- "@qse/ssh-sftp": "^1.0.0",
46
+ "@qse/ssh-sftp": "^1.0.1",
47
47
  "@svgr/webpack": "^8.0.1",
48
- "babel-loader": "^8.3.0",
49
- "babel-plugin-import": "^1.13.6",
48
+ "babel-loader": "^9.1.3",
49
+ "babel-plugin-import": "^1.13.8",
50
50
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
51
51
  "chalk": "^4.1.2",
52
52
  "chokidar": "^3.5.3",
@@ -61,6 +61,7 @@
61
61
  "globby": "^11.1.0",
62
62
  "gzip-size": "^6.0.0",
63
63
  "html-webpack-plugin": "^5.5.3",
64
+ "image-minimizer-webpack-plugin": "^3.0.0",
64
65
  "inquirer": "^8.2.5",
65
66
  "less": "^3.13.1",
66
67
  "less-loader": "^10.2.0",
@@ -80,6 +81,7 @@
80
81
  "recursive-readdir": "^2.2.3",
81
82
  "rimraf": "^3.0.2",
82
83
  "semver": "^7.5.4",
84
+ "sharp": "^0.32.0",
83
85
  "strip-ansi": "^6.0.1",
84
86
  "style-loader": "^3.3.3",
85
87
  "tailwindcss": "^3.3.3",
@@ -67,9 +67,9 @@ module.exports = function getBabelConfig(opts = {}) {
67
67
  },
68
68
  ],
69
69
  ['@babel/plugin-proposal-decorators', { legacy: true }],
70
- ['@babel/plugin-proposal-class-properties', { loose: true }],
71
- ['@babel/plugin-proposal-private-methods', { loose: true }],
72
- ['@babel/plugin-proposal-private-property-in-object', { loose: true }],
70
+ ['@babel/plugin-transform-class-properties', { loose: true }],
71
+ ['@babel/plugin-transform-private-methods', { loose: true }],
72
+ ['@babel/plugin-transform-private-property-in-object', { loose: true }],
73
73
  [
74
74
  'import',
75
75
  { libraryName: 'lodash', libraryDirectory: '', camel2DashComponentName: false },
@@ -9,6 +9,7 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
9
9
  const appPkg = require(paths.package)
10
10
  const appConfig = require('../utils/appConfig')
11
11
  const { ESBuildMinifyPlugin } = require('esbuild-loader')
12
+ const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
12
13
 
13
14
  const jsMainPath = appConfig.grayscale
14
15
  ? `${appPkg.name}/beta/${appPkg.name}`
@@ -210,7 +211,7 @@ module.exports = function getWebpackConfig(args, override) {
210
211
  exclude: /node_modules/,
211
212
  options: require('./babel')(),
212
213
  },
213
- (override.transformNodeModules || isProd) && {
214
+ override.transformNodeModules && {
214
215
  test: /\.m?js$/,
215
216
  loader: 'babel-loader',
216
217
  exclude: /@babel(?:\/|\\{1,2})runtime/,
@@ -381,6 +382,17 @@ module.exports = function getWebpackConfig(args, override) {
381
382
  optimization: {
382
383
  minimize: isProd && override.minify !== false,
383
384
  minimizer: [
385
+ override.minifyImage && new ImageMinimizerPlugin({
386
+ minimizer: {
387
+ implementation: ImageMinimizerPlugin.sharpMinify,
388
+ options: {
389
+ encodeOptions: {
390
+ // Your options for `sharp`
391
+ // https://sharp.pixelplumbing.com/api-output
392
+ },
393
+ },
394
+ },
395
+ }),
384
396
  override.minify === 'esbuild' &&
385
397
  new ESBuildMinifyPlugin({
386
398
  pure: override.pure_funcs ?? ['console.log'],
@@ -39,7 +39,6 @@ export type Config = {
39
39
  /**
40
40
  * 编译 node_modules 下文件
41
41
  *
42
- * 仅在 development 环境下生效。production 一定会编译 node_modules
43
42
  * @default true
44
43
  */
45
44
  transformNodeModules?: boolean
@@ -49,6 +48,11 @@ export type Config = {
49
48
  * @default 'esbuild'
50
49
  */
51
50
  minify?: boolean | 'terser' | 'esbuild'
51
+ /**
52
+ * 打包时压缩图片资源
53
+ * @default true
54
+ */
55
+ minifyImage?:boolean
52
56
  /** 自定义全局参数 */
53
57
  define?: Record<string, any>
54
58
  /**
@@ -4,6 +4,7 @@ const paths = require('../config/paths')
4
4
  /** @type {import('./defineConfig').Config} */
5
5
  const defaultOverride = {
6
6
  transformNodeModules: true,
7
+ minifyImage: true,
7
8
  minify: 'esbuild',
8
9
  proxy: [],
9
10
  extraPostCSSPlugins: [],