neo-cmp-cli 1.0.3 → 1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -50,7 +50,8 @@
50
50
  "ora": "^4.0.4",
51
51
  "webpack-sources": "^3.2.3",
52
52
  "yargs": "^12.0.2",
53
- "lodash": "^4.17.21"
53
+ "lodash": "^4.17.21",
54
+ "external-remotes-plugin": "^1.0.0"
54
55
  },
55
56
  "devDependencies": {
56
57
  "@commitlint/cli": "^8.3.5",
@@ -8,6 +8,7 @@ const { consoleTag } = require('../utils/neoParams');
8
8
  const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
9
9
  const publish2oss = require('../oss/publish2oss');
10
10
  const getEntries = require('../utils/getEntries');
11
+ const { MFPlugins } = require('../utils/webpack.mf');
11
12
 
12
13
  const getValue = (originValue, defaultValue) => {
13
14
  return originValue !== undefined ? originValue : defaultValue;
@@ -57,6 +58,9 @@ module.exports = {
57
58
  }
58
59
  }
59
60
 
61
+ // 添加模块联邦插件
62
+ curConfig.webpack.plugins.push(...MFPlugins);
63
+
60
64
  akfun.dev(curConfig, consoleTag);
61
65
  },
62
66
  build: () => akfun.build('build', curConfig, consoleTag), // 构建脚本:生产环境
@@ -75,6 +79,11 @@ module.exports = {
75
79
  }
76
80
  }
77
81
 
82
+ if (curConfig.build2lib.enableMF) {
83
+ // 添加模块联邦插件
84
+ curConfig.webpack.plugins.push(...MFPlugins);
85
+ }
86
+
78
87
  akfun.build('lib', curConfig, consoleTag);
79
88
  }, // 构建脚本:生产环境
80
89
  publish2oss: () => {
@@ -96,6 +105,9 @@ module.exports = {
96
105
  }
97
106
  }
98
107
 
