jjb-cmd 2.0.3 → 2.0.6

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.
Files changed (36) hide show
  1. package/bin/command.js +3 -2
  2. package/package.json +1 -1
  3. package/src/new/cmd.init/index.js +18 -0
  4. package/src/new/cmd.init.copy/lib/jjb.script/build.js +7 -4
  5. package/src/new/cmd.init.copy/micro-app/jjb.config.json +7 -4
  6. package/src/new/cmd.init.copy/micro-app/jjb.script/build.js +7 -4
  7. package/src/new/cmd.init.copy/micro-app/jjb.script/config.js +7 -12
  8. package/src/new/cmd.init.copy/micro-app/jjb.script/utils.js +1 -1
  9. package/src/new/cmd.init.copy/micro-app/package.json +9 -4
  10. package/src/new/cmd.init.copy/micro-app/public/index.html +18 -5
  11. package/src/new/cmd.init.copy/micro-app/src/api/home/index.js +1 -0
  12. package/src/new/cmd.init.copy/micro-app/src/enumerate/namespace/index.js +1 -1
  13. package/src/new/cmd.init.copy/micro-app/src/index.js +1 -1
  14. package/src/new/cmd.init.copy/micro-app/src/pages/index.js +6 -8
  15. package/src/new/cmd.init.copy/micro-app-ts/jjb.config.json +37 -0
  16. package/src/new/cmd.init.copy/micro-app-ts/jjb.script/build.js +11 -0
  17. package/src/new/cmd.init.copy/micro-app-ts/jjb.script/config.js +273 -0
  18. package/src/new/cmd.init.copy/micro-app-ts/jjb.script/proxy.js +19 -0
  19. package/src/new/cmd.init.copy/micro-app-ts/jjb.script/server.js +29 -0
  20. package/src/new/cmd.init.copy/micro-app-ts/jjb.script/utils.js +13 -0
  21. package/src/new/cmd.init.copy/micro-app-ts/package.json +79 -0
  22. package/src/new/cmd.init.copy/micro-app-ts/public/index.html +35 -0
  23. package/src/new/cmd.init.copy/{micro-app/src/api/main/index.js → micro-app-ts/src/api/home/index.ts} +0 -0
  24. package/src/new/cmd.init.copy/micro-app-ts/src/enumerate/namespace/index.ts +3 -0
  25. package/src/new/cmd.init.copy/micro-app-ts/src/index.ts +18 -0
  26. package/src/new/cmd.init.copy/micro-app-ts/src/pages/index.tsx +9 -0
  27. package/src/new/cmd.init.copy/micro-app-ts/src/types/global.d.ts +21 -0
  28. package/src/new/cmd.init.copy/micro-app-ts/tsconfig.json +16 -0
  29. package/src/new/cmd.init.copy/micro-app-ts/webstorm.config.js +16 -0
  30. package/src/new/cmd.init.copy/react-component/jjb.config.json +3 -3
  31. package/src/new/cmd.init.copy/react-component/jjb.script/build.js +7 -4
  32. package/src/new/cmd.init.copy/react-component/jjb.script/config.js +52 -19
  33. package/src/new/cmd.init.copy/react-component/package.json +6 -2
  34. package/src/new/cmd.init.copy/react-component/public/index.html +11 -0
  35. package/src/new/cmd.init.copy/react-component/src/index.js +6 -2
  36. package/src/new/cmd.install/index.js +15 -8
package/bin/command.js CHANGED
@@ -55,11 +55,12 @@ commander.command('init -- <templateName>').description('-- 初始化模板').ac
55
55
  if ([
56
56
  'lib',
57
57
  'react-component',
58
- 'micro-app'
58
+ 'micro-app',
59
+ 'micro-app-ts'
59
60
  ].includes(stdin)) {
60
61
  require('../src/new/cmd.init/index.js')(stdin);
61
62
  } else {
62
- console.log(`初始化失败,未能正确输入模板类型,仅支持(lib,react-component,micro-app)模板。`);
63
+ console.log(`初始化失败,未能正确输入模板类型,仅支持(lib,react-component,micro-app,micro-app-ts)模板。`);
63
64
  process.exit(0);
64
65
  }
65
66
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jjb-cmd",
3
- "version": "2.0.3",
3
+ "version": "2.0.6",
4
4
  "description": "jjb脚手架工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,6 +25,24 @@ module.exports = stdin => {
25
25
  console.log('初始化失败,文件已存在!');
26
26
  process.exit(0);
27
27
  }
