neo-cmp-cli 1.1.2 → 1.1.3
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 +1 -1
- package/src/module/main.js +23 -0
- package/src/neo/neoRequire.js +45 -0
- package/src/neo/wrapperContent.js +15 -0
- package/src/plugins/AddNeoRequirePlugin.js +47 -0
package/package.json
CHANGED
package/src/module/main.js
CHANGED
|
@@ -10,6 +10,7 @@ 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');
|
|
13
14
|
// const { MFPlugins } = require('../utils/webpack.mf');
|
|
14
15
|
|
|
15
16
|
const getValue = (originValue, defaultValue) => {
|
|
@@ -96,6 +97,17 @@ module.exports = {
|
|
|
96
97
|
}
|
|
97
98
|
*/
|
|
98
99
|
|
|
100
|
+
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
101
|
+
if (
|
|
102
|
+
curConfig.webpack &&
|
|
103
|
+
curConfig.webpack.plugins &&
|
|
104
|
+
Array.isArray(curConfig.webpack.plugins)
|
|
105
|
+
) {
|
|
106
|
+
curConfig.webpack.plugins.push(new AddNeoRequirePlugin());
|
|
107
|
+
} else {
|
|
108
|
+
curConfig.webpack.plugins = [new AddNeoRequirePlugin()];
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
akfun.dev(curConfig, consoleTag);
|
|
100
112
|
},
|
|
101
113
|
build: () => akfun.build('build', curConfig, consoleTag), // 构建脚本:生产环境
|
|
@@ -177,6 +189,17 @@ module.exports = {
|
|
|
177
189
|
}
|
|
178
190
|
*/
|
|
179
191
|
|
|
192
|
+
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
193
|
+
if (
|
|
194
|
+
curConfig.webpack &&
|
|
195
|
+
curConfig.webpack.plugins &&
|
|
196
|
+
Array.isArray(curConfig.webpack.plugins)
|
|
197
|
+
) {
|
|
198
|
+
curConfig.webpack.plugins.push(new AddNeoRequirePlugin());
|
|
199
|
+
} else {
|
|
200
|
+
curConfig.webpack.plugins = [new AddNeoRequirePlugin()];
|
|
201
|
+
}
|
|
202
|
+
|
|
180
203
|
akfun.build('lib', curConfig, consoleTag, () => {
|
|
181
204
|
// 构建完成后,执行 publish2oss
|
|
182
205
|
publish2oss(
|
|
@@ -0,0 +1,45 @@
|
|
|
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 getExternalsByNeoCommonModules = () => {
|
|
21
|
+
return Object.keys(NeoCommonModules).map(moduleName => `commonjs ${moduleName}`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// 用于添加共享的依赖模块
|
|
25
|
+
const addNeoCommonModules = (modules) => {
|
|
26
|
+
if (!window.__NeoCommonModules) {
|
|
27
|
+
window.__NeoCommonModules = {};
|
|
28
|
+
}
|
|
29
|
+
window.__NeoCommonModules = Object.assign(window.__NeoCommonModules, modules);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const initNeoRequire = () => {
|
|
33
|
+
if (!window.neoRequire) {
|
|
34
|
+
// 用于加载 Neo 共享出来的依赖模块
|
|
35
|
+
window.neoRequire = (moduleName) => {
|
|
36
|
+
return window.__NeoCommonModules[moduleName] || window[moduleName];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
initNeoRequire,
|
|
43
|
+
addNeoCommonModules,
|
|
44
|
+
getExternalsByNeoCommonModules
|
|
45
|
+
};
|
|
@@ -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;
|