@autobest-ui/scripts 1.9.4 → 1.9.5

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/README.md CHANGED
@@ -51,12 +51,11 @@ module.exports = function(
51
51
  #### app.config.js 介绍
52
52
 
53
53
  ##### start 配置参数说明(作用于`react-spa start` 或者 `react-ssr start`)
54
- | 参数名 | 默认值 | 说明 |
55
- | ---- |------|-----------------------------------|
56
- | startDefaultPort | 3030 | start默认端口号, 可自定义,下面介绍 |
57
- | startOpenPath | '/' | start 打开浏览器的路径 |
54
+ | 参数名 | 默认值 | 说明 |
55
+ | ---- |------| ---- |
56
+ | startDefaultPort | 3030 | start默认端口号, 可自定义,下面介绍 |
57
+ | startOpenPath | '/' | start 打开浏览器的路径 |
58
58
  | getStartEnvConfig | {} | start 自定义环境变量的方法,会追加到process.env中 |
59
- | devServer | {} | start 自定义devServer配置 |
60
59
 
61
60
  ##### hot ssr 配置参数说明(作用于`react-ssr ssr`)
62
61
  | 参数名 | 默认值 | 说明 |
@@ -75,26 +74,27 @@ module.exports = function(
75
74
  | buildClientLoadableConfig.writeToDiskFilename | '/build' | build ssr 自定义按需加载路径存储库文件存放位置 |
76
75
 
77
76
  ##### 公共配置
78
- | 参数名 | 默认值 | 说明 |
79
- |----------|------|------|
77
+ | 参数名 | 默认值 | 说明 |
78
+ |----------|---------------|------|
80
79
  | htmlPluginTemplate | '/index.html' | client端,模板html路径 |
81
- | htmlPluginFavicon | undefined | client端,favicon.ico路径,也可以通过nginx配置 |
82
- | baseStaticMediaPath | static | 静态资源图片等基础文件夹 |
83
- | baseStaticCssPath | css | 静态资源css基础文件夹 |
84
- | baseStaticJsPath | js | 静态资源js基础文件夹 |
80
+ | htmlPluginFavicon | undefined | client端,favicon.ico路径,也可以通过nginx配置 |
85
81
 
86
82
  ## 自定义
87
83
 
88
- #### 系统支持的运行参数
89
- | 参数名 | 默认值 | 说明 |
90
- |---------------------|-------------------|----------------------------------------------------------------|
91
- | --port 3031 | startDefaultPort值 | 覆盖默认端口号 `react-spa start --port 3031` |
92
- | --eslint | false | 运行时是否启动语法检查 `react-spa start --eslint`,`build`情况下该参数失效,不执行语法检查 |
84
+ #### 自定义端口
85
+
86
+ ##### react-spa 自定义方式
87
+ `react-spa start --port 3031` 或者已经在package.json.scripts中定义后(`{start: "react-spa start"}`), 将需要这样写 `npm run start -- --port 3031`
88
+
89
+ ##### react-ssr 自定义方式
90
+ 1. `react-ssr start --port 3031` 或者已经在package.json.scripts中定义后(`{start: "react-ssr start"}`), 将需要这样写 `npm run start -- --port 3031`
91
+ 1. `react-ssr server --port 3031` 或者已经在package.json.scripts中定义后(`{server: "react-ssr server"}`), 将需要这样写 `npm run server -- --port 3031`
92
+
93
93
 
94
94
  #### 自定义其他参数
95
95
  **例如:**
96
- - `react-spa start --site APW`
97
- - `react-ssr start --port 3032 --site APW`
96
+ `react-spa start --site APW`
97
+ `react-ssr start --port 3032 --site APW`
98
98
 
99
99
  该参数将解析成对象,通过get**EnvConfig()参数传递,此方式,可区分自定义的环境变量,例如:www2.0项目中site的区分。
100
100
 
@@ -26,7 +26,6 @@ const defaultConfig = {
26
26
  startDefaultPort: 3030,
27
27
  startOpenPath: '/',
28
28
  getStartEnvConfig: () => ({}),
29
- devServer: {},
30
29
 
31
30
  // hot ssr默认配置
32
31
  hotSsrDefaultPort: 9090,
@@ -43,13 +42,7 @@ const defaultConfig = {
43
42
  writeToDiskFilename: '/build'
44
43
  },
45
44
  // html模板
46
- htmlPluginTemplate: '/index.html',
47
- // 静态资源图片等基础文件夹
48
- baseStaticMediaPath: 'static',
49
- // 静态资源css基础文件夹
50
- baseStaticCssPath: 'css',
51
- // 静态资源js基础文件夹
52
- baseStaticJsPath: 'js'
45
+ htmlPluginTemplate: '/index.html'
53
46
  };
54
47
 
55
48
  module.exports = {
package/common/start.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const WebpackDevServer = require('webpack-dev-server');
2
- const { merge } = require('webpack-merge');
3
2
  const webpack = require('webpack');
4
3
  const open = require('open');
5
4
  const appConfig = require('./appConfig');
@@ -16,40 +15,37 @@ function openStartRun(webpackFactory) {
16
15
 
17
16
  const extendEnv = getEnvironmentInfo();
18
17
 
19
- const options = merge(
20
- {
21
- headers: {
22
- 'Access-Control-Allow-Origin': '*'
23
- },
24
- allowedHosts: 'all',
25
- hot: true,
26
- host: HOST,
27
- port: PORT,
28
- compress: true,
29
- historyApiFallback: {
30
- // https://github.com/facebook/create-react-app/issues/387.
31
- disableDotRule: true
32
- },
33
- client: {
34
- overlay: false,
35
- progress: false
36
- },
37
- static: {
38
- watch: {
39
- aggregateTimeout: 300,
40
- poll: 1000,
41
- ignored: /node_modules/
42
- }
43
- }
18
+ const options = {
19
+ headers: {
20
+ 'Access-Control-Allow-Origin': '*'
21
+ },
22
+ allowedHosts: 'all',
23
+ hot: true,
24
+ host: HOST,
25
+ port: PORT,
26
+ compress: true,
27
+ historyApiFallback: {
28
+ // https://github.com/facebook/create-react-app/issues/387.
29
+ disableDotRule: true
44
30
  },
45
- appConfig.devServer
46
- );
31
+ client: {
32
+ overlay: false,
33
+ progress: false
34
+ },
35
+ static: {
36
+ watch: {
37
+ aggregateTimeout: 300,
38
+ poll: 1000,
39
+ ignored: /node_modules/
40
+ }
41
+ }
42
+ };
47
43
 
48
44
  const startOpenPath = appConfig.startOpenPath ? appConfig.startOpenPath : '';
49
45
  try {
50
46
  const config = extendWebpackConfigFromProject(
51
47
  webpackFactory,
52
- { ...appConfig, startOpenPath, ...parseArgsToJson, port: PORT },
48
+ { ...appConfig, port: PORT, startOpenPath },
53
49
  extendEnv,
54
50
  { isProd: false, isServer: false, isHotServer: false }
55
51
  );
package/common/utils.js CHANGED
@@ -4,8 +4,6 @@ const fs = require('fs');
4
4
  // 执行node命令时候的文件绝对路径
5
5
  const root = process.cwd();
6
6
 
7
- const argsReg = /^--[0-9a-zA-Z]+$/;
8
-
9
7
  /**
10
8
  * 从根目录开始获取文件绝对地址路径
11
9
  * @param filePath 文件参数
@@ -17,35 +15,21 @@ function getProjectPath(...filePath) {
17
15
 
18
16
  function getParseArgsToJson() {
19
17
  const args = process.argv.slice(2);
18
+ const length = args.length - 1;
20
19
  const result = {};
21
- const length = args.length;
22
- for (let count = 0; count < args.length; count++) {
23
- if (!length || count >= length) {
24
- break;
25
- }
26
- if (!argsReg.test(args[0])) {
27
- throw Error('Run args error, example: "--port 3030" or "--eslint"');
20
+ let count = 0;
21
+ while (count <= length) {
22
+ if (!/^--[0-9a-z]+$/.test(args[count])) {
23
+ throw Error('Run args error, example: --port 3030');
28
24
  }
29
- const currentItem = args[count];
30
- if (argsReg.test(currentItem)) {
31
- const key = currentItem.substring(2);
32
- if (count + 1 >= length) {
33
- result[key] = true;
34
- break;
35
- }
36
- const nextItem = args[count + 1];
37
- if (argsReg.test(nextItem)) {
38
- result[key] = true;
39
- continue;
40
- }
41
- result[key] = isNaN(Number(nextItem))
42
- ? nextItem === 'false'
43
- ? false
44
- : nextItem === 'true'
45
- ? true
46
- : nextItem
47
- : Number(nextItem);
25
+ const key = args[count].substring(2);
26
+ count++;
27
+ if (count > length) {
28
+ result[key] = '';
29
+ break;
48
30
  }
31
+ result[key] = isNaN(Number(args[count])) ? args[count] : Number(args[count]);
32
+ count++;
49
33
  }
50
34
  return result;
51
35
  }
package/common/version.js CHANGED
@@ -8,7 +8,8 @@ function getCurrentVersion() {
8
8
  const month = date.getMonth() + 1;
9
9
  const day = date.getDate();
10
10
  const hour = date.getHours();
11
- return `${year}${getCompleteVal(month)}${getCompleteVal(day)}${getCompleteVal(hour)}`;
11
+ const minutes = date.getMinutes();
12
+ return `${year}${getCompleteVal(month)}${getCompleteVal(day)}${getCompleteVal(hour)}${getCompleteVal(minutes)}`;
12
13
  }
13
14
 
14
15
  /**
@@ -1,5 +1,6 @@
1
1
  const webpack = require('webpack');
2
2
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
+ const ESLintPlugin = require('eslint-webpack-plugin');
3
4
  const ProgressBarPlugin = require('progress-bar-webpack-plugin');
4
5
  const getCSSModuleLocalIdent = require('./getCSSModuleLocalIdent');
5
6
 
@@ -116,7 +117,7 @@ module.exports = (appConfig, extendEnv, { isProd, isServer, isHotServer }) => {
116
117
  }
117
118
  },
118
119
  generator: {
119
- filename: `${appConfig.baseStaticMediaPath}/[name].[contenthash:8].[ext]?v=${extendEnv.version}`
120
+ filename: `static/[name].[contenthash:8].[ext]?v=${extendEnv.version}`
120
121
  }
121
122
  },
122
123
  {
@@ -214,6 +215,13 @@ module.exports = (appConfig, extendEnv, { isProd, isServer, isHotServer }) => {
214
215
  },
215
216
  plugins: [
216
217
  new webpack.DefinePlugin(extendEnv.stringified),
218
+ new ESLintPlugin({
219
+ exclude: 'node_modules',
220
+ threads: 4,
221
+ failOnError: false,
222
+ lintDirtyModulesOnly: isProd,
223
+ extensions: ['tsx', 'ts', 'js']
224
+ }),
217
225
  new ProgressBarPlugin({
218
226
  // eslint-disable-next-line no-useless-concat
219
227
  format: 'build [:bar] ' + ':percent' + ' (:elapsed seconds)',
@@ -231,17 +239,6 @@ module.exports = (appConfig, extendEnv, { isProd, isServer, isHotServer }) => {
231
239
  })
232
240
  );
233
241
  }
234
- if (!isProd && appConfig.eslint) {
235
- result.plugins.push(
236
- new (require('eslint-webpack-plugin'))({
237
- exclude: 'node_modules',
238
- threads: 4,
239
- failOnError: false,
240
- lintDirtyModulesOnly: false,
241
- extensions: ['tsx', 'ts', 'js']
242
- })
243
- );
244
- }
245
242
 
246
243
  if (isProd && !isServer) {
247
244
  result.optimization = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobest-ui/scripts",
3
- "version": "1.9.4",
3
+ "version": "1.9.5",
4
4
  "private": false,
5
5
  "description": "utils for project tools",
6
6
  "bin": {
@@ -25,9 +25,7 @@
25
25
  ],
26
26
  "keywords": [
27
27
  "node",
28
- "react",
29
- "SSR",
30
- "react-script"
28
+ "express"
31
29
  ],
32
30
  "sideEffects": false,
33
31
  "browserslist": {
@@ -62,7 +60,7 @@
62
60
  "@babel/preset-react": "7.18.6",
63
61
  "@babel/preset-typescript": "7.18.6",
64
62
  "@babel/runtime": "7.20.1",
65
- "@loadable/babel-plugin": "5.15.3",
63
+ "@loadable/babel-plugin": "5.13.2",
66
64
  "@loadable/webpack-plugin": "5.15.2",
67
65
  "@soda/friendly-errors-webpack-plugin": "1.8.1",
68
66
  "babel-loader": "8.2.4",
@@ -72,7 +70,9 @@
72
70
  "cross-spawn": "7.0.3",
73
71
  "css-loader": "6.7.1",
74
72
  "css-minimizer-webpack-plugin": "3.4.1",
75
- "eslint-webpack-plugin": "3.2.0",
73
+ "eslint": "8.12.0",
74
+ "eslint-config-react-app": "7.0.0",
75
+ "eslint-webpack-plugin": "3.1.1",
76
76
  "html-webpack-plugin": "5.5.0",
77
77
  "ignore-loader": "0.1.2",
78
78
  "ip": "1.1.5",
@@ -91,16 +91,11 @@
91
91
  "sass-loader": "12.6.0",
92
92
  "style-loader": "3.3.1",
93
93
  "terser-webpack-plugin": "5.3.1",
94
- "ts-node": "10.9.1",
95
- "typescript": "4.8.3",
94
+ "ts-node": "9.1.1",
96
95
  "webpack": "5.70.0",
97
96
  "webpack-dev-server": "4.7.4",
98
97
  "webpack-merge": "5.8.0",
99
98
  "webpack-node-externals": "3.0.0"
100
99
  },
101
- "peerDependencies": {
102
- "eslint": "^8.23.1",
103
- "typescript": "4.8.3"
104
- },
105
- "gitHead": "2611548b4427c16fb03f9437ab20889615441a95"
100
+ "gitHead": "fb75bd54150164e95c075eef437badba8dcd0728"
106
101
  }
@@ -33,7 +33,7 @@ module.exports = (isProd, appConfig, extendEnv) => {
33
33
  if (isProd) {
34
34
  result.plugins.push(
35
35
  new MiniCssExtractPlugin({
36
- filename: `${appConfig.baseStaticCssPath}/[name].css?v=${extendEnv.version}`
36
+ filename: `css/[name].css?v=${extendEnv.version}`
37
37
  })
38
38
  );
39
39
  }
@@ -13,9 +13,9 @@ module.exports = function (appConfig, extendEnv) {
13
13
  publicPath: '/',
14
14
  path: getProjectPath('/build'),
15
15
  // 入口文件生产的js
16
- filename: `${appConfig.baseStaticJsPath}/[name].chunk.js?v=${extendEnv.version}`,
16
+ filename: `js/[name].chunk.js?v=${extendEnv.version}`,
17
17
  // 非入口文件生产的js
18
- chunkFilename: `${appConfig.baseStaticJsPath}/[name].chunk.js?v=${extendEnv.version}`
18
+ chunkFilename: `js/[name].chunk.js?v=${extendEnv.version}`
19
19
  },
20
20
  optimization: {
21
21
  // 在不同的编译中不变的短数字id。有益于长期缓存。在生产模式中会默认开启。
@@ -14,9 +14,7 @@ module.exports = (appConfig, extendEnv, { isServer, isHotServer, isProd }) => {
14
14
  new MiniCssExtractPlugin({
15
15
  // filename: isHotServer ? 'css/[name].css' : `css/[name].css?v=${env.version}`,
16
16
  // 采用AMP直接把css填充到html
17
- filename: isHotServer
18
- ? `${appConfig.baseStaticCssPath}/[name].css`
19
- : `${appConfig.baseStaticCssPath}/[name][contenthash:8].css`
17
+ filename: isHotServer ? 'css/[name].css' : 'css/[name][contenthash:8].css'
20
18
  })
21
19
  );
22
20
  }
@@ -23,8 +23,8 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
23
23
  // 输出文件路径
24
24
  path: getProjectPath('/devPublic'),
25
25
  publicPath: '/',
26
- filename: `${appConfig.baseStaticJsPath}/[name].js`,
27
- chunkFilename: `${appConfig.baseStaticJsPath}/[name].js`
26
+ filename: 'js/[name].js',
27
+ chunkFilename: 'js/[name].js'
28
28
  },
29
29
  plugins: [new LoadablePlugin()]
30
30
  }
@@ -19,9 +19,9 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
19
19
  path: getProjectPath('/build'),
20
20
  publicPath: '/',
21
21
  // 入口文件生产的js
22
- filename: `${appConfig.baseStaticJsPath}/[name].js?v=${extendEnv.version}`,
22
+ filename: `js/[name].js?v=${extendEnv.version}`,
23
23
  // 非入口文件生产的js
24
- chunkFilename: `${appConfig.baseStaticJsPath}/[name].js?v=${extendEnv.version}`
24
+ chunkFilename: `js/[name].js?v=${extendEnv.version}`
25
25
  },
26
26
  resolve: {
27
27
  fallback: {
@@ -78,8 +78,10 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
78
78
  },
79
79
  vendor: {
80
80
  test: /[\\/]node_modules[\\/]/,
81
- chunks: 'all',
82
- name: 'vendor'
81
+ chunks: 'initial',
82
+ name: 'vendor',
83
+ minChunks: 1,
84
+ priority: 10
83
85
  }
84
86
  }
85
87
  },
@@ -18,7 +18,7 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
18
18
  publicPath: '/',
19
19
  filename: 'server-bundle.js',
20
20
  libraryTarget: 'commonjs2',
21
- chunkFilename: `${appConfig.baseStaticJsPath}/[name].[chunkhash].js`
21
+ chunkFilename: 'js/[name].[chunkhash].js'
22
22
  },
23
23
  module: {
24
24
  rules: [