28
+ } else if(stdin === 'micro-app-ts') {
29
+ if (
30
+ !fs.existsSync(`${root_path}\\jjb.script`) &&
31
+ !fs.existsSync(`${root_path}\\public`) &&
32
+ !fs.existsSync(`${root_path}\\src`) &&
33
+ !fs.existsSync(`${root_path}\\.gitignore`) &&
34
+ !fs.existsSync(`${root_path}\\jjb.config.json`) &&
35
+ !fs.existsSync(`${root_path}\\tsconfig.json`) &&
36
+ !fs.existsSync(`${root_path}\\package.json`) &&
37
+ !fs.existsSync(`${root_path}\\webstorm.config.js`)
38
+ ) {
39
+ f_file_copy(`${__dirname}\\..\\cmd.init.copy\\micro-app-ts`, root_path);
40
+ console.log('初始化完成!');
41
+ process.exit(0);
42
+ } else {
43
+ console.log('初始化失败,文件已存在!');
44
+ process.exit(0);
45
+ }
28
46
  } else if ([
29
47
  'lib',
30
48
  'react-component'
@@ -1,11 +1,14 @@
1
1
  const { hasEnvironment } = require('./utils');
2
2
 
3
- if (!hasEnvironment()) {
3
+ if ( !hasEnvironment()) {
4
4
  throw Error('jjb.script[build]: 启动build需要提供NODE_ENV变量,请确认你所运行的脚本是否正确?');
5
5
  }
6
6
 
7
- require('webpack')(require('./config')('production').webpack).run(err => {
8
- if (!err) {
9
- console.log('项目打包完成!');
7
+ require('webpack')(require('./config')('production').webpack).run(function (stat, compiler) {
8
+ if ( !compiler.compilation.errors.length) {
9
+ console.log('库文件Build完成!');
10
+ } else {
11
+ console.log('库文件Build失败,发现以下问题,请解决后重试!');
12
+ console.log(compiler.compilation.errors);
10
13
  }
11
14
  });
@@ -3,7 +3,9 @@
3
3
  "installTarget": "node_modules",
4
4
  "installResources": [
5
5
  "jjb-dva-runtime",
6
- "jjb-common-decorator"
6
+ "jjb-common-lib",
7
+ "jjb-common-decorator",
8
+ "react-admin-component"
7
9
  ],
8
10
  "environment": {
9
11
  "development": {
@@ -20,10 +22,11 @@
20
22
  }
21
23
  },
22
24
  "contextInject": {
25
+ "basename": "/"
23
26
  },
24
27
  "windowInject": {
25
28
  "title": "微应用",
26
- "jjbCommonLibUrl": "http://120.26.210.58:8089/jjb-common-lib/latest/index.js"
29
+ "jjbCommonLibUrl": "https://cdn.cqjjb.cn/jjb-common-lib/latest/index.js"
27
30
  },
28
31
  "server": {
29
32
  "port": "8080",
@@ -31,8 +34,8 @@
31
34
  },
32
35
  "framework": {
33
36
  "antd": {
34
- "link-color": "#021e43",
35
- "primary-color": "#021e43",
37
+ "link-color": "#007AFF",
38
+ "primary-color": "#007AFF",
36
39
  "border-radius-base": "2px"
37
40
  }
38
41
  }
@@ -1,11 +1,14 @@
1
1
  const { hasEnvironment } = require('./utils');
2
2
 
3
- if (!hasEnvironment()) {
3
+ if ( !hasEnvironment()) {
4
4
  throw Error('jjb.script[build]: 启动build需要提供NODE_ENV变量,请确认你所运行的脚本是否正确?');
5
5
  }
6
6
 
7
- require('webpack')(require('./config')('production').webpack).run(err => {
8
- if (!err) {
9
- console.log('项目打包完成!');
7
+ require('webpack')(require('./config')('production').webpack).run(function (stat, compiler) {
8
+ if ( !compiler.compilation.errors.length) {
9
+ console.log('项目Build完成!');
10
+ } else {
11
+ console.log('项目Build失败,发现以下问题,请解决后重试!');
12
+ console.log(compiler.compilation.errors);
10
13
  }
11
14
  });
@@ -96,7 +96,7 @@ module.exports = mode => {
96
96
  // ‘jjb-common-decorator’库
97
97
  path.resolve(__dirname, '../node_modules/jjb-common-decorator'),
98
98
  // ‘react-admin-component’库
99
- path.resolve(__dirname, '../node_modules/react-admin-component')
99
+ path.resolve(__dirname, '../node_modules/jjb-react-admin-component')
100
100
  ],
101
101
  // 配置‘babel-loader’
102
102
  options: {
@@ -131,11 +131,11 @@ module.exports = mode => {
131
131
  // 处理‘svg’文件
132
132
  test: /\.svg/,
133
133
  // 使用‘file-loader’
134
- loader: 'file-loader',
134
+ loader: 'url-loader',
135
135
  // 配置‘file-loader’
136
136
  options: {
137
- // 指定存储目录
138
- outputPath: 'media/svg'
137
+ // 转base64
138
+ limit: false
139
139
  }
140
140
  },
141
141
  {
@@ -145,13 +145,8 @@ module.exports = mode => {
145
145
  loader: 'url-loader',
146
146
  // 配置‘url-loader’
147
147
  options: {
148
- // 当文件大小处于(?)byte,输出‘base64’,反之为‘url’.
149
- // 这里设为‘false’,表示无论多大多小,都为‘url’.
150
- limit: false,
151
- // 处理引入地址‘code’编码为‘utf-8’
152
- encoding: true,
153
- // 若输出为‘url’,需要指定存储目录
154
- outputPath: 'media/image'
148
+ // base64
149
+ limit: false
155
150
  }
156
151
  }
157
152
  ]
@@ -188,7 +183,7 @@ module.exports = mode => {
188
183
  ],
189
184
  // 外部扩展
190
185
  externals: {
191
- 'jjb-common-lib': 'jjbCommonLib'
186
+ 'jjb-common-lib-types': 'jjbCommonLib'
192
187
  },
193
188
  // 打包优化
194
189
  optimization: isProduction
@@ -10,4 +10,4 @@ exports.hasEnvironment = () => process.env.NODE_ENV !== undefined;
10
10
  * @param name {string}
11
11
  * @return {`${string}\\${string}`}
12
12
  */
13
- exports.requireResolve = name => `${path.resolve(__dirname, '..')}\\${name}`;
13
+ exports.requireResolve = name => `${path.resolve(__dirname, '..')}//${name}`;
@@ -13,8 +13,7 @@
13
13
  "build:development": "cross-env NODE_ENV=development npm run build",
14
14
  "build:test": "cross-env NODE_ENV=test npm run build",
15
15
  "build:release": "cross-env NODE_ENV=release npm run build",
16
- "build:production": "cross-env NODE_ENV=production npm run build",
17
- "jjb-cmd:install": "jjb-cmd install"
16
+ "build:production": "cross-env NODE_ENV=production npm run build"
18
17
  },
19
18
  "author": "JJB",
20
19
  "license": "MIT",
@@ -46,19 +45,25 @@
46
45
  },
47
46
  "dependencies": {
48
47
  "@ant-design/icons": "^4.7.0",
48
+ "@xiwell/ant-form-validate-tools": "^1.1.8",
49
49
  "antd": "^4.23.5",
50
50
  "axios": "^1.1.2",
51
51
  "crypto-js": "^4.1.1",
52
52
  "dva": "^2.6.0-beta.22",
53
+ "echarts": "^5.4.0",
53
54
  "history": "^5.3.0",
55
+ "jjb-common-decorator": "latest",
56
+ "jjb-common-lib-types": "latest",
57
+ "jjb-dva-runtime": "latest",
58
+ "jjb-react-admin-component": "latest",
54
59
  "moment": "^2.29.4",
60
+ "object-field-resolve": "^1.0.5",
55
61
  "prop-types": "^15.8.1",
56
62
  "qiankun": "^2.8.3",
57
63
  "react": "^17.0.2",
58
64
  "react-cropper": "^2.1.8",
59
65
  "react-dom": "^17.0.2",
60
66
  "react-router-dom": "^5.2.0",
61
- "watch-props": "^0.0.3",
62
- "object-field-resolve": "^1.0.4"
67
+ "watch-props": "^0.0.3"
63
68
  }
64
69
  }
@@ -2,10 +2,18 @@
2
2
  <html lang="zh">
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
- <meta name="renderer" content="webkit">
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
5
+ <meta
6
+ name="renderer"
7
+ content="webkit"
8
+ >
9
+ <meta
10
+ http-equiv="X-UA-Compatible"
11
+ content="IE=edge,Chrome=1"
12
+ >
7
13
  <title>
8
- <%= htmlWebpackPlugin.options.title %>
14
+ <%=
15
+ htmlWebpackPlugin.options.title
16
+ %>
9
17
  </title>
10
18
  <script>
11
19
  window.__JJB_ENVIRONMENT__ = {
@@ -16,7 +24,12 @@
16
24
  <script src="<%= htmlWebpackPlugin.options.jjbCommonLibUrl %>"></script>
17
25
  </head>
18
26
  <body>
19
- <noscript>此网页需要开启JavaScript功能。</noscript>
20
- <div id="root" style="width: 100%; height: 100%; position: relative"></div>
27
+ <noscript>
28
+ 此网页需要开启JavaScript功能。
29
+ </noscript>
30
+ <div
31
+ id="root"
32
+ style="width: 100%; height: 100%; position: relative"
33
+ ></div>
21
34
  </body>
22
35
  </html>
@@ -1,3 +1,3 @@
1
1
  import { defineNamespace } from 'jjb-dva-runtime';
2
2
 
3
- export const NS_MAIN = defineNamespace('main');
3
+ export const NS_HOME = defineNamespace('home');
@@ -7,7 +7,7 @@ const app = setup();
7
7
  * @param props {object}
8
8
  * @returns {Promise<*>}
9
9
  */
10
- export const mount = async props => app.mount(props);
10
+ export const mount = async props => app.mount(props)
11
11
 
12
12
  /**
13
13
  * @description 卸载
@@ -1,11 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- export default class App extends React.Component {
4
- render () {
5
- return (
6
- <div>
7
- Hello World!
8
- </div>
9
- );
10
- }
3
+ export default function () {
4
+ return (
5
+ <div>
6
+ Hello World
7
+ </div>
8
+ );
11
9
  }
@@ -0,0 +1,37 @@
1
+ {
2
+ "projectType": "micro-spa",
3
+ "installTarget": "node_modules",
4
+ "installResources": [],
5
+ "environment": {
6
+ "development": {
7
+ "API_HOST": ""
8
+ },
9
+ "test": {
10
+ "API_HOST": ""
11
+ },
12
+ "release": {
13
+ "API_HOST": ""
14
+ },
15
+ "production": {
16
+ "API_HOST": ""
17
+ }
18
+ },
19
+ "contextInject": {
20
+ "basename": "/"
21
+ },
22
+ "windowInject": {
23
+ "title": "微应用",
24
+ "jjbCommonLibUrl": "https://cdn.cqjjb.cn/jjb-common-lib/latest/index.js"
25
+ },
26
+ "server": {
27
+ "port": "8080",
28
+ "host": "127.0.0.1"
29
+ },
30
+ "framework": {
31
+ "antd": {
32
+ "link-color": "#007AFF",
33
+ "primary-color": "#007AFF",
34
+ "border-radius-base": "2px"
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,11 @@
1
+ const { hasEnvironment } = require('./utils');
2
+
3
+ if (!hasEnvironment()) {
4
+ throw Error('jjb.script[build]: 启动build需要提供NODE_ENV变量,请确认你所运行的脚本是否正确?');
5
+ }
6
+
7
+ require('webpack')(require('./config')('production').webpack).run(err => {
8
+ if (!err) {
9
+ console.log('项目打包完成!');
10
+ }
11
+ });
@@ -0,0 +1,273 @@
1
+ // noinspection JSUnresolvedVariable
2
+
3
+ const path = require('path');
4
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
5
+ const TerserWebpackPlugin = require('terser-webpack-plugin');
6
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
+ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
8
+ const CssMinimizerWebpackPlugin = require('css-minimizer-webpack-plugin');
9
+ const { requireResolve } = require('./utils');
10
+ const webpack = require('webpack');
11
+
12
+ const config = require(requireResolve('jjb.config.json'));
13
+ const packageJSON = require(requireResolve('package.json'));
14
+ const server = (config.server || {});
15
+ const framework = (config.framework || {});
16
+ const environment = (config.environment || {})[ process.env.NODE_ENV ];
17
+ const windowInject = {
18
+ ...(config.windowInject || {}),
19
+ ...environment,
20
+ framework
21
+ };
22
+ const contextInject = (config.contextInject || {});
23
+ const contextData = {
24
+ ...environment,
25
+ ...contextInject
26
+ };
27
+
28
+ module.exports = mode => {
29
+ const isProduction = mode === 'production';
30
+ return {
31
+ server,
32
+ webpack: {
33
+ // 模式 ‘development’ | ‘production’
34
+ mode,
35
+ // 入口
36
+ entry: './src/index.ts',
37
+ // 输出
38
+ output: {
39
+ libraryTarget: 'umd',
40
+ // 指定输出目录文件名
41
+ path: path.resolve(__dirname, '../dist'),
42
+ // 定义全局变量,暴露到‘window’对象中
43
+ library: packageJSON.name,
44
+ // 指定编译的‘js’存放目录文件名称
45
+ filename: 'static/js/[id].js',
46
+ // 输出公共路径
47
+ publicPath: '/'
48
+ },
49
+ experiments: {
50
+ topLevelAwait: true
51
+ },
52
+ // ‘node.module’
53
+ module: {
54
+ // 文件处理
55
+ rules: [
56
+ {
57
+ // 处理‘less’和‘css’文件
58
+ test: /\.(less|css)$/,
59
+ // 以此从下到上处理‘css’
60
+ use: [
61
+ // 3:由‘webpack.MiniCssExtractPlugin.loader’做收尾工作
62
+ // 主要分离css文件
63
+ {
64
+ loader: MiniCssExtractPlugin.loader
65
+ },
66
+ // 2:将被‘less-loader’处理的‘css’
67
+ // 由‘css-loader’再次处理
68
+ {
69
+ loader: 'css-loader'
70
+ },
71
+ // 1:处理‘less’文件
72
+ {
73
+ // 使用‘less-loader’
74
+ loader: 'less-loader',
75
+ // 配置‘less-loader’
76
+ options: {
77
+ // ‘less-loader’特殊配置
78
+ lessOptions: {
79
+ // 定义‘less’全局变量,从jjb.config.antd获取
80
+ modifyVars: (framework || {}).antd || {},
81
+ // 启用‘less-javascript’功能
82
+ javascriptEnabled: true
83
+ }
84
+ }
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ test: /\.(ts|tsx)$/,
90
+ loader: 'ts-loader'
91
+ },
92
+ {
93
+ // 处理‘js’文件
94
+ test: /\.js$/,
95
+ // 使用‘babel-loader’
96
+ loader: 'babel-loader',
97
+ // 允许‘babel-loader’操作目录
98
+ include: [
99
+ // 整个‘src’目录
100
+ path.resolve(__dirname, '../src'),
101
+ // ‘jjb-dva-runtime’库
102
+ path.resolve(__dirname, '../node_modules/jjb-dva-runtime'),
103
+ // ‘jjb-common-decorator’库
104
+ path.resolve(__dirname, '../node_modules/jjb-common-decorator'),
105
+ // ‘react-admin-component’库
106
+ path.resolve(__dirname, '../node_modules/jjb-react-admin-component')
107
+ ],
108
+ // 配置‘babel-loader’
109
+ options: {
110
+ // 加入一个‘babel-plugin-import’插件,特殊处理‘antd’文件过大问题
111
+ plugins: [
112
+ [
113
+ 'import',
114
+ {
115
+ // ‘webpack’定义全局变量‘antd’
116
+ libraryName: 'antd',
117
+ // 按需将‘es’文件夹中组件导出,绑定到‘antd’变量
118
+ // 除了‘es’,也可以修改为‘lib’
119
+ libraryDirectory: 'es',
120
+ // 这里设为‘true’,表示自动导入‘antd/dist/less’
121
+ // 或修改为‘css’ | ‘less’
122
+ style: true
123
+ }
124
+ ],
125
+ // 扩展-装饰器语法-版本ES-Future提案中stage-0
126
+ [
127
+ '@babel/plugin-proposal-decorators',
128
+ { legacy: true }
129
+ ],
130
+ // 扩展-do表达式-版本ES-Future提案中stage-0
131
+ [
132
+ '@babel/plugin-proposal-do-expressions',
133
+ { legacy: true }
134
+ ],
135
+ // 扩展-函数入参占位符语法-版本ES-Future提案中stage-0
136
+ [
137
+ '@babel/plugin-proposal-partial-application',
138
+ { legacy: true }
139
+ ],
140
+ // 扩展-async do 语法-版本ES-Future提案中stage-0
141
+ [
142
+ '@babel/plugin-proposal-async-do-expressions',
143
+ { legacy: true }
144
+ ],
145
+ // 扩展-顶层await语法-版本ES-Future提案中stage-0
146
+ [
147
+ '@babel/plugin-syntax-top-level-await',
148
+ { legacy: true }
149
+ ],
150
+ // 扩展-assert关键字-版本ES-Future提案中stage-0
151
+ [
152
+ '@babel/plugin-syntax-import-assertions',
153
+ { legacy: true }
154
+ ],
155
+ // 扩展-管道操作符语法-版本ES-Future提案中stage-0
156
+ [
157
+ '@babel/plugin-proposal-pipeline-operator',
158
+ { proposal: 'minimal' }
159
+ ],
160
+ // 扩展-元祖语法-版本ES-Future提案中stage-0
161
+ [
162
+ '@babel/plugin-proposal-record-and-tuple',
163
+ { legacy: true }
164
+ ],
165
+ // 扩展-class static block语法-版本ES-Future提案中stage-0
166
+ [
167
+ '@babel/plugin-proposal-class-static-block',
168
+ { legacy: true }
169
+ ]
170
+ ],
171
+ // 考虑到使用‘React JSX’语法‘babel-loader’的编译预设要改为‘preset-react’
172
+ // 可选值‘preset-env’
173
+ presets: [ '@babel/preset-react' ]
174
+ }
175
+ },
176
+ {
177
+ // 处理‘svg’文件
178
+ test: /\.svg/,
179
+ // 使用‘file-loader’
180
+ loader: 'url-loader',
181
+ // 配置‘file-loader’
182
+ options: {
183
+ // 转base64
184
+ limit: false
185
+ }
186
+ },
187
+ {
188
+ // 处理图片文件
189
+ test: /\.(png|jpg|jpeg|gif|ico|bmp)/,
190
+ // 使用‘url-loader’或‘raw-loader’
191
+ loader: 'url-loader',
192
+ // 配置‘url-loader’
193
+ options: {
194
+ // 转base64
195
+ limit: false
196
+ }
197
+ }
198
+ ]
199
+ },
200
+ // 解析
201
+ resolve: {
202
+ // 为‘import’或‘require’定义别名路径
203
+ alias: {
204
+ '~': requireResolve('src')
205
+ },
206
+ // 忽略文件后缀
207
+ extensions: [
208
+ '.js',
209
+ '.jsx',
210
+ '.ts',
211
+ '.tsx',
212
+ '.json'
213
+ ]
214
+ },
215
+ // 插件
216
+ plugins: [
217
+ // 定义输出‘html’模板
218
+ // 并向‘window’全局注入变量
219
+ new HtmlWebpackPlugin(Object.assign({ template: requireResolve('public/index.html') }, windowInject)),
220
+ // 对分离的‘css’区块定义同步导入名称,和异步导入名称
221
+ new MiniCssExtractPlugin({
222
+ // 同步导入‘import | require’
223
+ filename: 'static/css/[id].css',
224
+ // 异步导入‘import | require’
225
+ chunkFilename: 'static/css/[id].css'
226
+ }),
227
+ // 注入全局变量到项目中,从‘jjb.config.contextData’读取
228
+ new webpack.DefinePlugin({ 'process.env.app': JSON.stringify(contextData) }),
229
+ // 解决‘moment.js’本地化文件过多问题
230
+ // 按需加载本地化文件当前项目只需要‘zh_CN.js’
231
+ new webpack.IgnorePlugin({
232
+ contextRegExp: /moment$/,
233
+ resourceRegExp: /^\.\/locale$/
234
+ }),
235
+ // 每次打包前删除‘dist’目录
236
+ new CleanWebpackPlugin()
237
+ ],
238
+ // 外部扩展
239
+ externals: {
240
+ 'jjb-common-lib-types': 'jjbCommonLib'
241
+ },
242
+ // 打包优化
243
+ optimization: isProduction
244
+ ? {
245
+ // 是否启用优化
246
+ minimize: true,
247
+ // 优化插件
248
+ minimizer: [
249
+ // 压缩‘javascript’代码
250
+ new TerserWebpackPlugin({ extractComments: false }),
251
+ // 压缩‘css’代码
252
+ new CssMinimizerWebpackPlugin()
253
+ ],
254
+ // 分离‘区块’
255
+ splitChunks: {
256
+ // 分离范围‘all’即所有
257
+ chunks: 'all',
258
+ // 分离大小范围0
259
+ minSize: 0,
260
+ // 分离大小范围100000
261
+ maxSize: 100000,
262
+ // 同一个区块被调用两次,需要分离
263
+ minChunks: 2,
264
+ // 最大异步请求区块
265
+ maxAsyncRequests: 6,
266
+ // 最大初始化请求区块
267
+ maxInitialRequests: 4
268
+ }
269
+ }
270
+ : {}
271
+ }
272
+ };
273
+ };
@@ -0,0 +1,19 @@
1
+ const express = require('express');
2
+ const history = require('connect-history-api-fallback');
3
+ const app = express();
4
+ const port = '8866';
5
+
6
+ /**
7
+ * 单页面应用需要的历史记录模块
8
+ */
9
+ app.use(history());
10
+
11
+ /**
12
+ * 输出静态资源
13
+ */
14
+ app.use(express.static('../dist'));
15
+
16
+ /**
17
+ * 监听端口
18
+ */
19
+ app.listen(port, () => console.log(`Your application is running here: http://localhost:${port}`));
@@ -0,0 +1,29 @@
1
+ const Server = require('webpack-dev-server');
2
+ const webpack = require('webpack');
3
+ const { hasEnvironment } = require('./utils');
4
+
5
+ if (!hasEnvironment()) {
6
+ throw Error('jjb.script[server]: 启动server需要提供NODE_ENV变量,请确认你所运行的脚本是否正确?');
7
+ }
8
+
9
+ const config = require('./config')('development');
10
+
11
+ new Server({
12
+ host: config.server.host || '127.0.0.1',
13
+ port: config.server.port || '8080',
14
+ headers: {
15
+ 'Access-Control-Allow-Origin': '*',
16
+ 'Access-Control-Allow-Methods': '*',
17
+ 'Access-Control-Allow-Headers': '*'
18
+ },
19
+ compress: true,
20
+ client: {
21
+ overlay: {
22
+ errors: true,
23
+ warnings: true
24
+ }
25
+ },
26
+ historyApiFallback: {
27
+ disableDotRule: true
28
+ }
29
+ }, webpack(config.webpack)).startCallback(() => console.log('jjb.server 服务已启动,正在编译。'));
@@ -0,0 +1,13 @@
1
+ const path = require('path');
2
+ /**
3
+ * @description 是否有环境变量‘NODE_ENV’
4
+ * @return {boolean}
5
+ */
6
+ exports.hasEnvironment = () => process.env.NODE_ENV !== undefined;
7
+
8
+ /**
9
+ * @description 文件解析
10
+ * @param name {string}
11
+ * @return {`${string}\\${string}`}
12
+ */
13
+ exports.requireResolve = name => `${path.resolve(__dirname, '..')}//${name}`;
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "micro-app",
3
+ "version": "1.0.0",
4
+ "description": "建教帮微应用模板",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "serve": "node jjb.script/server.js",
8
+ "build": "node jjb.script/build.js",
9
+ "serve:devlopment": "cross-env NODE_ENV=development npm run serve",
10
+ "serve:test": "cross-env NODE_ENV=test npm run serve",
11
+ "serve:release": "cross-env NODE_ENV=release npm run serve",
12
+ "serve:production": "cross-env NODE_ENV=production npm run serve",
13
+ "build:development": "cross-env NODE_ENV=development npm run build",
14
+ "build:test": "cross-env NODE_ENV=test npm run build",
15
+ "build:release": "cross-env NODE_ENV=release npm run build",
16
+ "build:production": "cross-env NODE_ENV=production npm run build",
17
+ "jjb-cmd:install": "jjb-cmd install"
18
+ },
19
+ "author": "JJB",
20
+ "license": "MIT",
21
+ "devDependencies": {
22
+ "@babel/core": "^7.19.3",
23
+ "@babel/plugin-proposal-async-do-expressions": "^7.18.6",
24
+ "@babel/plugin-proposal-class-static-block": "^7.20.7",
25
+ "@babel/plugin-proposal-decorators": "^7.19.3",
26
+ "@babel/plugin-proposal-do-expressions": "^7.18.6",
27
+ "@babel/plugin-proposal-partial-application": "^7.18.9",
28
+ "@babel/plugin-proposal-pipeline-operator": "^7.18.9",
29
+ "@babel/plugin-proposal-record-and-tuple": "^7.18.6",
30
+ "@babel/plugin-syntax-import-assertions": "^7.20.0",
31
+ "@babel/plugin-syntax-top-level-await": "^7.14.5",
32
+ "@babel/preset-react": "^7.18.6",
33
+ "add": "^2.0.6",
34
+ "babel-loader": "^8.2.5",
35
+ "babel-plugin-import": "^1.13.5",
36
+ "clean-webpack-plugin": "^4.0.0",
37
+ "connect-history-api-fallback": "^2.0.0",
38
+ "cross-env": "^7.0.3",
39
+ "css-loader": "^6.7.1",
40
+ "css-minimizer-webpack-plugin": "^4.2.1",
41
+ "express": "^4.18.2",
42
+ "file-loader": "^6.2.0",
43
+ "html-webpack-plugin": "^5.5.0",
44
+ "less": "^4.1.3",
45
+ "less-loader": "^11.1.0",
46
+ "mini-css-extract-plugin": "^2.6.1",
47
+ "style-loader": "^3.3.1",
48
+ "terser-webpack-plugin": "^5.3.6",
49
+ "ts-loader": "^9.4.2",
50
+ "typescript": "^4.9.4",
51
+ "uglifyjs-webpack-plugin": "^2.2.0",
52
+ "url-loader": "^4.1.1",
53
+ "webpack": "^5.74.0",
54
+ "webpack-bundle-analyzer": "^4.6.1",
55
+ "webpack-cli": "^4.10.0",
56
+ "webpack-dev-server": "^4.11.1",
57
+ "yarn": "^1.22.19"
58
+ },
59
+ "dependencies": {
60
+ "@ant-design/icons": "^4.7.0",
61
+ "antd": "^4.23.5",
62
+ "axios": "^1.1.2",
63
+ "crypto-js": "^4.1.1",
64
+ "dva": "^2.6.0-beta.22",
65
+ "history": "^5.3.0",
66
+ "jjb-common-decorator": "latest",
67
+ "jjb-common-lib-types": "latest",
68
+ "jjb-dva-runtime": "latest",
69
+ "jjb-react-admin-component": "latest",
70
+ "moment": "^2.29.4",
71
+ "object-field-resolve": "^1.0.4",
72
+ "prop-types": "^15.8.1",
73
+ "react": "^17.0.2",
74
+ "react-cropper": "^2.1.8",
75
+ "react-dom": "^17.0.2",
76
+ "react-router-dom": "^5.2.0",
77
+ "watch-props": "^0.0.3"
78
+ }
79
+ }
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta
6
+ name="renderer"
7
+ content="webkit"
8
+ >
9
+ <meta
10
+ http-equiv="X-UA-Compatible"
11
+ content="IE=edge,Chrome=1"
12
+ >
13
+ <title>
14
+ <%=
15
+ htmlWebpackPlugin.options.title
16
+ %>
17
+ </title>
18
+ <script>
19
+ window.__JJB_ENVIRONMENT__ = {
20
+ API_HOST: '<%= htmlWebpackPlugin.options.API_HOST %>',
21
+ FRAMEWORK: JSON.parse('<%= JSON.stringify(htmlWebpackPlugin.options.framework.antd) %>')
22
+ };
23
+ </script>
24
+ <script src="<%= htmlWebpackPlugin.options.jjbCommonLibUrl %>"></script>
25
+ </head>
26
+ <body>
27
+ <noscript>
28
+ 此网页需要开启JavaScript功能。
29
+ </noscript>
30
+ <div
31
+ id="root"
32
+ style="width: 100%; height: 100%; position: relative"
33
+ ></div>
34
+ </body>
35
+ </html>
@@ -0,0 +1,3 @@
1
+ import { defineNamespace } from 'jjb-dva-runtime';
2
+
3
+ export const NS_HOME = defineNamespace('home');
@@ -0,0 +1,18 @@
1
+ import { setup } from 'jjb-dva-runtime';
2
+
3
+ const app = setup();
4
+
5
+ /**
6
+ * @description 挂载
7
+ */
8
+ export const mount = async () => app.mount();
9
+
10
+ /**
11
+ * @description 卸载
12
+ */
13
+ export const unmount = async props => app.unmount(props);
14
+
15
+ /**
16
+ * @description 启动
17
+ */
18
+ export const bootstrap = async props => app.bootstrap(props);
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+
3
+ export default function (): React.ReactNode {
4
+ return (
5
+ <div>
6
+ Hello World
7
+ </div>
8
+ );
9
+ }
@@ -0,0 +1,21 @@
1
+ declare interface ModalConfig {
2
+ readonly isModify?: boolean;
3
+ readonly detail?: GenericProperty;
4
+
5
+ onOk?: () => void;
6
+
7
+ onCancel?: () => void;
8
+ }
9
+
10
+ declare type GenericProperty = { [ p: string ]: any }
11
+
12
+ declare var process: {
13
+ env: {
14
+ app: {
15
+ API_HOST: string,
16
+ basename: string;
17
+ redirectLogin: string;
18
+ },
19
+ NODE_ENV: 'production' | 'development'
20
+ }
21
+ };
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es5",
5
+ "jsx": "react",
6
+ "allowSyntheticDefaultImports": true,
7
+ "experimentalDecorators": true,
8
+ "baseUrl": "./",
9
+ "paths": {
10
+ "~/*": ["src/*"]
11
+ }
12
+ },
13
+ "exclude": [
14
+ "node_modules"
15
+ ]
16
+ }
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+
4
+ function resolve (dir) {
5
+ return path.join(__dirname, '.', dir);
6
+ }
7
+
8
+ module.exports = {
9
+ context: path.resolve(__dirname, './'),
10
+ resolve: {
11
+ extensions: [ '.js' ],
12
+ alias: {
13
+ '~': resolve('src/')
14
+ }
15
+ }
16
+ };
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "projectType": "micro-spa",
3
3
  "installTarget": "node_modules",
4
- "installResources": [],
4
+ "installResources": [
5
+ "jjb-common-lib"
6
+ ],
5
7
  "environment": {
6
8
  "development": {
7
9
  "API_HOST": ""
@@ -16,7 +18,6 @@
16
18
  "API_HOST": ""
17
19
  }
18
20
  },
19
- "contextInject": {},
20
21
  "windowInject": {},
21
22
  "server": {
22
23
  "port": "8066",
@@ -24,7 +25,6 @@
24
25
  },
25
26
  "framework": {
26
27
  "antd": {
27
- "ant-prefix": "test",
28
28
  "link-color": "red",
29
29
  "primary-color": "red",
30
30
  "border-radius-base": "2px"
@@ -1,11 +1,14 @@
1
1
  const { hasEnvironment } = require('./utils');
2
2
 
3
- if (!hasEnvironment()) {
3
+ if ( !hasEnvironment()) {
4
4
  throw Error('jjb.script[build]: 启动build需要提供NODE_ENV变量,请确认你所运行的脚本是否正确?');
5
5
  }
6
6
 
7
- require('webpack')(require('./config')('production').webpack).run(err => {
8
- if (!err) {
9
- console.log('项目打包完成!');
7
+ require('webpack')(require('./config')('production').webpack).run(function (stat, compiler) {
8
+ if ( !compiler.compilation.errors.length) {
9
+ console.log('组件Build完成!');
10
+ } else {
11
+ console.log('组件Build失败,发现以下问题,请解决后重试!');
12
+ console.log(compiler.compilation.errors);
10
13
  }
11
14
  });
@@ -1,6 +1,7 @@
1
1
  // noinspection JSUnresolvedVariable
2
2
 
3
3
  const path = require('path');
4
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
5
  const { CleanWebpackPlugin } = require('clean-webpack-plugin');
5
6
  const { requireResolve } = require('./utils');
6
7
  const webpack = require('webpack');
@@ -8,7 +9,13 @@ const webpack = require('webpack');
8
9
  const config = require(requireResolve('jjb.config.json'));
9
10
  const packageJSON = require(requireResolve('package.json'));
10
11
  const server = (config.server || {});
12
+ const framework = (config.framework || {});
11
13
  const environment = (config.environment || {})[ process.env.NODE_ENV ];
14
+ const windowInject = {
15
+ ...(config.windowInject || {}),
16
+ ...environment,
17
+ framework
18
+ };
12
19
  const contextInject = (config.contextInject || {});
13
20
  const contextData = {
14
21
  ...environment,
@@ -16,6 +23,7 @@ const contextData = {
16
23
  };
17
24
 
18
25
  module.exports = mode => {
26
+ const isProduction = mode === 'production';
19
27
  return {
20
28
  server,
21
29
  webpack: {
@@ -25,6 +33,7 @@ module.exports = mode => {
25
33
  entry: './src/index.js',
26
34
  // 输出
27
35
  output: {
36
+ libraryTarget: 'umd',
28
37
  // 指定输出目录文件名
29
38
  path: path.resolve(__dirname, '../dist'),
30
39
  // 定义全局变量,暴露到‘window’对象中
@@ -32,9 +41,7 @@ module.exports = mode => {
32
41
  // 指定编译的‘js’存放目录文件名称
33
42
  filename: 'index.js',
34
43
  // 输出公共路径
35
- publicPath: '/',
36
- // 默认暴露‘window’此处修改为暴露到‘exports’中
37
- libraryTarget: 'umd'
44
+ publicPath: '/'
38
45
  },
39
46
  // ‘node.module’
40
47
  module: {
@@ -45,9 +52,14 @@ module.exports = mode => {
45
52
  test: /\.(less|css)$/,
46
53
  // 以此从下到上处理‘css’
47
54
  use: [
55
+ // 3:由‘webpack.MiniCssExtractPlugin.loader’做收尾工作
56
+ // 主要分离css文件
48
57
  {
49
58
  loader: 'style-loader'
50
59
  },
60
+ // {
61
+ // loader: MiniCssExtractPlugin.loader
62
+ // },
51
63
  // 2:将被‘less-loader’处理的‘css’
52
64
  // 由‘css-loader’再次处理
53
65
  {
@@ -62,7 +74,7 @@ module.exports = mode => {
62
74
  // ‘less-loader’特殊配置
63
75
  lessOptions: {
64
76
  // 定义‘less’全局变量,从jjb.config.antd获取
65
- modifyVars: (config.framework || {}).antd || {},
77
+ modifyVars: (framework || {}).antd || {},
66
78
  // 启用‘less-javascript’功能
67
79
  javascriptEnabled: true
68
80
  }
@@ -78,11 +90,7 @@ module.exports = mode => {
78
90
  // 允许‘babel-loader’操作目录
79
91
  include: [
80
92
  // 整个‘src’目录
81
- path.resolve(__dirname, '../src'),
82
- // ‘jjb-common’库
83
- path.resolve(__dirname, '../node_modules/jjb-common'),
84
- // ‘jjb-react-admin-component’库
85
- path.resolve(__dirname, '../node_modules/jjb-react-admin-component')
93
+ path.resolve(__dirname, '../src')
86
94
  ],
87
95
  // 配置‘babel-loader’
88
96
  options: {
@@ -95,10 +103,10 @@ module.exports = mode => {
95
103
  libraryName: 'antd',
96
104
  // 按需将‘es’文件夹中组件导出,绑定到‘antd’变量
97
105
  // 除了‘es’,也可以修改为‘lib’
98
- libraryDirectory: 'es'
106
+ libraryDirectory: 'es',
99
107
  // 这里设为‘true’,表示自动导入‘antd/dist/less’
100
108
  // 或修改为‘css’ | ‘less’
101
- // style: true
109
+ style: true
102
110
  }
103
111
  ],
104
112
  [
@@ -113,6 +121,16 @@ module.exports = mode => {
113
121
  presets: [ '@babel/preset-react' ]
114
122
  }
115
123
  },
124
+ {
125
+ // 处理‘svg’文件
126
+ test: /\.svg/,
127
+ // 使用‘file-loader’
128
+ loader: 'url-loader',
129
+ // 配置‘file-loader’
130
+ options: {
131
+ limit: true
132
+ }
133
+ },
116
134
  {
117
135
  // 处理图片文件
118
136
  test: /\.(png|jpg|jpeg|gif|ico|bmp)/,
@@ -120,8 +138,6 @@ module.exports = mode => {
120
138
  loader: 'url-loader',
121
139
  // 配置‘url-loader’
122
140
  options: {
123
- // 当文件大小处于(?)byte,输出‘base64’,反之为‘url’.
124
- // 这里设为‘false’,表示无论多大多小,都为‘url’.
125
141
  limit: true
126
142
  }
127
143
  }
@@ -134,13 +150,20 @@ module.exports = mode => {
134
150
  '~': requireResolve('src')
135
151
  }
136
152
  },
137
- externals: {
138
- 'jjb-common-lib': 'jjbCommonLib',
139
- 'react': 'React',
140
- 'react-dom': 'ReactDOM',
141
- },
142
153
  // 插件
143
154
  plugins: [
155
+ // 定义输出‘html’模板
156
+ // 并向‘window’全局注入变量
157
+ !isProduction
158
+ ? new HtmlWebpackPlugin(Object.assign({ template: requireResolve('public/index.html') }, windowInject))
159
+ : null,
160
+ // 对分离的‘css’区块定义同步导入名称,和异步导入名称
161
+ // new MiniCssExtractPlugin({
162
+ // // 同步导入‘import | require’
163
+ // filename: 'static/css/[id].css',
164
+ // // 异步导入‘import | require’
165
+ // chunkFilename: 'static/css/[id].css'
166
+ // }),
144
167
  // 注入全局变量到项目中,从‘jjb.config.contextData’读取
145
168
  new webpack.DefinePlugin({ 'process.env.app': JSON.stringify(contextData) }),
146
169
  // 解决‘moment.js’本地化文件过多问题
@@ -151,7 +174,17 @@ module.exports = mode => {
151
174
  }),
152
175
  // 每次打包前删除‘dist’目录
153
176
  new CleanWebpackPlugin()
154
- ]
177
+ ].filter(value => !!value),
178
+ // 外部扩展
179
+ externals: {
180
+ 'jjb-common-lib': 'jjbCommonLib',
181
+ ...(isProduction
182
+ ? {
183
+ 'react': 'React',
184
+ 'react-dom': 'ReactDOM'
185
+ }
186
+ : {})
187
+ }
155
188
  }
156
189
  };
157
190
  };
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "react-component",
2
+ "name": "test-react-component",
3
3
  "version": "1.0.7",
4
4
  "description": "react组件模板",
5
5
  "main": "index.js",
@@ -28,14 +28,18 @@
28
28
  "connect-history-api-fallback": "^2.0.0",
29
29
  "cross-env": "^7.0.3",
30
30
  "css-loader": "^6.7.1",
31
+ "css-minimizer-webpack-plugin": "^4.2.2",
31
32
  "express": "^4.18.2",
32
33
  "file-loader": "^6.2.0",
34
+ "html-webpack-plugin": "^5.5.0",
33
35
  "less": "^4.1.3",
34
36
  "less-loader": "^11.1.0",
37
+ "mini-css-extract-plugin": "^2.7.0",
35
38
  "style-loader": "^3.3.1",
36
39
  "url-loader": "^4.1.1",
37
40
  "webpack": "^5.74.0",
38
- "webpack-cli": "^4.10.0"
41
+ "webpack-cli": "^4.10.0",
42
+ "webpack-dev-server": "^4.11.1"
39
43
  },
40
44
  "dependencies": {
41
45
  "@ant-design/icons": "^4.7.0",
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Title</title>
6
+ <script src="https://cdn.cqjjb.cn/jjb-common-lib/latest/index.js"></script>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ </body>
11
+ </html>
@@ -1,11 +1,15 @@
1
1
  import React from 'react';
2
+ import ReactDOM from 'react-dom';
2
3
 
3
- export class Test extends React.Component {
4
+ export default class Test extends React.Component {
4
5
  render () {
5
6
  return (
6
7
  <div>
7
- <h1>hello</h1>
8
+ Hello World
8
9
  </div>
9
10
  );
10
11
  }
11
12
  }
13
+
14
+ // TODO 打包发布请删除此段代码,此处仅在开发模式用做预览。
15
+ ReactDOM.render(<Test />, document.getElementById('root'));
@@ -201,14 +201,21 @@ module.exports = () => {
201
201
  */
202
202
  fs.mkdirSync(`${target_node_modules}\\${package_name}`);
203
203
  }
204
- /**
205
- * 文件操作:复制文件到node_modules中
206
- */
207
- f_file_copy(item.path, `${target_node_modules}\\${package_name}`);
208
- /**
209
- * 文件操作:创建package.json
210
- */
211
- f_create_package_json(`${target_node_modules}\\${package_name}`, package_name, '1.0.0');
204
+ if (package_name !== 'jjb-common-lib') {
205
+ /**
206
+ * 文件操作:复制文件到node_modules中
207
+ */
208
+ f_file_copy(item.path, `${target_node_modules}\\${package_name}`);
209
+ /**
210
+ * 文件操作:创建package.json
211
+ */
212
+ f_create_package_json(`${target_node_modules}\\${package_name}`, package_name, '1.0.0');
213
+ } else {
214
+ /**
215
+ * 文件操作:复制文件到node_modules中
216
+ */
217
+ f_file_copy(`${item.path}\\types`, `${target_node_modules}\\${package_name}`);
218
+ }
212
219
  /**
213
220
  * 文件操作:在src/package.json中定义一个组件依赖
214
221
  */