108
+ // 添加模块联邦插件
109
+ curConfig.webpack.plugins.push(...MFPlugins);
110
+
99
111
  akfun.build('lib', curConfig, consoleTag, () => {
100
112
  // 构建完成后,执行 publish2oss
101
113
  publish2oss(
@@ -107,14 +107,20 @@ const getBosClient = (ossType, ossConfig) => {
107
107
  return new baiduBOS(
108
108
  ossConfig.endpoint,
109
109
  ossConfig.bucket,
110
- ossConfig.AccessKeyId || ossConfig.AccessKeyID || ossConfig.accessKeyId || ossConfig.accessKeyID,
110
+ ossConfig.AccessKeyId ||
111
+ ossConfig.AccessKeyID ||
112
+ ossConfig.accessKeyId ||
113
+ ossConfig.accessKeyID,
111
114
  ossConfig.AccessKeySecret
112
115
  );
113
116
  } else if (ossType === 'ali') {
114
117
  return new aliBOS(
115
118
  ossConfig.endpoint,
116
119
  ossConfig.bucket,
117
- ossConfig.AccessKeyId || ossConfig.AccessKeyID || ossConfig.accessKeyId || ossConfig.accessKeyID,
120
+ ossConfig.AccessKeyId ||
121
+ ossConfig.AccessKeyID ||
122
+ ossConfig.accessKeyId ||
123
+ ossConfig.accessKeyID,
118
124
  ossConfig.AccessKeySecret
119
125
  );
120
126
  }
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
  const path = require('path');
3
+ const { ModuleFederationPlugin } = require('webpack').container;
4
+ const curDependencies = require('./package.json').dependencies;
3
5
 
4
6
  // 统一路径解析
5
7
  function resolve(dir) {
@@ -34,7 +36,28 @@ module.exports = {
34
36
  allowList: [], // ignoreNodeModules为true时生效
35
37
  projectDir: ['src'],
36
38
  // template: resolve('./public/template.html'), // 自定义html模板
37
- // plugins: []
39
+ plugins: [
40
+ new ModuleFederationPlugin({
41
+ name: 'NeoCLIDeps',
42
+ shared: [
43
+ {
44
+ react: {
45
+ requiredVersion: curDependencies.react,
46
+ singleton: true,
47
+ eager: true,
48
+ },
49
+ 'react-dom': {
50
+ requiredVersion: curDependencies['react-dom'],
51
+ singleton: true,
52
+ eager: true,
53
+ },
54
+ },
55
+ ],
56
+ }),
57
+ ],
58
+ babelPlugins: [
59
+ ['import', { libraryName: 'antd', style: 'css' }], // babel-plugin-import: antd 的按需加载
60
+ ],
38
61
  },
39
62
  preview: {
40
63
  // 用于开启本地预览模式的相关配置信息
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "neo-register": "^1.0.0",
41
- "antd": "^4.9.4",
41
+ "antd": "4.9.4",
42
42
  "react": "^16.9.0",
43
43
  "react-dom": "^16.9.0"
44
44
  },
@@ -47,7 +47,7 @@
47
47
  "@commitlint/config-conventional": "^9.1.1",
48
48
  "@types/react": "^16.9.11",
49
49
  "@types/react-dom": "^16.9.15",
50
- "neo-cmp-cli": "^1.0.3",
50
+ "neo-cmp-cli": "^1.0.5",
51
51
  "husky": "^4.2.5",
52
52
  "lint-staged": "^10.2.9",
53
53
  "prettier": "^2.0.5"
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- // import { Avatar } from 'antd';
2
+ import { Avatar } from 'antd';
3
+ import { UserOutlined } from '@ant-design/icons';
3
4
  import './style.scss'; // 组件内容样式
4
5
 
5
6
  interface InfoCardProps {
@@ -42,6 +43,7 @@ export default class InfoCard extends React.PureComponent<InfoCardProps> {
42
43
  {title ||
43
44
  '营销服全场景智能CRM,帮助企业搭建数字化客户经营平台,实现业绩高质量增长。'}
44
45
  {systemInfo.tenantName ? `【${systemInfo.tenantName}】` : ''}
46
+ <Avatar size={64} icon={<UserOutlined />} />
45
47
  </div>
46
48
  <div className="item-imgbox">
47
49
  {userInfo && userInfo.icon && (
@@ -1,24 +1,24 @@
1
1
  <template>
2
2
  <div class="info-card-container">
3
- <div class="news-title">
4
- {{ title }}
5
- </div>
6
- <div class="item-imgbox">
7
- <div
8
- class="news-img"
9
- :style="{ backgroundImage: 'url(' + backgroundImage + ')' }"
10
- ></div>
11
- <div v-if="img_count > 0" class="img-count">
12
- {{ img_count }}
13
- </div>
3
+ <div class="news-title">
4
+ {{ title }}
5
+ </div>
6
+ <div class="item-imgbox">
7
+ <div
8
+ class="news-img"
9
+ :style="{ backgroundImage: 'url(' + backgroundImage + ')' }"
10
+ ></div>
11
+ <div v-if="img_count > 0" class="img-count">
12
+ {{ img_count }}
14
13
  </div>
15
- <div class="news-info">
16
- <div class="left media-mark">NeoCRM · 低代码平台@Vue2.0组件</div>
17
- <div v-if="comment_count && comment_count != 0" class="cmt-num right">
18
- {{ agreeDataFormat(comment_count) }}评
19
- </div>
14
+ </div>
15
+ <div class="news-info">
16
+ <div class="left media-mark">NeoCRM · 低代码平台@Vue2.0组件</div>
17
+ <div v-if="comment_count && comment_count != 0" class="cmt-num right">
18
+ {{ agreeDataFormat(comment_count) }}评
20
19
  </div>
21
20
  </div>
21
+ </div>
22
22
  </template>
23
23
  <script>
24
24
  // 按需引入element-ui中的组件
@@ -0,0 +1,59 @@
1
+ // 模块联邦插件
2
+ const webpack = require('webpack');
3
+ const { ModuleFederationPlugin } = require('webpack').container;
4
+
5
+ // 解析 webpack 模块联邦 remotes 中的变量
6
+ const ExternalTemplateRemotesPlugin = require('external-remotes-plugin');
7
+
8
+ const { catchCurPackageJson } = require('../utils/pathUtils');
9
+ const getConfigObj = require('../utils/getConfigObj');
10
+
11
+ // 获取当前项目的package文件
12
+ const currentPackageJsonDir = catchCurPackageJson();
13
+ const currentPackageJson = getConfigObj(currentPackageJsonDir);
14
+
15
+ /**
16
+ * Neo 提供的可共享依赖
17
+ * 说明:用于剔除掉自定义组件中的重复依赖,避免重复打包,减少包体积
18
+ */
19
+ const neoSharedDeps = {
20
+ antd: '4.9.4',
21
+ 'antd-mobile': '2.3.4',
22
+ '@ant-design/icons': '^4.8.0',
23
+ axios: '^0.27.2',
24
+ 'angular-expressions': '^1.1.4',
25
+ echarts: '5.4.2',
26
+ mobx: '^6.3.0',
27
+ 'mobx-react': '^7.0.0',
28
+ 'mobx-state-tree': '^5.4.0',
29
+ moment: '^2.25.3',
30
+ lodash: '^4.17.21',
31
+ 'react-dnd': '^11.1.3',
32
+ classnames: '^2.3.2'
33
+ };
34
+
35
+ const MFPlugins = [
36
+ new ModuleFederationPlugin({
37
+ name: currentPackageJson.name,
38
+ remotes: {
39
+ // 通过 external-remotes-plugin 支持变量写法
40
+ neobase: 'neobase@[window.neoEntrys.neobase]',
41
+ neoreact: 'neoreact@[window.neoEntrys.neoreact]'
42
+ }
43
+ }),
44
+ new ExternalTemplateRemotesPlugin(),
45
+ new webpack.NormalModuleReplacementPlugin(/(.*)/, (resource) => {
46
+ if (['react', 'react-dom'].indexOf(resource.request) > -1) {
47
+ // 使用 Neo 提供的 react 和 react-dom
48
+ resource.request = `neoreact/${resource.request}`;
49
+ } else if (neoSharedDeps[resource.request]) {
50
+ // 使用 Neo 提供的其他依赖
51
+ const mfKey = resource.request.replace(/(\/|\.)/gi, '_'); // 换成 neo-ui-mf-base exposes 的 key
52
+ resource.request = `neobase/${mfKey}`;
53
+ }
54
+ })
55
+ ];
56
+
57
+ module.exports = {
58
+ MFPlugins
59
+ };