@autobest-ui/scripts 3.0.0-alpha.0 → 3.0.0-alpha.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/README.md CHANGED
@@ -1,135 +1,4 @@
1
1
  # @autobest-ui/scripts
2
2
 
3
- ## 介绍
4
- 集成react项目在webpack下debug、build, 统一命令,方便维护与升级。
5
-
6
3
  ## 安装
7
- `npm install @autobest-ui/scripts --save-dev`
8
-
9
- ## 使用方式
10
-
11
- #### 单页面应用(SPA)
12
- 1. 本地 hot debug: `react-spa start`
13
-
14
- 2. build: `react-spa build`
15
-
16
- #### 服务端渲染应用(SSR)
17
- 1. 本地 client hot debug: `react-ssr start`
18
-
19
- 2. 本地 server hot debug: `react-ssr server`
20
-
21
- 3. build: `react-ssr build`
22
-
23
- ## 配置文件
24
- 根目录下创建`config`文件夹
25
-
26
- ```
27
- config
28
- app.config.js // 为命令提供的私有配置
29
- app.webpack.js // 扩展webpack配置, 非必须选
30
- env.js // 项目私有配置(比如: API BaseUrl配置),这个名字可以自定义
31
- ```
32
-
33
- #### app.webpack.js 介绍
34
-
35
- 该文件用于webpack扩展, 非必写。写法如下:
36
-
37
- ```
38
- module.exports = function(
39
- result,
40
- appConfig,
41
- extendEnv,
42
- { isProd, isServer, isHotServer }
43
- ) {
44
- // 根据条件,对不同环境的配置进行扩展
45
- ......
46
- // 最终返回扩展后的结果
47
- return result;
48
- }
49
- ```
50
-
51
- #### app.config.js 介绍
52
-
53
- ##### start 配置参数说明(作用于`react-spa start` 或者 `react-ssr start`)
54
- | 参数名 | 默认值 | 说明 |
55
- | ---- |------|-----------------------------------|
56
- | startDefaultPort | 3030 | start默认端口号, 可自定义,下面介绍 |
57
- | startOpenPath | '/' | start 打开浏览器的路径 |
58
- | getStartEnvConfig | {} | start 自定义环境变量的方法,会追加到process.env中 |
59
- | devServer | {} | start 自定义devServer配置 |
60
-
61
- ##### hot ssr 配置参数说明(作用于`react-ssr ssr`)
62
- | 参数名 | 默认值 | 说明 |
63
- | ---- |--------------------------------| ---- |
64
- | hotSsrDefaultPort | 9090 | hot ssr默认端口号, 可自定义,下面介绍 |
65
- | hotSsrOpenPath | '/' | hot ssr 打开浏览器的路径 |
66
- | hotSsrRunPath | 'server/app.ts' | hot ssr 执行nodejs 入口文件路径 |
67
- | hotSsrWatch |['devPublic', 'devBuild', 'server']| hot ssr 需要watch的文件夹,类型: Array |
68
- | getHotSsrEnvConfig | {} | hot ssr 自定义环境变量的方法,会追加到process.env中 |
69
-
70
- ##### build ssr 配置参数说明(作用于`react-ssr build`)
71
- | 参数名 | 默认值 | 说明 |
72
- | ---- |-----------------------| ---- |
73
- | getBuildEnvConfig | {} | build ssr 自定义环境变量的方法,会追加到process.env中 |
74
- | buildClientLoadableConfig.filename | 'loadable-stats.json' | build ssr 自定义按需加载路径存储库文件名 |
75
- | buildClientLoadableConfig.writeToDiskFilename | '/build' | build ssr 自定义按需加载路径存储库文件存放位置 |
76
-
77
- ##### 公共配置
78
- | 参数名 | 默认值 | 说明 |
79
- |----------|------|------|
80
- | htmlPluginTemplate | '/index.html' | client端,模板html路径 |
81
- | htmlPluginFavicon | undefined | client端,favicon.ico路径,也可以通过nginx配置 |
82
- | baseStaticMediaPath | static | 静态资源图片等基础文件夹 |
83
- | baseStaticCssPath | css | 静态资源css基础文件夹 |
84
- | baseStaticJsPath | js | 静态资源js基础文件夹 |
85
-
86
- ## 自定义
87
-
88
- #### 系统支持的运行参数
89
- | 参数名 | 默认值 | 说明 |
90
- |---------------------|-------------------|----------------------------------------------------------------|
91
- | --port 3031 | startDefaultPort值 | 覆盖默认端口号 `react-spa start --port 3031` |
92
- | --eslint | false | 运行时是否启动语法检查 `react-spa start --eslint`,`build`情况下该参数失效,不执行语法检查 |
93
-
94
- #### 自定义其他参数
95
- **例如:**
96
- - `react-spa start --site APW`
97
- - `react-ssr start --port 3032 --site APW`
98
-
99
- 该参数将解析成对象,通过get**EnvConfig()参数传递,此方式,可区分自定义的环境变量,例如:www2.0项目中site的区分。
100
-
101
-
102
- ### 自定义环境变量
103
- 该方式,主要应用于启动程序前,自定义环境变量,主要用于get**EnvConfig()方法的多样性。
104
-
105
- 例如: `cross-env REACT_APP_ENV=local react-ssr start`
106
-
107
- #### 背景图片问题
108
- 推荐把静态资源放到静态库,并使用sass环境变量`$env`进行本地调试,若想使用本地文件,需特殊处理。
109
-
110
- - scss环境变量
111
- ```scss
112
- // 其中 $env = process.env.NODE_ENV, 满足background-image链接不全、区分本地与线上样式等需求。
113
- if($env == 'development','为true的样式', ‘为false的样式’)
114
- // 例子
115
- $AssetBaseUrl: 'https://assets-web.dev.autobestdevops.com';
116
- $AssetCommonPath: '/common-uiasset';
117
- $AssetWwwPath: '/www-uiasset';
118
-
119
- @mixin getBgImgFromCommon($url) {
120
- background-image: if($env == 'development', url($AssetBaseUrl + $AssetCommonPath + $url), url($AssetCommonPath + $url));
121
- }
122
-
123
- @mixin getBgImgFromWww($url) {
124
- background-image: if($env == 'development', url($AssetBaseUrl + $AssetWwwPath + $url), url($AssetWwwPath + $url));
125
- }
126
- ```
127
-
128
- - 使用本地文件注意事项
129
- ```scss
130
- // background image 不解析以"http、https"开头或者/common-uiasset/|/wwwasset/|/onlineasset/开头的静态资源, 例如:'/common-uiasset/img.png'
131
- // 所以本地静态资源需要特别注意,不能创建/common-uiasset/|/wwwasset/|/onlineasset/文件夹
132
- .live-chat {
133
- background: url('imgs/图片名.resolving.png') 0 center no-repeat;
134
- }
135
- ```
4
+ `npm install @autobest-ui/scripts --save-dev`
@@ -28,11 +28,20 @@ const defaultConfig = {
28
28
  getStartEnvConfig: () => ({}),
29
29
  devServer: {},
30
30
 
31
+ clientEntryAtSpa: '/src/index.tsx',
32
+ clientOutputPathAtSpa: '/build',
33
+
34
+ clientEntryAtSsr: '/src/client-entry.tsx',
35
+ clientOutputPathAtSsr: '/build',
36
+
37
+ serverEntryAtSsr: '/server/index.ts',
38
+ serverOutputPathAtSsr: '/dist',
39
+
31
40
  // hot ssr默认配置
32
41
  hotSsrDefaultPort: 9090,
33
42
  hotSsrOpenPath: '/',
34
- hotSsrRunPath: 'server/app.ts',
35
- hotSsrWatch: ['devPublic', 'devBuild', 'server'],
43
+ hotSsrRunPath: '/dist/index.js',
44
+ hotSsrWatch: ['build', 'dist'],
36
45
  getHotSsrEnvConfig: () => ({}),
37
46
 
38
47
  // build默认配置
@@ -213,7 +213,6 @@ module.exports = (appConfig, extendEnv, { isProd, isServer, isHotServer }) => {
213
213
  extensions: ['.tsx', '.ts', '.js', 'scss', 'css']
214
214
  },
215
215
  plugins: [
216
- new webpack.DefinePlugin(extendEnv.stringified),
217
216
  new ProgressBarPlugin({
218
217
  // eslint-disable-next-line no-useless-concat
219
218
  format: 'build [:bar] ' + ':percent' + ' (:elapsed seconds)',
@@ -243,6 +242,10 @@ module.exports = (appConfig, extendEnv, { isProd, isServer, isHotServer }) => {
243
242
  );
244
243
  }
245
244
 
245
+ if (!isServer) {
246
+ result.plugins.push(new webpack.DefinePlugin(extendEnv.stringified));
247
+ }
248
+
246
249
  if (isProd && !isServer) {
247
250
  result.optimization = {
248
251
  chunkIds: 'named',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobest-ui/scripts",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "private": false,
5
5
  "description": "utils for project tools",
6
6
  "bin": {
@@ -98,9 +98,5 @@
98
98
  "webpack-merge": "5.8.0",
99
99
  "webpack-node-externals": "3.0.0"
100
100
  },
101
- "peerDependencies": {
102
- "eslint": "^8.23.1",
103
- "typescript": "4.8.3"
104
- },
105
101
  "gitHead": "fb75bd54150164e95c075eef437badba8dcd0728"
106
102
  }
@@ -8,10 +8,10 @@ const HOST = process.env.HOST || ip.address() || 'localhost';
8
8
 
9
9
  module.exports = function (appConfig, extendEnv) {
10
10
  return merge(baseConfig(false, appConfig, extendEnv), {
11
- entry: getProjectPath('/src/index.tsx'),
11
+ entry: getProjectPath(appConfig.clientEntryAtSpa),
12
12
  output: {
13
13
  publicPath: '/',
14
- path: getProjectPath('/dist'),
14
+ path: getProjectPath(appConfig.clientOutputPathAtSpa),
15
15
  pathinfo: true,
16
16
  filename: '[name].js',
17
17
  chunkFilename: '[name].chunk.js'
@@ -7,11 +7,11 @@ const baseConfig = require('./webpack.base');
7
7
  module.exports = function (appConfig, extendEnv) {
8
8
  const result = merge(baseConfig(true, appConfig, extendEnv), {
9
9
  // 打包的入口文件
10
- entry: getProjectPath('/src/index.tsx'),
10
+ entry: getProjectPath(appConfig.clientEntryAtSpa),
11
11
  // 打包的出口
12
12
  output: {
13
13
  publicPath: '/',
14
- path: getProjectPath('/build'),
14
+ path: getProjectPath(appConfig.clientOutputPathAtSpa),
15
15
  // 入口文件生产的js
16
16
  filename: `${appConfig.baseStaticJsPath}/[name].chunk.js?v=${extendEnv.version}`,
17
17
  // 非入口文件生产的js
@@ -12,7 +12,7 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
12
12
  }),
13
13
  {
14
14
  // 入口文件
15
- entry: getProjectPath('/src/client-entry.tsx'),
15
+ entry: getProjectPath(appConfig.clientEntryAtSsr),
16
16
  resolve: {
17
17
  fallback: {
18
18
  fs: false
@@ -21,7 +21,7 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
21
21
  // 输出信息
22
22
  output: {
23
23
  // 输出文件路径
24
- path: getProjectPath('/devPublic'),
24
+ path: getProjectPath(appConfig.clientOutputPathAtSsr),
25
25
  publicPath: '/',
26
26
  filename: `${appConfig.baseStaticJsPath}/[name].js`,
27
27
  chunkFilename: `${appConfig.baseStaticJsPath}/[name].js`
@@ -15,10 +15,10 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
15
15
  isProd
16
16
  }),
17
17
  {
18
- entry: getProjectPath('/src/index.tsx'),
18
+ entry: getProjectPath(appConfig.clientEntryAtSpa),
19
19
  output: {
20
20
  publicPath: '/',
21
- path: getProjectPath('/dist'),
21
+ path: getProjectPath(appConfig.clientOutputPathAtSpa),
22
22
  pathinfo: true,
23
23
  filename: '[name].js',
24
24
  chunkFilename: '[name].chunk.js'
@@ -20,13 +20,13 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
20
20
  allowlist: /\.(js|css|less|scss|png|jpg|jpeg)$/
21
21
  }),
22
22
  // 入口文件
23
- entry: getProjectPath('/src/serverEntry/index.tsx'),
23
+ entry: getProjectPath(appConfig.serverEntryAtSsr),
24
24
  // 输出信息
25
25
  output: {
26
- path: getProjectPath('/devBuild'),
26
+ entry: getProjectPath(appConfig.serverOutputPathAtSsr),
27
27
  publicPath: '/',
28
28
  // 输出文件名
29
- filename: 'bundle.js',
29
+ filename: 'index.js',
30
30
  libraryTarget: 'commonjs2'
31
31
  },
32
32
  module: {
@@ -13,10 +13,10 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
13
13
  isProd
14
14
  }),
15
15
  {
16
- entry: getProjectPath('/src/client-entry.tsx'),
16
+ entry: getProjectPath(appConfig.clientEntryAtSsr),
17
17
  // 打包的出口
18
18
  output: {
19
- path: getProjectPath('/build'),
19
+ path: getProjectPath(appConfig.clientOutputPathAtSsr),
20
20
  publicPath: '/',
21
21
  // 入口文件生产的js
22
22
  filename: `${appConfig.baseStaticJsPath}/[name].js?v=${extendEnv.version}`,
@@ -1,4 +1,3 @@
1
- const nodeExternals = require('webpack-node-externals');
2
1
  const { merge } = require('webpack-merge');
3
2
  const { getProjectPath, deleteFolders } = require('../common/utils');
4
3
  const baseConfig = require('./webpack.base');
@@ -12,11 +11,11 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
12
11
  }),
13
12
  {
14
13
  target: 'node',
15
- entry: getProjectPath('/src/serverEntry/index.tsx'),
14
+ entry: getProjectPath(appConfig.serverEntryAtSsr),
16
15
  output: {
17
- path: getProjectPath('/build'),
16
+ entry: getProjectPath(appConfig.serverOutputPathAtSsr),
18
17
  publicPath: '/',
19
- filename: 'server-bundle.js',
18
+ filename: 'index.js',
20
19
  libraryTarget: 'commonjs2',
21
20
  chunkFilename: `${appConfig.baseStaticJsPath}/[name].[chunkhash].js`
22
21
  },
@@ -35,12 +34,7 @@ module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd
35
34
  ]
36
35
  }
37
36
  ]
38
- },
39
- // 服务端打包的时候忽略外部的npm包
40
- externals: nodeExternals({
41
- // 当然外部的css还是可以打进来的
42
- allowlist: /\.(css|less|scss)$/
43
- })
37
+ }
44
38
  }
45
39
  );
46
40