neo-cmp-cli 1.1.2 → 1.1.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/package.json
CHANGED
package/src/module/main.js
CHANGED
|
@@ -10,6 +10,8 @@ const publish2oss = require('../oss/publish2oss');
|
|
|
10
10
|
const getEntries = require('../cmpUtils/getEntries');
|
|
11
11
|
const getEntriesWithAutoRegister = require('../cmpUtils/getEntriesWithAutoRegister');
|
|
12
12
|
const previewCmp = require('./previewCmp');
|
|
13
|
+
const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
|
|
14
|
+
const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
|
|
13
15
|
// const { MFPlugins } = require('../utils/webpack.mf');
|
|
14
16
|
|
|
15
17
|
const getValue = (originValue, defaultValue) => {
|
|
@@ -96,6 +98,28 @@ module.exports = {
|
|
|
96
98
|
}
|
|
97
99
|
*/
|
|
98
100
|
|
|
101
|
+
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
102
|
+
if (
|
|
103
|
+
curConfig.webpack &&
|
|
104
|
+
curConfig.webpack.plugins &&
|
|
105
|
+
Array.isArray(curConfig.webpack.plugins)
|
|
106
|
+
) {
|
|
107
|
+
curConfig.webpack.plugins.push(new AddNeoRequirePlugin());
|
|
108
|
+
} else {
|
|
109
|
+
curConfig.webpack.plugins = [new AddNeoRequirePlugin()];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 添加 externals 配置
|
|
113
|
+
const neoExternals = getExternalsByNeoCommonModules();
|
|
114
|
+
if (
|
|
115
|
+
curConfig.dev.externals &&
|
|
116
|
+
Array.isArray(curConfig.dev.externals)
|
|
117
|
+
) {
|
|
118
|
+
curConfig.dev.externals.push(...neoExternals);
|
|
119
|
+
} else {
|
|
120
|
+
curConfig.dev.externals = neoExternals;
|
|
121
|
+
}
|
|
122
|
+
|
|
99
123
|
akfun.dev(curConfig, consoleTag);
|
|
100
124
|
},
|
|
101
125
|
build: () => akfun.build('build', curConfig, consoleTag), // 构建脚本:生产环境
|
|
@@ -177,6 +201,28 @@ module.exports = {
|
|
|
177
201
|
}
|
|
178
202
|
*/
|
|
179
203
|
|
|
204
|
+
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
205
|
+
if (
|
|
206
|
+
curConfig.webpack &&
|
|
207
|
+
curConfig.webpack.plugins &&
|
|
208
|
+
Array.isArray(curConfig.webpack.plugins)
|
|
209
|
+
) {
|
|
210
|
+
curConfig.webpack.plugins.push(new AddNeoRequirePlugin());
|
|
211
|
+
} else {
|
|
212
|
+
curConfig.webpack.plugins = [new AddNeoRequirePlugin()];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 添加 externals 配置
|
|
216
|
+
const neoExternals = getExternalsByNeoCommonModules();
|
|
217
|
+
if (
|
|
218
|
+
curConfig.build2lib.externals &&
|
|
219
|
+
Array.isArray(curConfig.build2lib.externals)
|
|
220
|
+
) {
|
|
221
|
+
curConfig.build2lib.externals.push(...neoExternals);
|
|
222
|
+
} else {
|
|
223
|
+
curConfig.build2lib.externals = neoExternals;
|
|
224
|
+
}
|
|
225
|
+
|
|
180
226
|
akfun.build('lib', curConfig, consoleTag, () => {
|
|
181
227
|
// 构建完成后,执行 publish2oss
|
|
182
228
|
publish2oss(
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Neo 共享出来的依赖模块
|
|
2
|
+
const NeoCommonModules = {
|
|
3
|
+
react: '^16.13.1',
|
|
4
|
+
'react-dom': '^16.13.1',
|
|
5
|
+
mobx: '^6.3.0',
|
|
6
|
+
'mobx-react': '^7.0.0',
|
|
7
|
+
'mobx-state-tree': '^5.4.0',
|
|
8
|
+
echarts: '5.4.2',
|
|
9
|
+
antd: '4.9.4',
|
|
10
|
+
'antd-mobile': '2.3.4',
|
|
11
|
+
'@ant-design/icons': '^4.8.0',
|
|
12
|
+
'video-react': '0.14.1',
|
|
13
|
+
axios: '^0.27.2',
|
|
14
|
+
classnames: '^2.3.2',
|
|
15
|
+
qs: '^6.11.0',
|
|
16
|
+
lodash: '^4.17.21'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// 根据 Neo 共享出来的依赖模块,获取 externals 配置
|
|
20
|
+
const getExternalsByNeoCommonModulesV1 = () => {
|
|
21
|
+
const neoExternals = {};
|
|
22
|
+
Object.keys(NeoCommonModules).forEach(moduleName => {
|
|
23
|
+
neoExternals[moduleName] = `commonjs ${moduleName}`;
|
|
24
|
+
});
|
|
25
|
+
return neoExternals;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getExternalsByNeoCommonModules = () => {
|
|
29
|
+
return Object.keys(NeoCommonModules).map(moduleName => `commonjs ${moduleName}`);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// 用于添加共享的依赖模块
|
|
33
|
+
const addNeoCommonModules = (modules) => {
|
|
34
|
+
if (!window.__NeoCommonModules) {
|
|
35
|
+
window.__NeoCommonModules = {};
|
|
36
|
+
}
|
|
37
|
+
window.__NeoCommonModules = Object.assign(window.__NeoCommonModules, modules);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const initNeoRequire = () => {
|
|
41
|
+
if (!window.neoRequire) {
|
|
42
|
+
// 用于加载 Neo 共享出来的依赖模块
|
|
43
|
+
window.neoRequire = (moduleName) => {
|
|
44
|
+
return window.__NeoCommonModules[moduleName] || window[moduleName];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
initNeoRequire,
|
|
51
|
+
addNeoCommonModules,
|
|
52
|
+
getExternalsByNeoCommonModules
|
|
53
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 注入 neoRequire 函数
|
|
3
|
+
* 备注:用于实现和 Neo 平台共享依赖
|
|
4
|
+
*/
|
|
5
|
+
(function(cmpFileFactory) {
|
|
6
|
+
if (!window.neoRequire) {
|
|
7
|
+
throw new Error('neoRequire 不存在,请在 NeoCRM 平台中加载此脚本。');
|
|
8
|
+
}
|
|
9
|
+
cmpFileFactory(window.neoRequire);
|
|
10
|
+
})(function(require) {
|
|
11
|
+
/**
|
|
12
|
+
* 这里放自定义组件相关内容代码
|
|
13
|
+
* 备注: 自定义组件代码中的 require 函数 已被替换成 neoRequire 函数(require === neoRequire)。
|
|
14
|
+
*/
|
|
15
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { ConcatSource } = require('webpack-sources');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 注入 neoRequire 函数
|
|
5
|
+
* 备注:用于实现和 Neo 平台共享依赖
|
|
6
|
+
*/
|
|
7
|
+
class AddNeoRequirePlugin {
|
|
8
|
+
apply(compiler) {
|
|
9
|
+
compiler.hooks.compilation.tap('AddNeoRequirePlugin', (compilation) => {
|
|
10
|
+
compilation.hooks.processAssets.tap(
|
|
11
|
+
{
|
|
12
|
+
name: 'AddNeoRequirePlugin',
|
|
13
|
+
stage: -100
|
|
14
|
+
},
|
|
15
|
+
() => {
|
|
16
|
+
for (const chunk of compilation.chunks) {
|
|
17
|
+
if (!chunk.canBeInitial() || !chunk.rendered) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (const file of chunk.files) {
|
|
22
|
+
if (/.css$/.test(file)) {
|
|
23
|
+
// 不处理 css 文件
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Header = `
|
|
28
|
+
(function(cmpFileFactory) {
|
|
29
|
+
if (!window.neoRequire) {
|
|
30
|
+
throw new Error('neoRequire 不存在,请在 NeoCRM 平台中加载此脚本。');
|
|
31
|
+
}
|
|
32
|
+
cmpFileFactory(window.neoRequire);
|
|
33
|
+
})(function(require) {
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const Footer = `})`;
|
|
37
|
+
|
|
38
|
+
compilation.updateAsset(file, (oldFileContent) => new ConcatSource(Header, oldFileContent, Footer));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = AddNeoRequirePlugin;
|