@moneko/core 3.0.0-beta.82 → 3.0.0-beta.84
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/app.js +27 -1
- package/lib/cleanup.js +19 -1
- package/lib/common.js +214 -2
- package/lib/coverage.js +30 -1
- package/lib/define.d.ts +1 -3
- package/lib/define.js +9 -1
- package/lib/docs.js +118 -1
- package/lib/done.js +12 -1
- package/lib/esm.js +7 -1
- package/lib/generate-api.js +331 -1
- package/lib/has-pkg.js +14 -1
- package/lib/html-add-entry-attr.js +24 -1
- package/lib/html-plugin-option.js +44 -1
- package/lib/index.js +3 -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 +211 -1
- package/lib/net.js +33 -1
- package/lib/object-listener.js +28 -1
- package/lib/process-env.js +65 -1
- package/lib/resolver-sync.js +21 -1
- package/lib/routes.d.ts +1 -2
- package/lib/routes.js +171 -1
- package/lib/seo.js +59 -1
- package/lib/swcrc.js +105 -1
- package/lib/tsloader.config.js +25 -1
- package/lib/utils.js +49 -1
- package/lib/virtual-module-plugin.js +26 -1
- package/lib/virtual-modules.js +30 -1
- package/lib/webpack.common.js +230 -1
- package/lib/webpack.dev.js +92 -3
- package/lib/webpack.prod.js +66 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +2 -2
package/lib/generate-api.js
CHANGED
|
@@ -1 +1,331 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname } from 'path';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { CONFIG } from './common.js';
|
|
5
|
+
import { alias } from './webpack.common.js';
|
|
6
|
+
const { ScriptKind , ScriptTarget , SyntaxKind , createSourceFile , forEachChild , getLeadingCommentRanges , isInterfaceDeclaration , isQuestionToken , isPropertySignature , isFunctionTypeNode , isUnionTypeNode , isMethodSignature } = ts;
|
|
7
|
+
const allType = {};
|
|
8
|
+
function getPropertyComment(propertyNode) {
|
|
9
|
+
const comments = getLeadingCommentRanges(propertyNode.getSourceFile().text, propertyNode.pos);
|
|
10
|
+
if (comments) {
|
|
11
|
+
const commentText = propertyNode.getSourceFile().text.substring(comments[0].pos, comments[0].end);
|
|
12
|
+
const match = commentText.match(/\/\*\*([\s\S]*?)\*\//);
|
|
13
|
+
if (match) {
|
|
14
|
+
const trimmedCommentText = match[1].replace(/^\s*\* ?/gm, '').replace(/\s+$/, '').trim();
|
|
15
|
+
return trimmedCommentText;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function getDefaultValueFromComment(commentText) {
|
|
21
|
+
if (!commentText) return null;
|
|
22
|
+
const defaultValueRegex = /@default\s+([^\n]+)/;
|
|
23
|
+
const defaultValueMatch = commentText.match(defaultValueRegex);
|
|
24
|
+
return defaultValueMatch ? defaultValueMatch[1].trim() : null;
|
|
25
|
+
}
|
|
26
|
+
function getVersionFromComment(commentText) {
|
|
27
|
+
if (!commentText) return null;
|
|
28
|
+
const versionRegex = /@since\s+([^\n]+)/;
|
|
29
|
+
const versionMatch = commentText.match(versionRegex);
|
|
30
|
+
return versionMatch ? versionMatch[1].trim() : null;
|
|
31
|
+
}
|
|
32
|
+
function getAuthor(commentText) {
|
|
33
|
+
if (!commentText) return null;
|
|
34
|
+
const regex = /@author (\w+)\s*(?:<([^>]+)>)?/;
|
|
35
|
+
const match = commentText.match(regex);
|
|
36
|
+
if (match?.length) {
|
|
37
|
+
const author = match[1].trim();
|
|
38
|
+
let url = match[2]?.trim();
|
|
39
|
+
const isEmail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(url);
|
|
40
|
+
if (!url) {
|
|
41
|
+
url = `https://github.com/${author}`;
|
|
42
|
+
} else if (isEmail) {
|
|
43
|
+
url = `mailto:${url}`;
|
|
44
|
+
}
|
|
45
|
+
return `[${author}${isEmail ? ' 📧' : ' ⎋'}](${url})`;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function getIgnore(commentText) {
|
|
50
|
+
if (!commentText) return null;
|
|
51
|
+
const versionRegex = /@ignore\s+([^\n]+)/;
|
|
52
|
+
const versionMatch = commentText.match(versionRegex);
|
|
53
|
+
return versionMatch ? versionMatch[1].trim() : null;
|
|
54
|
+
}
|
|
55
|
+
const regex = /(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;
|
|
56
|
+
function getTypeText(typeText, hasColor) {
|
|
57
|
+
if (!typeText) return null;
|
|
58
|
+
let modifiedTypeText = typeText.replace(/\b([A-Z][a-zA-Z0-9]*)\b/g, (item)=>{
|
|
59
|
+
if (allType[item]) {
|
|
60
|
+
const url = `/${[
|
|
61
|
+
CONFIG.routeBaseName,
|
|
62
|
+
allType[item]
|
|
63
|
+
].join('/').split('/').filter(Boolean).join('/')}`;
|
|
64
|
+
return hasColor ? `[\\color{#009688}{${item}}](${url})` : `[${item}](${url})`;
|
|
65
|
+
}
|
|
66
|
+
return hasColor ? `\\color{#009688}{${item}}` : item;
|
|
67
|
+
});
|
|
68
|
+
if (hasColor) {
|
|
69
|
+
modifiedTypeText = modifiedTypeText.replace(regex, (match)=>{
|
|
70
|
+
return `\\color{#009688}{${match}}`;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return modifiedTypeText;
|
|
74
|
+
}
|
|
75
|
+
function getMemberValue(memberNode) {
|
|
76
|
+
const initializer = memberNode.initializer;
|
|
77
|
+
if (initializer && ts.isStringLiteral(initializer)) {
|
|
78
|
+
return ` '${initializer.text}'`;
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
function replacePairedSymbols(inputString) {
|
|
83
|
+
if (!inputString) return null;
|
|
84
|
+
const coloredContent = [];
|
|
85
|
+
let matches;
|
|
86
|
+
while(matches = /\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(inputString)){
|
|
87
|
+
coloredContent.push(matches[0]);
|
|
88
|
+
}
|
|
89
|
+
return inputString.replace(/(\{|\}|\[|\]|\(|\)|=>|keyof|typeof|true|false)/g, (match)=>{
|
|
90
|
+
if (coloredContent.some((content)=>content.includes(match))) {
|
|
91
|
+
return match;
|
|
92
|
+
}
|
|
93
|
+
return `\\color{#569cd6}{${match}}`;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function isFunctionTypeProperty(member) {
|
|
97
|
+
if (member.type) {
|
|
98
|
+
if (isUnionTypeNode(member.type)) {
|
|
99
|
+
for (const typeNode of member.type.types){
|
|
100
|
+
if (isFunctionTypeNode(typeNode)) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
return isFunctionTypeNode(member.type);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
function replaceText(str) {
|
|
111
|
+
return replacePairedSymbols(str)?.replace(/^\s*\|\s*|\s*\|\s*$/gm, '').replace(/\n/g, '<br/>').replace(/\*/g, '\\*').replace(/\|/g, '\\|').replace(/(['"])((?:(?!\1).)*)\1/g, '\\color{#ce9178}{$1$2$1}');
|
|
112
|
+
}
|
|
113
|
+
function getBaseInterfaces(interfaceNode) {
|
|
114
|
+
const baseInterfaces = [];
|
|
115
|
+
if (interfaceNode.heritageClauses) {
|
|
116
|
+
for (const clause of interfaceNode.heritageClauses){
|
|
117
|
+
if (clause.token === ts.SyntaxKind.ExtendsKeyword) {
|
|
118
|
+
for (const typeNode of clause.types){
|
|
119
|
+
baseInterfaces.push(typeNode.getText());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return baseInterfaces;
|
|
125
|
+
}
|
|
126
|
+
function getComment(comment) {
|
|
127
|
+
if (!comment) return null;
|
|
128
|
+
return comment.replace(/^@[a-z].+/gm, '').replace(/(\n\s+)+/g, '<br />').replace(/\n/g, '<br />').replace(/(<br \/>)$/g, '');
|
|
129
|
+
}
|
|
130
|
+
function getMethodText(member) {
|
|
131
|
+
if (isMethodSignature(member)) {
|
|
132
|
+
return `(${member.parameters.map((param)=>`${param.name.getText()}: ${param.type?.getText() || 'any'}`).join(', ')}): ${member.type?.getText() || 'any'}`;
|
|
133
|
+
}
|
|
134
|
+
return member.type?.getText() || 'any';
|
|
135
|
+
}
|
|
136
|
+
function generateInterfaceDocumentation(node) {
|
|
137
|
+
const typeName = node.name.text;
|
|
138
|
+
Object.assign(allType, {
|
|
139
|
+
[node.name.text]: dirname(node.getSourceFile().fileName).replace(alias['@pkg'], '')
|
|
140
|
+
});
|
|
141
|
+
const baseComment = getPropertyComment(node);
|
|
142
|
+
const vers = getVersionFromComment(baseComment);
|
|
143
|
+
const title = getComment(baseComment);
|
|
144
|
+
const ignore = getIgnore(baseComment)?.split('|') || [];
|
|
145
|
+
const ignoreComment = ignore.includes('comment');
|
|
146
|
+
const ignoreInitial = ignore.includes('initial');
|
|
147
|
+
const ignoreOptional = ignore.includes('optional');
|
|
148
|
+
const ignoreVersion = ignore.includes('version');
|
|
149
|
+
const ignoreAuthor = ignore.includes('author');
|
|
150
|
+
const subTitle = title ? `\\color{|4||0.45}{${typeName}}` : typeName;
|
|
151
|
+
const baseInterfaces = getBaseInterfaces(node)?.map((s)=>{
|
|
152
|
+
return `<n-tag color="#4c81db" css=".tag{gap:0px;}">${getTypeText(replaceText(s))}</n-tag>`;
|
|
153
|
+
});
|
|
154
|
+
const heading = [
|
|
155
|
+
title,
|
|
156
|
+
subTitle,
|
|
157
|
+
vers && `\\color{#52c11b|1||0.9}{${vers}}`,
|
|
158
|
+
baseInterfaces.length > 0 && `<sub>\`extends\`</sub> ${baseInterfaces.join(' ')}`
|
|
159
|
+
].filter(Boolean).join(' ');
|
|
160
|
+
let markdownContent = `## ${heading}`;
|
|
161
|
+
const members = node.members.filter((m)=>isPropertySignature(m) && m.type?.kind !== SyntaxKind.NeverKeyword || isMethodSignature(m));
|
|
162
|
+
const rowsData = [];
|
|
163
|
+
if (members.length) {
|
|
164
|
+
members.forEach((member)=>{
|
|
165
|
+
const type = getTypeText(replaceText(getMethodText(member)), true);
|
|
166
|
+
const propertyComment = getPropertyComment(member);
|
|
167
|
+
let name = replaceText(member.name.getText());
|
|
168
|
+
if (name && !name.startsWith('\\color')) {
|
|
169
|
+
if (isMethodSignature(member) || isFunctionTypeProperty(member) || type?.includes('=>')) {
|
|
170
|
+
name = `\\color{#f9a913}{${name}}`;
|
|
171
|
+
} else if (!/^("|')(.+)("|')$/.test(name)) {
|
|
172
|
+
name = `\\color{#4c81db}{${name}}`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const isOptional = member.questionToken && isQuestionToken(member.questionToken);
|
|
176
|
+
rowsData.push([
|
|
177
|
+
name,
|
|
178
|
+
!ignoreOptional && `\\color{${isOptional ? '#f9a913' : '#52c11b'}\\|\\|\\|0.9}{${isOptional ? '✘' : '✔'}}`,
|
|
179
|
+
!ignoreComment && replaceText(getComment(propertyComment)),
|
|
180
|
+
type,
|
|
181
|
+
!ignoreInitial && replaceText(getDefaultValueFromComment(propertyComment)),
|
|
182
|
+
!ignoreVersion && replaceText(getVersionFromComment(propertyComment)),
|
|
183
|
+
!ignoreAuthor && (getAuthor(propertyComment) || getAuthor(baseComment))
|
|
184
|
+
]);
|
|
185
|
+
});
|
|
186
|
+
let hasAuthor = false, hasVersion = false, hasInitial = false, hasComment = false;
|
|
187
|
+
rowsData.forEach((row)=>{
|
|
188
|
+
if (!ignoreComment && row[2]) {
|
|
189
|
+
hasComment = true;
|
|
190
|
+
}
|
|
191
|
+
if (!ignoreInitial && row[4]) {
|
|
192
|
+
hasInitial = true;
|
|
193
|
+
}
|
|
194
|
+
if (!ignoreVersion && row[5]) {
|
|
195
|
+
hasVersion = true;
|
|
196
|
+
}
|
|
197
|
+
if (!ignoreAuthor && row[6]) {
|
|
198
|
+
hasAuthor = true;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
markdownContent += '\n';
|
|
202
|
+
const cols = [
|
|
203
|
+
'属性',
|
|
204
|
+
!ignoreOptional && '必要',
|
|
205
|
+
hasComment && '说明',
|
|
206
|
+
'类型',
|
|
207
|
+
hasInitial && '默认值',
|
|
208
|
+
hasVersion && '版本',
|
|
209
|
+
hasAuthor && '作者'
|
|
210
|
+
].filter(Boolean).join('|');
|
|
211
|
+
markdownContent += `|${cols}|`;
|
|
212
|
+
const algins = [
|
|
213
|
+
':-',
|
|
214
|
+
!ignoreOptional && ':-',
|
|
215
|
+
hasComment && ':-',
|
|
216
|
+
':-',
|
|
217
|
+
hasInitial && ':-',
|
|
218
|
+
hasVersion && ':-',
|
|
219
|
+
hasAuthor && ':-'
|
|
220
|
+
].filter(Boolean);
|
|
221
|
+
markdownContent += '\n';
|
|
222
|
+
const alignStr = algins.join('|');
|
|
223
|
+
markdownContent += `|${alignStr}|`;
|
|
224
|
+
rowsData.forEach((row)=>{
|
|
225
|
+
markdownContent += '\n';
|
|
226
|
+
const rowStr = [
|
|
227
|
+
row[0] || '-',
|
|
228
|
+
!ignoreOptional && (row[1] || '-'),
|
|
229
|
+
hasComment && (row[2] || '-'),
|
|
230
|
+
row[3] || '-',
|
|
231
|
+
hasInitial && (row[4] || '-'),
|
|
232
|
+
hasVersion && (row[5] || '-'),
|
|
233
|
+
hasAuthor && (row[6] || '-')
|
|
234
|
+
].filter(Boolean).join('|');
|
|
235
|
+
markdownContent += `|${rowStr}|`;
|
|
236
|
+
});
|
|
237
|
+
markdownContent += '\n';
|
|
238
|
+
}
|
|
239
|
+
markdownContent += '\n';
|
|
240
|
+
return markdownContent;
|
|
241
|
+
}
|
|
242
|
+
function generateEnumDocumentation(node) {
|
|
243
|
+
const enumName = node.name.text;
|
|
244
|
+
Object.assign(allType, {
|
|
245
|
+
[node.name.text]: dirname(node.getSourceFile().fileName).replace(alias['@pkg'], '')
|
|
246
|
+
});
|
|
247
|
+
const baseComment = getPropertyComment(node);
|
|
248
|
+
const ignore = getIgnore(baseComment)?.split('|') || [];
|
|
249
|
+
const ignoreComment = ignore.includes('comment');
|
|
250
|
+
const ignoreVersion = ignore.includes('version');
|
|
251
|
+
const ignoreAuthor = ignore.includes('author');
|
|
252
|
+
let markdownContent = `## ${enumName}`;
|
|
253
|
+
if (node.members.length) {
|
|
254
|
+
const rowsData = [];
|
|
255
|
+
node.members.forEach((member)=>{
|
|
256
|
+
let name = replaceText(member.name.getText());
|
|
257
|
+
const memberComment = getPropertyComment(member);
|
|
258
|
+
const value = replaceText(getMemberValue(member));
|
|
259
|
+
const version = replaceText(getVersionFromComment(memberComment));
|
|
260
|
+
const comment = replaceText(getComment(memberComment));
|
|
261
|
+
if (name && !name.startsWith('\\color') && !/^("|')(.+)("|')$/.test(name)) {
|
|
262
|
+
name = `\\color{#4c81db}{${name}}`;
|
|
263
|
+
}
|
|
264
|
+
rowsData.push([
|
|
265
|
+
name,
|
|
266
|
+
!ignoreComment && comment,
|
|
267
|
+
value,
|
|
268
|
+
!ignoreVersion && version,
|
|
269
|
+
!ignoreAuthor && (getAuthor(memberComment) || getAuthor(baseComment))
|
|
270
|
+
]);
|
|
271
|
+
});
|
|
272
|
+
let hasAuthor = false, hasVersion = false, hasComment = false;
|
|
273
|
+
rowsData.forEach((row)=>{
|
|
274
|
+
if (!ignoreComment && row[1]) {
|
|
275
|
+
hasComment = true;
|
|
276
|
+
}
|
|
277
|
+
if (!ignoreVersion && row[3]) {
|
|
278
|
+
hasVersion = true;
|
|
279
|
+
}
|
|
280
|
+
if (!ignoreAuthor && row[4]) {
|
|
281
|
+
hasAuthor = true;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
markdownContent += '\n';
|
|
285
|
+
const cols = [
|
|
286
|
+
'属性',
|
|
287
|
+
hasComment && '说明',
|
|
288
|
+
'值',
|
|
289
|
+
hasVersion && '版本',
|
|
290
|
+
hasAuthor && '作者'
|
|
291
|
+
].filter(Boolean).join('|');
|
|
292
|
+
markdownContent += `|${cols}|`;
|
|
293
|
+
const algins = [
|
|
294
|
+
':-',
|
|
295
|
+
hasComment && ':-',
|
|
296
|
+
':-',
|
|
297
|
+
hasVersion && ':-',
|
|
298
|
+
hasAuthor && ':-'
|
|
299
|
+
].filter(Boolean);
|
|
300
|
+
markdownContent += '\n';
|
|
301
|
+
const alignStr = algins.join('|');
|
|
302
|
+
markdownContent += `|${alignStr}|`;
|
|
303
|
+
rowsData.forEach((row)=>{
|
|
304
|
+
markdownContent += '\n';
|
|
305
|
+
const rowStr = [
|
|
306
|
+
row[0] || '-',
|
|
307
|
+
hasComment && (row[1] || '-'),
|
|
308
|
+
row[2] || '-',
|
|
309
|
+
hasVersion && (row[3] || '-'),
|
|
310
|
+
hasAuthor && (row[4] || '-')
|
|
311
|
+
].filter(Boolean).join('|');
|
|
312
|
+
markdownContent += `|${rowStr}|`;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
markdownContent += '\n';
|
|
316
|
+
markdownContent += '\n';
|
|
317
|
+
return markdownContent;
|
|
318
|
+
}
|
|
319
|
+
export default function generateApi(path) {
|
|
320
|
+
const content = readFileSync(path, 'utf-8');
|
|
321
|
+
const sourceFile = createSourceFile(path, content, ScriptTarget.Latest, true, ScriptKind.TS);
|
|
322
|
+
let markdownDocumentation = '';
|
|
323
|
+
forEachChild(sourceFile, (node)=>{
|
|
324
|
+
if (isInterfaceDeclaration(node)) {
|
|
325
|
+
markdownDocumentation += generateInterfaceDocumentation(node);
|
|
326
|
+
} else if (ts.isEnumDeclaration(node)) {
|
|
327
|
+
markdownDocumentation += generateEnumDocumentation(node);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
return markdownDocumentation;
|
|
331
|
+
}
|
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,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
|
+
class AddEntryAttributeWebpackPlugin {
|
|
3
|
+
entryMatchCallback;
|
|
4
|
+
constructor(matchCallback){
|
|
5
|
+
this.entryMatchCallback = matchCallback;
|
|
6
|
+
}
|
|
7
|
+
apply(compiler) {
|
|
8
|
+
compiler.hooks.compilation.tap('AddEntryAttributeWebpackPlugin', (compilation)=>{
|
|
9
|
+
const HtmlWebpackPluginInstance = compiler.options.plugins.find((p)=>p instanceof HtmlWebpackPlugin);
|
|
10
|
+
if (HtmlWebpackPluginInstance) {
|
|
11
|
+
const hooks = HtmlWebpackPluginInstance.getHooks(compilation);
|
|
12
|
+
hooks.alterAssetTagGroups.tap('AddEntryAttributeWebpackPlugin', (data)=>{
|
|
13
|
+
data.headTags.forEach((tag)=>{
|
|
14
|
+
if (tag.tagName === 'script' && typeof tag.attributes?.src === 'string' && this.entryMatchCallback(tag.attributes.src)) {
|
|
15
|
+
tag.attributes.entry = true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return data;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
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 { PACKAGENAME, PROGRAMPATH, pkgName, programInfo } 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
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
|
+
}
|