@moneko/core 3.0.0-beta.31 → 3.0.0-beta.32
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/lib/common.js +175 -2
- package/lib/coverage.js +30 -1
- package/lib/done.js +12 -1
- package/lib/envFlags.js +48 -1
- package/lib/esm.js +7 -1
- package/lib/has-pkg.js +14 -1
- package/lib/html-add-entry-attr.js +22 -1
- package/lib/html-plugin-option.js +41 -1
- package/lib/index.js +4 -1
- package/lib/minify.js +46 -1
- package/lib/modifyVars.js +11 -1
- package/lib/module-federation.js +46 -1
- package/lib/module.config.js +184 -1
- package/lib/process-env.js +63 -1
- package/lib/resolver-sync.js +21 -1
- package/lib/routes.js +171 -1
- package/lib/seo.js +57 -1
- package/lib/swcrc.js +107 -1
- package/lib/tsloader.config.js +25 -1
- package/lib/utils.js +64 -1
- package/lib/webpack.common.js +218 -1
- package/lib/webpack.dev.js +97 -3
- package/lib/webpack.prod.js +64 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +2 -2
package/lib/common.js
CHANGED
|
@@ -1,4 +1,169 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import readline from 'readline';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { merge } from 'webpack-merge';
|
|
6
|
+
import { APPTYPE, CUSTOMCONFIG, FRAMEWORK, jsxImportSource, pkgName, PROGRAMPATH } from './process-env.js';
|
|
7
|
+
import { isFunction, readConf } from './utils.js';
|
|
8
|
+
export const ENTRYPATH = {
|
|
9
|
+
mobile: 'mobile',
|
|
10
|
+
site: 'site',
|
|
11
|
+
'back-stage': 'back-stage',
|
|
12
|
+
'single-spa': 'single-spa',
|
|
13
|
+
library: 'library',
|
|
14
|
+
'single-component': 'single-component'
|
|
15
|
+
};
|
|
16
|
+
const includeModule = [
|
|
17
|
+
`@moneko/${FRAMEWORK}`,
|
|
18
|
+
'neko-ui',
|
|
19
|
+
'antd',
|
|
20
|
+
'@antv',
|
|
21
|
+
'katex',
|
|
22
|
+
'font-pingfang-sc',
|
|
23
|
+
'font-pingfang-tc',
|
|
24
|
+
'react-photo-view',
|
|
25
|
+
'react-markdown-editor-lite',
|
|
26
|
+
'schema-design'
|
|
27
|
+
];
|
|
28
|
+
let defaultSplitChunk = {
|
|
29
|
+
chunks: 'all',
|
|
30
|
+
minSize: 1024,
|
|
31
|
+
minChunks: 1
|
|
32
|
+
};
|
|
33
|
+
if (APPTYPE === 'single-component') {
|
|
34
|
+
defaultSplitChunk = false;
|
|
35
|
+
}
|
|
36
|
+
const defaultConfig = {
|
|
37
|
+
seo: false,
|
|
38
|
+
mode: 'csr',
|
|
39
|
+
compiler: 'swc',
|
|
40
|
+
bundleAnalyzer: {
|
|
41
|
+
analyzerMode: 'static',
|
|
42
|
+
reportFilename: 'report.html',
|
|
43
|
+
openAnalyzer: false
|
|
44
|
+
},
|
|
45
|
+
entry: {},
|
|
46
|
+
minifier: {
|
|
47
|
+
js: {},
|
|
48
|
+
css: {}
|
|
49
|
+
},
|
|
50
|
+
sourceMap: {
|
|
51
|
+
filename: '[file].map',
|
|
52
|
+
publicPath: ''
|
|
53
|
+
},
|
|
54
|
+
env: {},
|
|
55
|
+
routeBaseName: '/',
|
|
56
|
+
publicPath: '/',
|
|
57
|
+
designSize: APPTYPE === 'mobile' ? 375 : 1680,
|
|
58
|
+
fallbackCompPath: null,
|
|
59
|
+
modifyVars: {},
|
|
60
|
+
prefixCls: 'n',
|
|
61
|
+
alias: {},
|
|
62
|
+
layoutSider: {},
|
|
63
|
+
moduleRules: [],
|
|
64
|
+
prefixJsLoader: [],
|
|
65
|
+
cssModules: [],
|
|
66
|
+
importOnDemand: {},
|
|
67
|
+
proxy: [],
|
|
68
|
+
cacheDirectory: PROGRAMPATH + '/node_modules/.temp_cache',
|
|
69
|
+
devServer: {
|
|
70
|
+
allowedHosts: [
|
|
71
|
+
'.baidu.com'
|
|
72
|
+
],
|
|
73
|
+
host: 'localhost',
|
|
74
|
+
port: 3000,
|
|
75
|
+
https: false,
|
|
76
|
+
compress: false
|
|
77
|
+
},
|
|
78
|
+
htmlPluginOption: {
|
|
79
|
+
template: `./node_modules/${pkgName}/template/index.html`,
|
|
80
|
+
favicon: `./node_modules/${pkgName}/template/favicon.ico`,
|
|
81
|
+
tags: []
|
|
82
|
+
},
|
|
83
|
+
assetHtml: [],
|
|
84
|
+
routerMode: 'browser',
|
|
85
|
+
fixBrowserRouter: false,
|
|
86
|
+
plugins: [],
|
|
87
|
+
splitChunk: defaultSplitChunk,
|
|
88
|
+
runtimeChunk: APPTYPE === 'single-component' ? false : 'single',
|
|
89
|
+
moduleFederation: [],
|
|
90
|
+
rulesInclude: {
|
|
91
|
+
less: includeModule,
|
|
92
|
+
css: includeModule,
|
|
93
|
+
js: includeModule,
|
|
94
|
+
media: includeModule,
|
|
95
|
+
fonts: includeModule
|
|
96
|
+
},
|
|
97
|
+
mdx: {
|
|
98
|
+
jsxImportSource: jsxImportSource,
|
|
99
|
+
remarkPlugins: [],
|
|
100
|
+
rehypePlugins: []
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
export const log = (msg)=>{
|
|
104
|
+
readline.cursorTo(process.stdout, 0);
|
|
105
|
+
process.stdout.write(msg);
|
|
106
|
+
};
|
|
107
|
+
let customConf = defaultConfig;
|
|
108
|
+
let configPath = null;
|
|
109
|
+
let normalConf = {};
|
|
110
|
+
let envConf = {};
|
|
111
|
+
try {
|
|
112
|
+
configPath = path.join(PROGRAMPATH, './config/index.ts');
|
|
113
|
+
fs.accessSync(configPath, fs.constants.R_OK);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
configPath = null;
|
|
116
|
+
}
|
|
117
|
+
if (configPath) {
|
|
118
|
+
try {
|
|
119
|
+
const conf = (await readConf(configPath, 'index')).default;
|
|
120
|
+
normalConf = isFunction(conf) ? conf(process) : conf;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
process.stdout.write(chalk.red(error));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (CUSTOMCONFIG) {
|
|
126
|
+
let customConfigPath = null;
|
|
127
|
+
try {
|
|
128
|
+
customConfigPath = path.join(PROGRAMPATH, `./config/${CUSTOMCONFIG}.ts`);
|
|
129
|
+
fs.accessSync(customConfigPath, fs.constants.R_OK);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
customConfigPath = null;
|
|
132
|
+
}
|
|
133
|
+
if (customConfigPath !== null) {
|
|
134
|
+
try {
|
|
135
|
+
const conf = (await readConf(customConfigPath, CUSTOMCONFIG)).default;
|
|
136
|
+
envConf = isFunction(conf) ? conf(process) : conf;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
process.stdout.write(chalk.red(error));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
customConf = merge(customConf, normalConf, envConf);
|
|
143
|
+
if (customConf.compiler === 'tsc' && customConf.minifier) {
|
|
144
|
+
if (!customConf.minifier.js) {
|
|
145
|
+
Object.assign(customConf.minifier, {
|
|
146
|
+
js: {
|
|
147
|
+
type: 'terser'
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (!customConf.minifier.css) {
|
|
152
|
+
Object.assign(customConf.minifier, {
|
|
153
|
+
css: {
|
|
154
|
+
type: 'cssnano'
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (customConf.devtool === false) customConf.sourceMap = false;
|
|
160
|
+
if (customConf.sourceMap === false) customConf.devtool = false;
|
|
161
|
+
if (customConf.fixBrowserRouter) {
|
|
162
|
+
if (!customConf.htmlPluginOption.tags) {
|
|
163
|
+
customConf.htmlPluginOption.tags = [];
|
|
164
|
+
}
|
|
165
|
+
customConf.htmlPluginOption.tags.push({
|
|
166
|
+
textContent: `
|
|
2
167
|
(function(l) {
|
|
3
168
|
if (l.search[1] === '/' ) {
|
|
4
169
|
var decoded = l.search.slice(1).split('&').map(function(s) {
|
|
@@ -9,4 +174,12 @@ import e from"fs";import t from"path";import o from"readline";import s from"chal
|
|
|
9
174
|
);
|
|
10
175
|
}
|
|
11
176
|
}(window.location))
|
|
12
|
-
`
|
|
177
|
+
`
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
export const CONFIG = customConf;
|
|
181
|
+
export const PUBLICPATH = CONFIG.publicPath || '/';
|
|
182
|
+
global.NEKOCLICONFIG = {
|
|
183
|
+
CONFIG,
|
|
184
|
+
log
|
|
185
|
+
};
|
package/lib/coverage.js
CHANGED
|
@@ -1 +1,30 @@
|
|
|
1
|
-
import{readFileSync
|
|
1
|
+
import { readFileSync, accessSync, constants } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { Parser } from 'xml2js';
|
|
4
|
+
import { PACKAGENAME, PROGRAMPATH } from './process-env.js';
|
|
5
|
+
export const coverage = {};
|
|
6
|
+
try {
|
|
7
|
+
const coveragePath = join(PROGRAMPATH, './coverage/clover.xml');
|
|
8
|
+
accessSync(coveragePath, constants.R_OK);
|
|
9
|
+
const parser = new Parser({
|
|
10
|
+
explicitArray: false,
|
|
11
|
+
async: false
|
|
12
|
+
});
|
|
13
|
+
const cover = readFileSync(coveragePath, {
|
|
14
|
+
encoding: 'utf-8'
|
|
15
|
+
});
|
|
16
|
+
parser.parseString(cover, (error, result)=>{
|
|
17
|
+
if (!error) {
|
|
18
|
+
const projectMetrics = result.coverage.project.metrics.$;
|
|
19
|
+
const components = result.coverage.project.package;
|
|
20
|
+
Object.assign(coverage, {
|
|
21
|
+
[PACKAGENAME]: projectMetrics
|
|
22
|
+
});
|
|
23
|
+
components.forEach((pkg)=>{
|
|
24
|
+
Object.assign(coverage, {
|
|
25
|
+
[pkg.$.name]: pkg.metrics.$
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {}
|
package/lib/done.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
class DoneWebpackPlugin {
|
|
2
|
+
constructor(options){
|
|
3
|
+
this.options = Object.assign({}, options);
|
|
4
|
+
}
|
|
5
|
+
apply(compiler) {
|
|
6
|
+
const that = this;
|
|
7
|
+
compiler.hooks.done.tap('DoneWebpackPlugin', function() {
|
|
8
|
+
that.options.done?.();
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export default DoneWebpackPlugin;
|
package/lib/envFlags.js
CHANGED
|
@@ -1 +1,48 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { CONFIG } from './common.js';
|
|
4
|
+
import { coverage } from './coverage.js';
|
|
5
|
+
import htmlPluginOption from './html-plugin-option.js';
|
|
6
|
+
import { APPTYPE, NODE_ENV, PACKAGENAME, programInfo, PROGRAMPATH, hasAntd } from './process-env.js';
|
|
7
|
+
import { toUpperCaseString } from './utils.js';
|
|
8
|
+
const ReactDOMPath = 'react-dom/client';
|
|
9
|
+
const entryName = APPTYPE === 'library' ? 'site' : 'src';
|
|
10
|
+
let APPENTRY = false;
|
|
11
|
+
try {
|
|
12
|
+
const appEntryPath = path.join(PROGRAMPATH, './src/index.ts');
|
|
13
|
+
fs.accessSync(appEntryPath, fs.constants.R_OK);
|
|
14
|
+
APPENTRY = appEntryPath;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
APPENTRY = false;
|
|
17
|
+
}
|
|
18
|
+
const envFlags = {
|
|
19
|
+
projectName: JSON.stringify(toUpperCaseString(PACKAGENAME)),
|
|
20
|
+
projectCoverage: JSON.stringify(coverage),
|
|
21
|
+
providerConfig: JSON.stringify({
|
|
22
|
+
prefixCls: CONFIG.prefixCls,
|
|
23
|
+
iconPrefixCls: CONFIG.prefixCls + '-icon',
|
|
24
|
+
theme: CONFIG.theme
|
|
25
|
+
}),
|
|
26
|
+
fallbackCompPath: JSON.stringify(CONFIG.fallbackCompPath),
|
|
27
|
+
ReactDOMPath: JSON.stringify(ReactDOMPath),
|
|
28
|
+
favicon: JSON.stringify(htmlPluginOption.favicon),
|
|
29
|
+
hasLocales: JSON.stringify(fs.existsSync(path.join(PROGRAMPATH, `./${entryName}/locales`))),
|
|
30
|
+
hasPersist: JSON.stringify(fs.existsSync(path.join(PROGRAMPATH, `./${entryName}/persist.ts`))),
|
|
31
|
+
layoutSider: JSON.stringify(CONFIG.layoutSider),
|
|
32
|
+
hasAntd: JSON.stringify(hasAntd),
|
|
33
|
+
APPTYPE: JSON.stringify(APPTYPE),
|
|
34
|
+
APPENTRY: JSON.stringify(APPENTRY),
|
|
35
|
+
programInfo: JSON.stringify({
|
|
36
|
+
...programInfo,
|
|
37
|
+
routeBaseName: CONFIG.routeBaseName,
|
|
38
|
+
designSize: CONFIG.designSize,
|
|
39
|
+
routerMode: CONFIG.routerMode,
|
|
40
|
+
renderMode: CONFIG.mode
|
|
41
|
+
}),
|
|
42
|
+
'process.env': JSON.stringify({
|
|
43
|
+
NODE_ENV: NODE_ENV,
|
|
44
|
+
iconfont: CONFIG.iconfont,
|
|
45
|
+
...CONFIG.env
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
export default envFlags;
|
package/lib/esm.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function esm(templateStrings, ...substitutions) {
|
|
2
|
+
let js = templateStrings.raw[0];
|
|
3
|
+
for(let i = 0; i < substitutions.length; i++){
|
|
4
|
+
js += substitutions[i] + templateStrings.raw[i + 1];
|
|
5
|
+
}
|
|
6
|
+
return `data:text/javascript;base64,${Buffer.from(js).toString('base64')}`;
|
|
7
|
+
}
|
package/lib/has-pkg.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
import{accessSync
|
|
1
|
+
import { accessSync, constants } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { PROGRAMPATH } from './process-env.js';
|
|
4
|
+
export function hasPkg(name) {
|
|
5
|
+
let flag = false;
|
|
6
|
+
try {
|
|
7
|
+
const antdPath = path.join(PROGRAMPATH, `./node_modules/${name}/package.json`);
|
|
8
|
+
accessSync(antdPath, constants.R_OK);
|
|
9
|
+
flag = true;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
flag = false;
|
|
12
|
+
}
|
|
13
|
+
return flag;
|
|
14
|
+
}
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
class AddEntryAttributeWebpackPlugin {
|
|
2
|
+
constructor(matchCallback){
|
|
3
|
+
this.entryMatchCallback = matchCallback;
|
|
4
|
+
}
|
|
5
|
+
apply(compiler) {
|
|
6
|
+
compiler.hooks.compilation.tap('AddEntryAttributeWebpackPlugin', (compilation)=>{
|
|
7
|
+
const HtmlWebpackPluginInstance = compiler.options.plugins.map(({ constructor })=>constructor).find((constructor)=>constructor && constructor.name === 'HtmlWebpackPlugin');
|
|
8
|
+
if (HtmlWebpackPluginInstance) {
|
|
9
|
+
const hooks = HtmlWebpackPluginInstance.getHooks(compilation);
|
|
10
|
+
hooks.alterAssetTagGroups.tap('AddEntryAttributeWebpackPlugin', (data)=>{
|
|
11
|
+
data.headTags.forEach((tag)=>{
|
|
12
|
+
if (tag.tagName === 'script' && typeof tag.attributes?.src === 'string' && this.entryMatchCallback(tag.attributes.src)) {
|
|
13
|
+
tag.attributes.entry = true;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return data;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export default AddEntryAttributeWebpackPlugin;
|
|
@@ -1 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { merge } from 'webpack-merge';
|
|
3
|
+
import { CONFIG } from './common.js';
|
|
4
|
+
import { PROGRAMPATH, PACKAGENAME, programInfo } from './process-env.js';
|
|
5
|
+
const { template , favicon , ...option } = CONFIG.htmlPluginOption;
|
|
6
|
+
const htmlPluginOption = merge({
|
|
7
|
+
title: CONFIG.env?.PROJECTNAME || PACKAGENAME.toLocaleUpperCase() || 'Title',
|
|
8
|
+
filename: 'index.html',
|
|
9
|
+
hash: false,
|
|
10
|
+
minify: {
|
|
11
|
+
collapseWhitespace: true,
|
|
12
|
+
removeComments: true,
|
|
13
|
+
removeRedundantAttributes: false,
|
|
14
|
+
removeScriptTypeAttributes: false,
|
|
15
|
+
removeStyleLinkTypeAttributes: false,
|
|
16
|
+
removeAttributeQuotes: true,
|
|
17
|
+
useShortDoctype: true
|
|
18
|
+
},
|
|
19
|
+
meta: {
|
|
20
|
+
charset: 'UTF-8',
|
|
21
|
+
'X-UA-Compatible': {
|
|
22
|
+
'http-equiv': 'X-UA-Compatible',
|
|
23
|
+
content: 'IE=edge,Chrome=1'
|
|
24
|
+
},
|
|
25
|
+
HandheldFriendly: 'true',
|
|
26
|
+
MobileOptimized: '320',
|
|
27
|
+
'screen-orientation': 'portrait',
|
|
28
|
+
'x5-orientation': 'portrait',
|
|
29
|
+
browsermode: 'application',
|
|
30
|
+
'x5-page-mode': 'app',
|
|
31
|
+
'msapplication-tap-highlight': 'no',
|
|
32
|
+
viewport: 'width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no',
|
|
33
|
+
'apple-mobile-web-app-capable': 'yes',
|
|
34
|
+
renderer: 'webkit',
|
|
35
|
+
description: programInfo.description || ''
|
|
36
|
+
},
|
|
37
|
+
tags: [],
|
|
38
|
+
template: path.join(PROGRAMPATH, template),
|
|
39
|
+
favicon: path.join(PROGRAMPATH, favicon)
|
|
40
|
+
}, option);
|
|
41
|
+
export default htmlPluginOption;
|
package/lib/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export*from
|
|
1
|
+
export * from './process-env.js';
|
|
2
|
+
export * from './utils.js';
|
|
3
|
+
export * from '../typings/global.js';
|
|
4
|
+
export { default as envFlags } from './envFlags.js';
|
package/lib/minify.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
2
|
+
import { merge } from 'webpack-merge';
|
|
3
|
+
import { swcMinifyOption } from './swcrc.js';
|
|
4
|
+
export const minify = {
|
|
5
|
+
terser: {
|
|
6
|
+
minify: TerserPlugin.terserMinify,
|
|
7
|
+
terserOptions: {
|
|
8
|
+
ecma: 2015,
|
|
9
|
+
parse: {},
|
|
10
|
+
compress: {
|
|
11
|
+
global_defs: {
|
|
12
|
+
'@alert': 'console.log'
|
|
13
|
+
},
|
|
14
|
+
drop_console: true,
|
|
15
|
+
drop_debugger: true,
|
|
16
|
+
pure_funcs: [
|
|
17
|
+
'console.log',
|
|
18
|
+
'console.warn',
|
|
19
|
+
'console.error',
|
|
20
|
+
'console.info'
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
toplevel: false,
|
|
24
|
+
mangle: true,
|
|
25
|
+
module: false,
|
|
26
|
+
format: {
|
|
27
|
+
comments: false
|
|
28
|
+
},
|
|
29
|
+
ie8: false,
|
|
30
|
+
keep_classnames: undefined,
|
|
31
|
+
keep_fnames: false,
|
|
32
|
+
safari10: false
|
|
33
|
+
},
|
|
34
|
+
extractComments: false
|
|
35
|
+
},
|
|
36
|
+
swc: {
|
|
37
|
+
minify: TerserPlugin.swcMinify,
|
|
38
|
+
terserOptions: swcMinifyOption
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export const getMinifyOption = (type, options = {})=>{
|
|
42
|
+
const min = minify[type];
|
|
43
|
+
return Object.assign(min, {
|
|
44
|
+
terserOptions: merge(min.terserOptions, options)
|
|
45
|
+
});
|
|
46
|
+
};
|
package/lib/modifyVars.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{CONFIG
|
|
1
|
+
import { CONFIG } from './common.js';
|
|
2
|
+
import htmlPluginOption from './html-plugin-option.js';
|
|
3
|
+
const prefixCls = CONFIG.prefixCls || 'n';
|
|
4
|
+
const modifyVars = {};
|
|
5
|
+
Object.assign(modifyVars, {
|
|
6
|
+
'@prefix-cls': prefixCls,
|
|
7
|
+
'@ant-prefix': prefixCls,
|
|
8
|
+
'@iconfont-css-prefix': prefixCls + '-icon',
|
|
9
|
+
'@favicon': JSON.stringify(htmlPluginOption.favicon)
|
|
10
|
+
}, CONFIG.modifyVars || {});
|
|
11
|
+
export default modifyVars;
|
package/lib/module-federation.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ExternalTemplateRemotesPlugin from 'external-remotes-plugin';
|
|
2
|
+
import webpack from 'webpack';
|
|
3
|
+
import ModuleFederationPlugin from 'webpack/lib/container/ModuleFederationPlugin.js';
|
|
4
|
+
import { CONFIG } from './common.js';
|
|
5
|
+
import { resolve } from './utils.js';
|
|
6
|
+
const NormalModuleReplacementPlugin = webpack.NormalModuleReplacementPlugin;
|
|
7
|
+
const aliasLibrary = {};
|
|
8
|
+
const exposesMap = {};
|
|
9
|
+
const remoteMap = {};
|
|
10
|
+
export const moduleFederation = CONFIG.moduleFederation?.map((opt)=>{
|
|
11
|
+
if (Array.isArray(opt.remotes)) {
|
|
12
|
+
for(let r = 0, rlen = opt.remotes.length; r < rlen; r++){
|
|
13
|
+
const m = opt.remotes[r];
|
|
14
|
+
const aliasName = m.alias || m.name;
|
|
15
|
+
const filename = m.filename || 'remote_entry.js';
|
|
16
|
+
remoteMap[aliasName] = `${m.name}@${m.host}/${filename}`;
|
|
17
|
+
if (Array.isArray(m.library)) {
|
|
18
|
+
for(let i = 0, len = m.library.length; i < len; i++){
|
|
19
|
+
aliasLibrary[m.library[i]] = `${aliasName}/${m.library[i]}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(opt.exposes)) {
|
|
25
|
+
for(let i = 0, len = opt.exposes.length; i < len; i++){
|
|
26
|
+
const m = opt.exposes[i];
|
|
27
|
+
if (typeof m === 'string') {
|
|
28
|
+
exposesMap[`./${m}`] = resolve(m);
|
|
29
|
+
} else if (Object.prototype.toString.call(m) === '[object Object]') {
|
|
30
|
+
exposesMap[`./${m.name}`] = resolve(m.path);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return new ModuleFederationPlugin({
|
|
35
|
+
filename: 'remote_entry.js',
|
|
36
|
+
...opt,
|
|
37
|
+
remotes: remoteMap,
|
|
38
|
+
exposes: exposesMap
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
if (moduleFederation.length) {
|
|
42
|
+
moduleFederation.push(new ExternalTemplateRemotesPlugin());
|
|
43
|
+
moduleFederation.push(new NormalModuleReplacementPlugin(/(.*)/, (resource)=>{
|
|
44
|
+
if (aliasLibrary[resource.request]) resource.request = aliasLibrary[resource.request];
|
|
45
|
+
}));
|
|
46
|
+
}
|