@moneko/core 3.0.0-beta.42 → 3.0.0-beta.45
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 +212 -2
- package/lib/coverage.js +30 -1
- package/lib/done.js +13 -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 +23 -1
- package/lib/html-plugin-option.js +44 -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.d.ts +2 -0
- package/lib/process-env.js +65 -1
- package/lib/resolver-sync.js +21 -1
- package/lib/routes.js +190 -1
- package/lib/seo.js +57 -1
- package/lib/swcrc.js +111 -1
- package/lib/tsloader.config.js +25 -1
- package/lib/utils.js +64 -1
- package/lib/webpack.common.js +216 -1
- package/lib/webpack.dev.js +98 -3
- package/lib/webpack.prod.js +66 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +3 -4
package/lib/common.js
CHANGED
|
@@ -1,4 +1,206 @@
|
|
|
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
|
+
cacheGroups: {
|
|
33
|
+
route: {
|
|
34
|
+
test: /[\\/].git[\\/]router/,
|
|
35
|
+
priority: -10,
|
|
36
|
+
reuseExistingChunk: true,
|
|
37
|
+
name: 'route'
|
|
38
|
+
},
|
|
39
|
+
example: {
|
|
40
|
+
test: /[\\/].git[\\/]example/,
|
|
41
|
+
priority: -10,
|
|
42
|
+
reuseExistingChunk: true,
|
|
43
|
+
name: 'example'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
if (APPTYPE === 'single-component') {
|
|
48
|
+
defaultSplitChunk = false;
|
|
49
|
+
}
|
|
50
|
+
const defaultConfig = {
|
|
51
|
+
seo: false,
|
|
52
|
+
mode: 'csr',
|
|
53
|
+
compiler: 'swc',
|
|
54
|
+
bundleAnalyzer: {
|
|
55
|
+
analyzerMode: 'static',
|
|
56
|
+
reportFilename: 'report.html',
|
|
57
|
+
openAnalyzer: false
|
|
58
|
+
},
|
|
59
|
+
entry: {},
|
|
60
|
+
minifier: {
|
|
61
|
+
js: {},
|
|
62
|
+
css: {}
|
|
63
|
+
},
|
|
64
|
+
sourceMap: {
|
|
65
|
+
filename: '[file].map',
|
|
66
|
+
publicPath: ''
|
|
67
|
+
},
|
|
68
|
+
env: {},
|
|
69
|
+
routeBaseName: '/',
|
|
70
|
+
publicPath: '/',
|
|
71
|
+
designSize: APPTYPE === 'mobile' ? 375 : 1680,
|
|
72
|
+
fallbackCompPath: null,
|
|
73
|
+
modifyVars: {},
|
|
74
|
+
prefixCls: 'n',
|
|
75
|
+
alias: {},
|
|
76
|
+
layoutSider: {},
|
|
77
|
+
moduleRules: [],
|
|
78
|
+
prefixJsLoader: [],
|
|
79
|
+
cssModules: [],
|
|
80
|
+
importOnDemand: {},
|
|
81
|
+
proxy: [],
|
|
82
|
+
cacheDirectory: PROGRAMPATH + '/node_modules/.temp_cache',
|
|
83
|
+
devServer: {
|
|
84
|
+
allowedHosts: [
|
|
85
|
+
'.baidu.com'
|
|
86
|
+
],
|
|
87
|
+
host: 'localhost',
|
|
88
|
+
port: 3000,
|
|
89
|
+
https: false,
|
|
90
|
+
compress: false
|
|
91
|
+
},
|
|
92
|
+
htmlPluginOption: {
|
|
93
|
+
template: `./node_modules/${pkgName}/template/index.html`,
|
|
94
|
+
favicon: `./node_modules/${pkgName}/template/favicon.ico`,
|
|
95
|
+
tags: []
|
|
96
|
+
},
|
|
97
|
+
assetHtml: [],
|
|
98
|
+
routerMode: 'browser',
|
|
99
|
+
fixBrowserRouter: false,
|
|
100
|
+
plugins: [],
|
|
101
|
+
splitChunk: defaultSplitChunk,
|
|
102
|
+
runtimeChunk: APPTYPE === 'single-component' ? false : 'single',
|
|
103
|
+
moduleFederation: [],
|
|
104
|
+
rulesInclude: {
|
|
105
|
+
less: includeModule,
|
|
106
|
+
css: includeModule,
|
|
107
|
+
js: includeModule,
|
|
108
|
+
media: includeModule,
|
|
109
|
+
fonts: includeModule
|
|
110
|
+
},
|
|
111
|
+
mdx: {
|
|
112
|
+
jsxImportSource: jsxImportSource,
|
|
113
|
+
remarkPlugins: [],
|
|
114
|
+
rehypePlugins: []
|
|
115
|
+
},
|
|
116
|
+
jsxDomExpressions: {
|
|
117
|
+
moduleName: 'solid-js/web',
|
|
118
|
+
builtIns: [
|
|
119
|
+
'For',
|
|
120
|
+
'Show',
|
|
121
|
+
'Switch',
|
|
122
|
+
'Match',
|
|
123
|
+
'Suspense',
|
|
124
|
+
'SuspenseList',
|
|
125
|
+
'Portal',
|
|
126
|
+
'Index',
|
|
127
|
+
'Dynamic',
|
|
128
|
+
'ErrorBoundary'
|
|
129
|
+
],
|
|
130
|
+
contextToCustomElements: true,
|
|
131
|
+
wrapConditionals: true,
|
|
132
|
+
generate: 'dom',
|
|
133
|
+
hydratable: false
|
|
134
|
+
},
|
|
135
|
+
bar: {
|
|
136
|
+
name: '编译中',
|
|
137
|
+
color: '#6f42c1'
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
export const log = (msg)=>{
|
|
141
|
+
readline.cursorTo(process.stdout, 0);
|
|
142
|
+
process.stdout.write(msg);
|
|
143
|
+
};
|
|
144
|
+
let customConf = defaultConfig;
|
|
145
|
+
let configPath = null;
|
|
146
|
+
let normalConf = {};
|
|
147
|
+
let envConf = {};
|
|
148
|
+
try {
|
|
149
|
+
configPath = path.join(PROGRAMPATH, './config/index.ts');
|
|
150
|
+
fs.accessSync(configPath, fs.constants.R_OK);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
configPath = null;
|
|
153
|
+
}
|
|
154
|
+
if (configPath) {
|
|
155
|
+
try {
|
|
156
|
+
const conf = (await readConf(configPath, 'index')).default;
|
|
157
|
+
normalConf = isFunction(conf) ? conf(process) : conf;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
process.stdout.write(chalk.red(error));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (CUSTOMCONFIG) {
|
|
163
|
+
let customConfigPath = null;
|
|
164
|
+
try {
|
|
165
|
+
customConfigPath = path.join(PROGRAMPATH, `./config/${CUSTOMCONFIG}.ts`);
|
|
166
|
+
fs.accessSync(customConfigPath, fs.constants.R_OK);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
customConfigPath = null;
|
|
169
|
+
}
|
|
170
|
+
if (customConfigPath !== null) {
|
|
171
|
+
try {
|
|
172
|
+
const conf = (await readConf(customConfigPath, CUSTOMCONFIG)).default;
|
|
173
|
+
envConf = isFunction(conf) ? conf(process) : conf;
|
|
174
|
+
} catch (error) {
|
|
175
|
+
process.stdout.write(chalk.red(error));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
customConf = merge(customConf, normalConf, envConf);
|
|
180
|
+
if (customConf.compiler === 'tsc' && customConf.minifier) {
|
|
181
|
+
if (!customConf.minifier.js) {
|
|
182
|
+
Object.assign(customConf.minifier, {
|
|
183
|
+
js: {
|
|
184
|
+
type: 'terser'
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (!customConf.minifier.css) {
|
|
189
|
+
Object.assign(customConf.minifier, {
|
|
190
|
+
css: {
|
|
191
|
+
type: 'cssnano'
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (customConf.devtool === false) customConf.sourceMap = false;
|
|
197
|
+
if (customConf.sourceMap === false) customConf.devtool = false;
|
|
198
|
+
if (customConf.fixBrowserRouter && customConf.htmlPluginOption) {
|
|
199
|
+
if (!customConf.htmlPluginOption.tags) {
|
|
200
|
+
customConf.htmlPluginOption.tags = [];
|
|
201
|
+
}
|
|
202
|
+
customConf.htmlPluginOption.tags.push({
|
|
203
|
+
textContent: `
|
|
2
204
|
(function(l) {
|
|
3
205
|
if (l.search[1] === '/' ) {
|
|
4
206
|
var decoded = l.search.slice(1).split('&').map(function(s) {
|
|
@@ -9,4 +211,12 @@ import e from"fs";import t from"path";import o from"readline";import s from"chal
|
|
|
9
211
|
);
|
|
10
212
|
}
|
|
11
213
|
}(window.location))
|
|
12
|
-
`
|
|
214
|
+
`
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
export const CONFIG = customConf;
|
|
218
|
+
export const PUBLICPATH = CONFIG.publicPath || '/';
|
|
219
|
+
global.NEKOCLICONFIG = {
|
|
220
|
+
CONFIG,
|
|
221
|
+
log
|
|
222
|
+
};
|
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,13 @@
|
|
|
1
|
-
|
|
1
|
+
class DoneWebpackPlugin {
|
|
2
|
+
options;
|
|
3
|
+
constructor(options){
|
|
4
|
+
this.options = Object.assign({}, options);
|
|
5
|
+
}
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
const that = this;
|
|
8
|
+
compiler.hooks.done.tap('DoneWebpackPlugin', function() {
|
|
9
|
+
that.options.done?.();
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
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,23 @@
|
|
|
1
|
-
|
|
1
|
+
class AddEntryAttributeWebpackPlugin {
|
|
2
|
+
entryMatchCallback;
|
|
3
|
+
constructor(matchCallback){
|
|
4
|
+
this.entryMatchCallback = matchCallback;
|
|
5
|
+
}
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
compiler.hooks.compilation.tap('AddEntryAttributeWebpackPlugin', (compilation)=>{
|
|
8
|
+
const HtmlWebpackPluginInstance = compiler.options.plugins.map(({ constructor })=>constructor).find((constructor)=>constructor && constructor.name === 'HtmlWebpackPlugin');
|
|
9
|
+
if (HtmlWebpackPluginInstance) {
|
|
10
|
+
const hooks = HtmlWebpackPluginInstance.getHooks(compilation);
|
|
11
|
+
hooks.alterAssetTagGroups.tap('AddEntryAttributeWebpackPlugin', (data)=>{
|
|
12
|
+
data.headTags.forEach((tag)=>{
|
|
13
|
+
if (tag.tagName === 'script' && typeof tag.attributes?.src === 'string' && this.entryMatchCallback(tag.attributes.src)) {
|
|
14
|
+
tag.attributes.entry = true;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return data;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export default AddEntryAttributeWebpackPlugin;
|
|
@@ -1 +1,44 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { merge } from 'webpack-merge';
|
|
3
|
+
import { CONFIG } from './common.js';
|
|
4
|
+
import { PROGRAMPATH, PACKAGENAME, programInfo, pkgName } from './process-env.js';
|
|
5
|
+
const { template , favicon , ...option } = CONFIG.htmlPluginOption || {
|
|
6
|
+
template: `./node_modules/${pkgName}/template/index.html`,
|
|
7
|
+
favicon: `./node_modules/${pkgName}/template/favicon.ico`
|
|
8
|
+
};
|
|
9
|
+
const htmlPluginOption = merge({
|
|
10
|
+
title: CONFIG.env?.PROJECTNAME || PACKAGENAME.toLocaleUpperCase() || 'Title',
|
|
11
|
+
filename: 'index.html',
|
|
12
|
+
hash: false,
|
|
13
|
+
minify: {
|
|
14
|
+
collapseWhitespace: true,
|
|
15
|
+
removeComments: true,
|
|
16
|
+
removeRedundantAttributes: false,
|
|
17
|
+
removeScriptTypeAttributes: false,
|
|
18
|
+
removeStyleLinkTypeAttributes: false,
|
|
19
|
+
removeAttributeQuotes: true,
|
|
20
|
+
useShortDoctype: true
|
|
21
|
+
},
|
|
22
|
+
meta: {
|
|
23
|
+
charset: 'UTF-8',
|
|
24
|
+
'X-UA-Compatible': {
|
|
25
|
+
'http-equiv': 'X-UA-Compatible',
|
|
26
|
+
content: 'IE=edge,Chrome=1'
|
|
27
|
+
},
|
|
28
|
+
HandheldFriendly: 'true',
|
|
29
|
+
MobileOptimized: '320',
|
|
30
|
+
'screen-orientation': 'portrait',
|
|
31
|
+
'x5-orientation': 'portrait',
|
|
32
|
+
browsermode: 'application',
|
|
33
|
+
'x5-page-mode': 'app',
|
|
34
|
+
'msapplication-tap-highlight': 'no',
|
|
35
|
+
viewport: 'width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no',
|
|
36
|
+
'apple-mobile-web-app-capable': 'yes',
|
|
37
|
+
renderer: 'webkit',
|
|
38
|
+
description: programInfo.description || ''
|
|
39
|
+
},
|
|
40
|
+
tags: [],
|
|
41
|
+
template: path.join(PROGRAMPATH, template),
|
|
42
|
+
favicon: path.join(PROGRAMPATH, favicon)
|
|
43
|
+
}, option);
|
|
44
|
+
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
|
+
}
|