@moneko/core 3.2.1-beta.2 → 3.2.1-beta.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/lib/app-entry.js +1 -32
- package/lib/app.js +2 -40
- package/lib/cleanup.js +1 -19
- package/lib/common.js +1 -248
- package/lib/config.js +1 -234
- package/lib/coverage.js +2 -33
- package/lib/dev.js +5 -89
- package/lib/docs.js +2 -120
- package/lib/done.js +1 -12
- package/lib/esm.js +1 -7
- package/lib/fallback.js +1 -6
- package/lib/generate-api.js +3 -345
- package/lib/has-pkg.js +1 -12
- package/lib/html-add-entry-attr.js +10 -32
- package/lib/html-plugin-option.js +1 -45
- package/lib/index.js +1 -4
- package/lib/locales.js +3 -93
- package/lib/merge-router.js +1 -1
- package/lib/minify.js +2 -47
- package/lib/modify-vars.js +1 -11
- package/lib/module-federation.js +1 -46
- package/lib/module.config.js +3 -273
- package/lib/net.js +1 -33
- package/lib/normalize-css.js +1 -6
- package/lib/paths.js +1 -21
- package/lib/polyfills/replace-children.js +3 -26
- package/lib/polyfills.js +3 -15
- package/lib/prefix-router.js +1 -6
- package/lib/process-env.js +2 -33
- package/lib/prod.js +5 -65
- package/lib/reactive-object.js +8 -47
- package/lib/rem.js +1 -6
- package/lib/resolver-sync.js +1 -27
- package/lib/routes.js +4 -196
- package/lib/seo.js +2 -41
- package/lib/swcrc.js +2 -100
- package/lib/tsloader.config.js +2 -26
- package/lib/utils.js +7 -71
- package/lib/virtual-module-plugin.js +1 -49
- package/lib/virtual-modules.js +1 -37
- package/lib/yarn-argv.js +1 -9
- package/package.json +2 -2
package/lib/app-entry.js
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { CONFIG } from './config.js';
|
|
4
|
-
import { APPTYPE, FRAMEWORK, isMicro } from './process-env.js';
|
|
5
|
-
import rem from './rem.js';
|
|
6
|
-
import { getExportTokens } from './utils.js';
|
|
7
|
-
const entryPath = join(CONFIG.alias['@'], './index.ts');
|
|
8
|
-
const hasEntry = existsSync(entryPath);
|
|
9
|
-
let prefixStr = '', suffixStr = `const renderApp = (await import('@moneko/${FRAMEWORK}/lib/entry.js')).default;`;
|
|
10
|
-
let im = [];
|
|
11
|
-
if (hasEntry) {
|
|
12
|
-
let exported = '';
|
|
13
|
-
if (isMicro) {
|
|
14
|
-
im = getExportTokens(entryPath).filter(Boolean);
|
|
15
|
-
if (im.length) {
|
|
16
|
-
exported = `{${im.map((m)=>`${m} as app${m}`).join(',')}} from `;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
prefixStr = `import ${exported}"@/index.ts";`;
|
|
20
|
-
}
|
|
21
|
-
prefixStr += `import "@app/normalize/index.css";${rem}`;
|
|
22
|
-
if (isMicro) {
|
|
23
|
-
prefixStr += 'if (window.__POWERED_BY_QIANKUN__) {__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;}';
|
|
24
|
-
suffixStr += `if (!window.__POWERED_BY_QIANKUN__) {renderApp();}let unmountApp = void 0;export async function bootstrap() {console.log('app bootstraped');}export async function mount(props) {${im.includes('mount') ? 'appmount(props);' : ''}unmountApp = renderApp(props);}export async function unmount(props) {${im.includes('unmount') ? 'appunmount(props);' : ''}unmountApp();}`;
|
|
25
|
-
} else {
|
|
26
|
-
suffixStr += 'renderApp();';
|
|
27
|
-
}
|
|
28
|
-
if (APPTYPE === 'mobile') {
|
|
29
|
-
suffixStr += 'window.H5RemoteRuntime = {bootstrap: renderApp};';
|
|
30
|
-
}
|
|
31
|
-
const appEntry = `${prefixStr}${suffixStr}`;
|
|
32
|
-
export default appEntry;
|
|
1
|
+
import{existsSync as o}from"fs";import{join as p}from"path";import{CONFIG as n}from"./config.js";import{APPTYPE as t,FRAMEWORK as r,isMicro as e}from"./process-env.js";import i from"./rem.js";import{getExportTokens as m}from"./utils.js";let s=p(n.alias["@"],"./index.ts"),_=o(s),u="",a=`const renderApp = (await import('@moneko/${r}/lib/entry.js')).default;`,l=[];if(_){let o="";e&&(l=m(s).filter(Boolean)).length&&(o=`{${l.map(o=>`${o} as app${o}`).join(",")}} from `),u=`import ${o}"@/index.ts";`}u+=`import "@app/normalize/index.css";${i}`,e?(u+="if (window.__POWERED_BY_QIANKUN__) {__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;}",a+=`if (!window.__POWERED_BY_QIANKUN__) {renderApp();}let unmountApp = void 0;export async function bootstrap() {console.log('app bootstraped');}export async function mount(props) {${l.includes("mount")?"appmount(props);":""}unmountApp = renderApp(props);}export async function unmount(props) {${l.includes("unmount")?"appunmount(props);":""}unmountApp();}`):a+="renderApp();","mobile"===t&&(a+="window.H5RemoteRuntime = {bootstrap: renderApp};");let d=`${u}${a}`;export default d;
|
package/lib/app.js
CHANGED
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { APPTYPE, PACKAGENAME, PACKAGEVERSION } from './process-env.js';
|
|
4
|
-
import { resolveProgramPath, toUpperCaseString } from './utils.js';
|
|
5
|
-
const app = {
|
|
6
|
-
name: PACKAGENAME,
|
|
7
|
-
projectName: JSON.stringify(toUpperCaseString(PACKAGENAME).replace(/-/g, ' ')),
|
|
8
|
-
version: PACKAGEVERSION,
|
|
9
|
-
base: CONFIG.basename,
|
|
10
|
-
type: APPTYPE,
|
|
11
|
-
routerMode: CONFIG.routerMode,
|
|
12
|
-
prefixCls: CONFIG.prefixCls,
|
|
13
|
-
theme: CONFIG.theme,
|
|
14
|
-
description: process.env.npm_package_description,
|
|
15
|
-
author: {
|
|
16
|
-
name: process.env.npm_package_author_name,
|
|
17
|
-
email: process.env.npm_package_author_email,
|
|
18
|
-
url: process.env.npm_package_author_url
|
|
19
|
-
},
|
|
20
|
-
repository: {
|
|
21
|
-
type: process.env.npm_package_repository_type,
|
|
22
|
-
url: process.env.npm_package_repository_url,
|
|
23
|
-
directory: process.env.npm_package_repository_directory
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
// node 16
|
|
27
|
-
if (parseInt(process.versions.node) > 14) {
|
|
28
|
-
const ikpg = readFileSync(resolveProgramPath('package.json'), {
|
|
29
|
-
encoding: 'utf-8'
|
|
30
|
-
});
|
|
31
|
-
const { description, author, repository } = JSON.parse(ikpg);
|
|
32
|
-
app.author = typeof author === 'string' ? {
|
|
33
|
-
name: author
|
|
34
|
-
} : author;
|
|
35
|
-
app.repository = typeof author === 'string' ? {
|
|
36
|
-
url: repository
|
|
37
|
-
} : repository;
|
|
38
|
-
app.description = description;
|
|
39
|
-
}
|
|
40
|
-
export default app;
|
|
1
|
+
import{readFileSync as e}from"fs";import{CONFIG as r}from"./config.js";import{APPTYPE as o,PACKAGENAME as p,PACKAGEVERSION as s}from"./process-env.js";import{resolveProgramPath as t,toUpperCaseString as a}from"./utils.js";let n={name:p,projectName:JSON.stringify(a(p).replace(/-/g," ")),version:s,base:r.basename,type:o,routerMode:r.routerMode,prefixCls:r.prefixCls,theme:r.theme,description:process.env.npm_package_description,author:{name:process.env.npm_package_author_name,email:process.env.npm_package_author_email,url:process.env.npm_package_author_url},repository:{type:process.env.npm_package_repository_type,url:process.env.npm_package_repository_url,directory:process.env.npm_package_repository_directory}};// node 16
|
|
2
|
+
if(parseInt(process.versions.node)>14){let r=e(t("package.json"),{encoding:"utf-8"}),{description:o,author:p,repository:s}=JSON.parse(r);n.author="string"==typeof p?{name:p}:p,n.repository="string"==typeof p?{url:s}:s,n.description=o}export default n;
|
package/lib/cleanup.js
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import paths from './paths.js';
|
|
4
|
-
function cleanDir(folderPath) {
|
|
5
|
-
if (existsSync(folderPath)) {
|
|
6
|
-
readdirSync(folderPath).forEach((file)=>{
|
|
7
|
-
const filePath = join(folderPath, file);
|
|
8
|
-
if (statSync(filePath).isDirectory()) {
|
|
9
|
-
cleanDir(filePath);
|
|
10
|
-
} else {
|
|
11
|
-
unlinkSync(filePath);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
rmdirSync(folderPath);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
process.on('exit', function() {
|
|
18
|
-
cleanDir(paths.cachePath);
|
|
19
|
-
});
|
|
1
|
+
import{existsSync as o,readdirSync as t,rmdirSync as r,statSync as i,unlinkSync as c}from"fs";import{join as f}from"path";import m from"./paths.js";process.on("exit",function(){!function m(p){o(p)&&(t(p).forEach(o=>{let t=f(p,o);i(t).isDirectory()?m(t):c(t)}),r(p))}(m.cachePath)});
|
package/lib/common.js
CHANGED
|
@@ -1,248 +1 @@
|
|
|
1
|
-
import fs from '
|
|
2
|
-
import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin';
|
|
3
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
4
|
-
import webpack from 'webpack';
|
|
5
|
-
import WebpackBar from 'webpackbar';
|
|
6
|
-
import './cleanup.js';
|
|
7
|
-
import { CONFIG, PUBLICPATH } from './config.js';
|
|
8
|
-
import DoneWebpackPlugin from './done.js';
|
|
9
|
-
import AddEntryAttributeWebpackPlugin from './html-add-entry-attr.js';
|
|
10
|
-
import htmlPluginOption from './html-plugin-option.js';
|
|
11
|
-
import { moduleFederation } from './module-federation.js';
|
|
12
|
-
import moduleConfig from './module.config.js';
|
|
13
|
-
import paths from './paths.js';
|
|
14
|
-
import { CUSTOMCONFIG, PACKAGENAME, PACKAGEVERSION, hasEslintConfig, hasStylelintConfig, isDev, isLibrary, isMicro } from './process-env.js';
|
|
15
|
-
import { seo } from './seo.js';
|
|
16
|
-
import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
|
|
17
|
-
import VirtualModulePlugin from './virtual-module-plugin.js';
|
|
18
|
-
import virtualModules from './virtual-modules.js';
|
|
19
|
-
const { AutomaticPrefetchPlugin, DefinePlugin, SourceMapDevToolPlugin, WatchIgnorePlugin } = webpack;
|
|
20
|
-
const eslintrc = [
|
|
21
|
-
'.eslintrc.js',
|
|
22
|
-
'.eslintrc.json',
|
|
23
|
-
'.eslintrc.yaml',
|
|
24
|
-
'.eslintrc.json'
|
|
25
|
-
];
|
|
26
|
-
const stylelintrc = [
|
|
27
|
-
'.stylelintrc',
|
|
28
|
-
'.stylelintrc.json',
|
|
29
|
-
'.stylelintrc.yaml',
|
|
30
|
-
'.stylelintrc.yml',
|
|
31
|
-
'.stylelintrc.js',
|
|
32
|
-
'stylelint.config.js',
|
|
33
|
-
'stylelint.config.cjs'
|
|
34
|
-
];
|
|
35
|
-
const rootFiles = fs.readdirSync(paths.programPath);
|
|
36
|
-
let hasEslint = false, hasStylelint = false;
|
|
37
|
-
for(let i = 0, len = rootFiles.length; i < len; i++){
|
|
38
|
-
if (stylelintrc.includes(rootFiles[i])) {
|
|
39
|
-
hasStylelint = true;
|
|
40
|
-
}
|
|
41
|
-
if (eslintrc.includes(rootFiles[i])) {
|
|
42
|
-
hasEslint = true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!hasEslint) {
|
|
46
|
-
hasEslint = hasEslintConfig;
|
|
47
|
-
}
|
|
48
|
-
if (!hasStylelint) {
|
|
49
|
-
hasStylelint = hasStylelintConfig;
|
|
50
|
-
}
|
|
51
|
-
const StylelintPlugin = hasStylelint ? (await import('stylelint-webpack-plugin')).default : null;
|
|
52
|
-
const ESLintPlugin = hasEslint ? (await import('eslint-webpack-plugin')).default : null;
|
|
53
|
-
const assetHtmlOption = CONFIG.assetHtml.map((item)=>{
|
|
54
|
-
return {
|
|
55
|
-
publicPath: '',
|
|
56
|
-
...item
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
export const outputConfig = {
|
|
60
|
-
path: resolveProgramPath(isLibrary ? 'docs' : 'dist'),
|
|
61
|
-
filename: 'js/[name].bundle.js',
|
|
62
|
-
chunkFilename: `js/[${isDev ? 'name' : 'chunkhash'}].js`,
|
|
63
|
-
assetModuleFilename: (pathData)=>{
|
|
64
|
-
const filename = pathData.filename;
|
|
65
|
-
if (filename && filename.endsWith('?url')) {
|
|
66
|
-
if (/(?:webworker|worker)(\.|\b).*\.(js|ts)\b/.test(filename.replace('?url', ''))) {
|
|
67
|
-
return 'worker/[name][ext]';
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return 'assets/[name][hash][ext]';
|
|
71
|
-
},
|
|
72
|
-
library: {
|
|
73
|
-
name: PACKAGENAME,
|
|
74
|
-
type: 'window'
|
|
75
|
-
},
|
|
76
|
-
globalObject: 'window',
|
|
77
|
-
chunkLoadingGlobal: `webpackJsonp_${PACKAGENAME}`,
|
|
78
|
-
pathinfo: isDev,
|
|
79
|
-
clean: true,
|
|
80
|
-
publicPath: PUBLICPATH,
|
|
81
|
-
asyncChunks: true,
|
|
82
|
-
charset: true
|
|
83
|
-
};
|
|
84
|
-
let entryMap = {
|
|
85
|
-
main: resolveNodeModulesPath('@app/entry')
|
|
86
|
-
};
|
|
87
|
-
if (CONFIG.polyfill) {
|
|
88
|
-
Object.assign(entryMap, {
|
|
89
|
-
'dom-polyfills': [
|
|
90
|
-
`${paths.corePath}/polyfills/replace-children.js`
|
|
91
|
-
]
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
if (CONFIG.entry) {
|
|
95
|
-
if (typeof CONFIG.entry === 'string') {
|
|
96
|
-
entryMap = {
|
|
97
|
-
main: CONFIG.entry
|
|
98
|
-
};
|
|
99
|
-
} else if (Object.keys(CONFIG.entry)) {
|
|
100
|
-
Object.assign(entryMap, CONFIG.entry);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (CONFIG.output) {
|
|
104
|
-
if (typeof CONFIG.output === 'string') {
|
|
105
|
-
outputConfig.path = CONFIG.output;
|
|
106
|
-
} else if (Object.keys(CONFIG.output)) {
|
|
107
|
-
Object.assign(outputConfig, CONFIG.output);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const dirDeep = CONFIG.basename.split('/').filter(Boolean).length;
|
|
111
|
-
const page404 = `${Array(dirDeep).fill('..').join('/') + (dirDeep ? '/' : '')}404.html`;
|
|
112
|
-
const { pathSegmentsToKeep = dirDeep, path = page404 } = CONFIG.fixBrowserRouter || {};
|
|
113
|
-
let cacheConfig = false;
|
|
114
|
-
if (CONFIG.cacheDirectory) {
|
|
115
|
-
cacheConfig = {
|
|
116
|
-
type: 'filesystem',
|
|
117
|
-
store: 'pack',
|
|
118
|
-
allowCollectingMemory: true,
|
|
119
|
-
cacheDirectory: CONFIG.cacheDirectory,
|
|
120
|
-
memoryCacheUnaffected: true,
|
|
121
|
-
name: `${CUSTOMCONFIG || 'default'}-${isDev ? 'development' : 'production'}`,
|
|
122
|
-
version: PACKAGEVERSION
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const plugins = [
|
|
126
|
-
new AutomaticPrefetchPlugin(),
|
|
127
|
-
...moduleFederation,
|
|
128
|
-
ESLintPlugin && new ESLintPlugin({
|
|
129
|
-
fix: true,
|
|
130
|
-
threads: true,
|
|
131
|
-
extensions: [
|
|
132
|
-
'js',
|
|
133
|
-
'md',
|
|
134
|
-
'mdx',
|
|
135
|
-
'cjs',
|
|
136
|
-
'ejs',
|
|
137
|
-
'mjs',
|
|
138
|
-
'jsx',
|
|
139
|
-
'ts',
|
|
140
|
-
'tsx',
|
|
141
|
-
'json',
|
|
142
|
-
'html',
|
|
143
|
-
'coffee',
|
|
144
|
-
'vue'
|
|
145
|
-
]
|
|
146
|
-
}),
|
|
147
|
-
StylelintPlugin && new StylelintPlugin({
|
|
148
|
-
fix: true,
|
|
149
|
-
threads: true,
|
|
150
|
-
extensions: [
|
|
151
|
-
'css',
|
|
152
|
-
'scss',
|
|
153
|
-
'sass',
|
|
154
|
-
'less',
|
|
155
|
-
'ts',
|
|
156
|
-
'tsx',
|
|
157
|
-
'js',
|
|
158
|
-
'jsx'
|
|
159
|
-
],
|
|
160
|
-
exclude: [
|
|
161
|
-
'node_modules/',
|
|
162
|
-
'es/',
|
|
163
|
-
'lib/',
|
|
164
|
-
'docs/',
|
|
165
|
-
'coverage/',
|
|
166
|
-
'dist/'
|
|
167
|
-
]
|
|
168
|
-
}),
|
|
169
|
-
CONFIG.htmlPluginOption && new HtmlWebpackPlugin(htmlPluginOption),
|
|
170
|
-
CONFIG.fixBrowserRouter && new HtmlWebpackPlugin({
|
|
171
|
-
filename: path,
|
|
172
|
-
inject: false,
|
|
173
|
-
templateContent: ()=>`<html lang="en"><head><title>${htmlPluginOption.title}</title><script>const pathKeep = ${pathSegmentsToKeep || dirDeep};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`
|
|
174
|
-
}),
|
|
175
|
-
new AddAssetHtmlPlugin(assetHtmlOption),
|
|
176
|
-
isMicro && new AddEntryAttributeWebpackPlugin((src)=>{
|
|
177
|
-
return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
|
|
178
|
-
}),
|
|
179
|
-
new DefinePlugin({
|
|
180
|
-
'process.env': JSON.stringify(CONFIG.env)
|
|
181
|
-
}),
|
|
182
|
-
new WatchIgnorePlugin({
|
|
183
|
-
paths: [
|
|
184
|
-
/\.d\.ts$/
|
|
185
|
-
]
|
|
186
|
-
}),
|
|
187
|
-
CONFIG.sourceMap && new SourceMapDevToolPlugin(CONFIG.sourceMap),
|
|
188
|
-
CONFIG.bar && new WebpackBar(CONFIG.bar),
|
|
189
|
-
new DoneWebpackPlugin({
|
|
190
|
-
done: ()=>{
|
|
191
|
-
if (!isDev && CONFIG.seo) {
|
|
192
|
-
seo();
|
|
193
|
-
}
|
|
194
|
-
CONFIG.done?.();
|
|
195
|
-
if (!isDev) {
|
|
196
|
-
setTimeout(()=>{
|
|
197
|
-
process.exit(0);
|
|
198
|
-
}, 2000);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}),
|
|
202
|
-
new VirtualModulePlugin(virtualModules),
|
|
203
|
-
...CONFIG.plugins
|
|
204
|
-
].filter((p)=>!!p);
|
|
205
|
-
export const clientConfig = {
|
|
206
|
-
entry: entryMap,
|
|
207
|
-
stats: 'errors-only',
|
|
208
|
-
cache: cacheConfig,
|
|
209
|
-
infrastructureLogging: {
|
|
210
|
-
level: 'none'
|
|
211
|
-
},
|
|
212
|
-
target: 'web',
|
|
213
|
-
externalsPresets: CONFIG.externalsPresets,
|
|
214
|
-
plugins: plugins,
|
|
215
|
-
experiments: {
|
|
216
|
-
topLevelAwait: true,
|
|
217
|
-
asyncWebAssembly: true,
|
|
218
|
-
cacheUnaffected: true,
|
|
219
|
-
layers: true,
|
|
220
|
-
lazyCompilation: isDev && {
|
|
221
|
-
imports: false,
|
|
222
|
-
entries: false
|
|
223
|
-
},
|
|
224
|
-
buildHttp: CONFIG.buildHttp,
|
|
225
|
-
backCompat: true,
|
|
226
|
-
futureDefaults: false,
|
|
227
|
-
css: false,
|
|
228
|
-
outputModule: false
|
|
229
|
-
},
|
|
230
|
-
resolve: {
|
|
231
|
-
extensions: [
|
|
232
|
-
'.tsx',
|
|
233
|
-
'.ts',
|
|
234
|
-
'.js',
|
|
235
|
-
'.jsx'
|
|
236
|
-
],
|
|
237
|
-
alias: CONFIG.alias,
|
|
238
|
-
fallback: {
|
|
239
|
-
path: false,
|
|
240
|
-
fs: false,
|
|
241
|
-
crypto: false,
|
|
242
|
-
assert: false
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
module: moduleConfig,
|
|
246
|
-
externals: CONFIG.externals,
|
|
247
|
-
output: outputConfig
|
|
248
|
-
};
|
|
1
|
+
import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import l from"webpack";import o from"webpackbar";import"./cleanup.js";import{CONFIG as n,PUBLICPATH as r}from"./config.js";import i from"./done.js";import a from"./html-add-entry-attr.js";import p from"./html-plugin-option.js";import{moduleFederation as c}from"./module-federation.js";import m from"./module.config.js";import u from"./paths.js";import{CUSTOMCONFIG as f,PACKAGENAME as d,PACKAGEVERSION as h,hasEslintConfig as j,hasStylelintConfig as y,isDev as b,isLibrary as g,isMicro as w}from"./process-env.js";import{seo as x}from"./seo.js";import{resolveNodeModulesPath as k,resolveProgramPath as v}from"./utils.js";import C from"./virtual-module-plugin.js";import $ from"./virtual-modules.js";let{AutomaticPrefetchPlugin:O,DefinePlugin:P,SourceMapDevToolPlugin:M,WatchIgnorePlugin:D}=l,A=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],B=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],H=e.readdirSync(u.programPath),K=!1,L=!1;for(let e=0,t=H.length;e<t;e++)B.includes(H[e])&&(L=!0),A.includes(H[e])&&(K=!0);K||(K=j),L||(L=y);let F=L?(await import("stylelint-webpack-plugin")).default:null,J=K?(await import("eslint-webpack-plugin")).default:null,R=n.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:v(g?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:`js/[${b?"name":"chunkhash"}].js`,assetModuleFilename:e=>{let t=e.filename;return t&&t.endsWith("?url")&&/(?:webworker|worker)(\.|\b).*\.(js|ts)\b/.test(t.replace("?url",""))?"worker/[name][ext]":"assets/[name][hash][ext]"},library:{name:d,type:"window"},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${d}`,pathinfo:b,clean:!0,publicPath:r,asyncChunks:!0,charset:!0};let S={main:k("@app/entry")};n.polyfill&&Object.assign(S,{"dom-polyfills":[`${u.corePath}/polyfills/replace-children.js`]}),n.entry&&("string"==typeof n.entry?S={main:n.entry}:Object.keys(n.entry)&&Object.assign(S,n.entry)),n.output&&("string"==typeof n.output?outputConfig.path=n.output:Object.keys(n.output)&&Object.assign(outputConfig,n.output));let U=n.basename.split("/").filter(Boolean).length,W=`${Array(U).fill("..").join("/")+(U?"/":"")}404.html`,{pathSegmentsToKeep:_=U,path:z=W}=n.fixBrowserRouter||{},G=!1;n.cacheDirectory&&(G={type:"filesystem",store:"pack",allowCollectingMemory:!0,cacheDirectory:n.cacheDirectory,memoryCacheUnaffected:!0,name:`${f||"default"}-${b?"development":"production"}`,version:h});let N=[new O,...c,J&&new J({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"]}),F&&new F({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","docs/","coverage/","dist/"]}),n.htmlPluginOption&&new s(p),n.fixBrowserRouter&&new s({filename:z,inject:!1,templateContent:()=>`<html lang="en"><head><title>${p.title}</title><script>const pathKeep = ${_||U};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}),new t(R),w&&new a(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new P({"process.env":JSON.stringify(n.env)}),new D({paths:[/\.d\.ts$/]}),n.sourceMap&&new M(n.sourceMap),n.bar&&new o(n.bar),new i({done:()=>{!b&&n.seo&&x(),n.done?.(),b||setTimeout(()=>{process.exit(0)},2e3)}}),new C($),...n.plugins].filter(e=>!!e);export const clientConfig={entry:S,stats:"errors-only",cache:G,infrastructureLogging:{level:"none"},target:"web",externalsPresets:n.externalsPresets,plugins:N,experiments:{topLevelAwait:!0,asyncWebAssembly:!0,cacheUnaffected:!0,layers:!0,lazyCompilation:b&&{imports:!1,entries:!1},buildHttp:n.buildHttp,backCompat:!0,futureDefaults:!1,css:!1,outputModule:!1},resolve:{extensions:[".tsx",".ts",".js",".jsx"],alias:n.alias,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:m,externals:n.externals,output:outputConfig};
|
package/lib/config.js
CHANGED
|
@@ -1,234 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import readline from 'readline';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { merge } from 'webpack-merge';
|
|
5
|
-
import paths from './paths.js';
|
|
6
|
-
import { APPTYPE, CUSTOMCONFIG, FRAMEWORK, PACKAGENAME, coreName, jsxImportSource } from './process-env.js';
|
|
7
|
-
import { isFunction, readConf, resolveProgramPath } from './utils.js';
|
|
8
|
-
const includeModule = [
|
|
9
|
-
'@moneko/core',
|
|
10
|
-
`@moneko/${FRAMEWORK}`,
|
|
11
|
-
'neko-ui',
|
|
12
|
-
'antd',
|
|
13
|
-
'@antv',
|
|
14
|
-
'katex',
|
|
15
|
-
'font-pingfang-sc',
|
|
16
|
-
'font-pingfang-tc',
|
|
17
|
-
'react-photo-view',
|
|
18
|
-
'react-markdown-editor-lite',
|
|
19
|
-
'schema-design',
|
|
20
|
-
'@app',
|
|
21
|
-
'.cache/http/data'
|
|
22
|
-
];
|
|
23
|
-
const defaultSplitChunk = {
|
|
24
|
-
chunks: 'all',
|
|
25
|
-
minSize: 1024,
|
|
26
|
-
minChunks: 1,
|
|
27
|
-
cacheGroups: {
|
|
28
|
-
route: {
|
|
29
|
-
test: /[\\/].git[\\/]router/,
|
|
30
|
-
priority: -10,
|
|
31
|
-
reuseExistingChunk: true,
|
|
32
|
-
name: 'route'
|
|
33
|
-
},
|
|
34
|
-
example: {
|
|
35
|
-
test: /[\\/].git[\\/]example/,
|
|
36
|
-
priority: -10,
|
|
37
|
-
reuseExistingChunk: true,
|
|
38
|
-
name: 'example'
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const defaultAlias = {
|
|
43
|
-
library: {
|
|
44
|
-
'@': resolveProgramPath('site'),
|
|
45
|
-
'@pkg': resolveProgramPath('components'),
|
|
46
|
-
[PACKAGENAME]: resolveProgramPath('components')
|
|
47
|
-
},
|
|
48
|
-
mobile: {},
|
|
49
|
-
site: {},
|
|
50
|
-
backstage: {},
|
|
51
|
-
micro: {}
|
|
52
|
-
};
|
|
53
|
-
const defaultConfig = {
|
|
54
|
-
seo: false,
|
|
55
|
-
mode: 'csr',
|
|
56
|
-
compiler: 'swc',
|
|
57
|
-
bundleAnalyzer: false,
|
|
58
|
-
polyfill: false,
|
|
59
|
-
entry: {},
|
|
60
|
-
minifier: {
|
|
61
|
-
js: {},
|
|
62
|
-
css: {}
|
|
63
|
-
},
|
|
64
|
-
sourceMap: {
|
|
65
|
-
filename: '[file].map',
|
|
66
|
-
publicPath: ''
|
|
67
|
-
},
|
|
68
|
-
env: {
|
|
69
|
-
NODE_ENV: process.env.NODE_ENV
|
|
70
|
-
},
|
|
71
|
-
basename: '/',
|
|
72
|
-
publicPath: '/',
|
|
73
|
-
rem: {
|
|
74
|
-
designSize: APPTYPE === 'mobile' ? 375 : 1680
|
|
75
|
-
},
|
|
76
|
-
fallbackCompPath: null,
|
|
77
|
-
modifyVars: {},
|
|
78
|
-
prefixCls: 'n',
|
|
79
|
-
alias: Object.assign({
|
|
80
|
-
'@': resolveProgramPath('src')
|
|
81
|
-
}, defaultAlias[APPTYPE]),
|
|
82
|
-
moduleRules: [],
|
|
83
|
-
prefixJsLoader: [],
|
|
84
|
-
cssModules: [],
|
|
85
|
-
importOnDemand: {},
|
|
86
|
-
proxy: [],
|
|
87
|
-
cacheDirectory: paths.webpackCachePath,
|
|
88
|
-
devServer: {
|
|
89
|
-
allowedHosts: [
|
|
90
|
-
'.baidu.com'
|
|
91
|
-
],
|
|
92
|
-
host: 'localhost',
|
|
93
|
-
port: 3000,
|
|
94
|
-
https: false,
|
|
95
|
-
compress: false
|
|
96
|
-
},
|
|
97
|
-
htmlPluginOption: {
|
|
98
|
-
template: `node_modules/${coreName}/template/index.html`,
|
|
99
|
-
favicon: `node_modules/${coreName}/template/favicon.ico`,
|
|
100
|
-
tags: []
|
|
101
|
-
},
|
|
102
|
-
assetHtml: [],
|
|
103
|
-
routerMode: 'browser',
|
|
104
|
-
fixBrowserRouter: false,
|
|
105
|
-
plugins: [],
|
|
106
|
-
splitChunk: defaultSplitChunk,
|
|
107
|
-
runtimeChunk: 'single',
|
|
108
|
-
moduleFederation: [],
|
|
109
|
-
rulesInclude: {
|
|
110
|
-
css: includeModule,
|
|
111
|
-
js: includeModule,
|
|
112
|
-
media: includeModule,
|
|
113
|
-
font: includeModule,
|
|
114
|
-
wasm: []
|
|
115
|
-
},
|
|
116
|
-
mdx: {
|
|
117
|
-
jsxImportSource: jsxImportSource,
|
|
118
|
-
useDynamicImport: true,
|
|
119
|
-
remarkPlugins: [],
|
|
120
|
-
rehypePlugins: []
|
|
121
|
-
},
|
|
122
|
-
jsxDomExpressions: {
|
|
123
|
-
moduleName: 'solid-js/web',
|
|
124
|
-
builtIns: [
|
|
125
|
-
'For',
|
|
126
|
-
'Show',
|
|
127
|
-
'Switch',
|
|
128
|
-
'Match',
|
|
129
|
-
'Suspense',
|
|
130
|
-
'SuspenseList',
|
|
131
|
-
'Portal',
|
|
132
|
-
'Index',
|
|
133
|
-
'Dynamic',
|
|
134
|
-
'ErrorBoundary'
|
|
135
|
-
],
|
|
136
|
-
contextToCustomElements: true,
|
|
137
|
-
wrapConditionals: true,
|
|
138
|
-
generate: 'dom',
|
|
139
|
-
hydratable: false
|
|
140
|
-
},
|
|
141
|
-
bar: {
|
|
142
|
-
name: '编译中',
|
|
143
|
-
color: '#6f42c1'
|
|
144
|
-
},
|
|
145
|
-
virtualModule: {},
|
|
146
|
-
normalizeCss: true,
|
|
147
|
-
externalsPresets: {},
|
|
148
|
-
buildHttp: {
|
|
149
|
-
allowedUris: [],
|
|
150
|
-
lockfileLocation: `${paths.httpCachePath}/http.lock`,
|
|
151
|
-
cacheLocation: `${paths.httpCachePath}/data`,
|
|
152
|
-
upgrade: true
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
export const log = (msg)=>{
|
|
156
|
-
readline.cursorTo(process.stdout, 0);
|
|
157
|
-
process.stdout.write(msg);
|
|
158
|
-
};
|
|
159
|
-
let customConf = defaultConfig;
|
|
160
|
-
let configPath = null;
|
|
161
|
-
let normalConf = {};
|
|
162
|
-
let envConf = {};
|
|
163
|
-
try {
|
|
164
|
-
configPath = paths.defaultConfigPath;
|
|
165
|
-
accessSync(configPath, constants.R_OK);
|
|
166
|
-
} catch (error) {
|
|
167
|
-
configPath = null;
|
|
168
|
-
}
|
|
169
|
-
if (configPath) {
|
|
170
|
-
try {
|
|
171
|
-
const conf = (await readConf(configPath, 'index')).default;
|
|
172
|
-
normalConf = isFunction(conf) ? conf(process) : conf;
|
|
173
|
-
} catch (error) {
|
|
174
|
-
process.stdout.write(chalk.red(error));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (CUSTOMCONFIG) {
|
|
178
|
-
let customConfigPath = null;
|
|
179
|
-
try {
|
|
180
|
-
customConfigPath = `${paths.programPath}/config/${CUSTOMCONFIG}.ts`;
|
|
181
|
-
accessSync(customConfigPath, constants.R_OK);
|
|
182
|
-
} catch (error) {
|
|
183
|
-
customConfigPath = null;
|
|
184
|
-
}
|
|
185
|
-
if (customConfigPath !== null) {
|
|
186
|
-
try {
|
|
187
|
-
const conf = (await readConf(customConfigPath, CUSTOMCONFIG)).default;
|
|
188
|
-
envConf = isFunction(conf) ? conf(process) : conf;
|
|
189
|
-
} catch (error) {
|
|
190
|
-
process.stdout.write(chalk.red(error));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
customConf = merge(customConf, normalConf, envConf);
|
|
195
|
-
export const isTsc = customConf.compiler === 'tsc';
|
|
196
|
-
if (isTsc && customConf.minifier) {
|
|
197
|
-
if (!customConf.minifier.js) {
|
|
198
|
-
Object.assign(customConf.minifier, {
|
|
199
|
-
js: {
|
|
200
|
-
type: 'terser'
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
if (!customConf.minifier.css) {
|
|
205
|
-
Object.assign(customConf.minifier, {
|
|
206
|
-
css: {
|
|
207
|
-
type: 'cssnano'
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (customConf.devtool === false) customConf.sourceMap = false;
|
|
213
|
-
if (customConf.sourceMap === false) customConf.devtool = false;
|
|
214
|
-
if (customConf.fixBrowserRouter && customConf.htmlPluginOption) {
|
|
215
|
-
if (!customConf.htmlPluginOption.tags) {
|
|
216
|
-
customConf.htmlPluginOption.tags = [];
|
|
217
|
-
}
|
|
218
|
-
customConf.htmlPluginOption.tags.push({
|
|
219
|
-
textContent: "(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
export const CONFIG = customConf;
|
|
223
|
-
export const PUBLICPATH = CONFIG.publicPath || '/';
|
|
224
|
-
export let hasCustomRouter;
|
|
225
|
-
try {
|
|
226
|
-
accessSync(`${CONFIG.alias['@']}/router/index.ts`, constants.R_OK);
|
|
227
|
-
hasCustomRouter = true;
|
|
228
|
-
} catch (error) {
|
|
229
|
-
hasCustomRouter = false;
|
|
230
|
-
}
|
|
231
|
-
global.NEKOCLICONFIG = {
|
|
232
|
-
CONFIG,
|
|
233
|
-
log
|
|
234
|
-
};
|
|
1
|
+
import{accessSync as e,constants as t}from"fs";import o from"readline";import s from"chalk";import{merge as r}from"webpack-merge";import i from"./paths.js";import{APPTYPE as a,CUSTOMCONFIG as n,FRAMEWORK as l,PACKAGENAME as c,coreName as m,jsxImportSource as p}from"./process-env.js";import{isFunction as u,readConf as d,resolveProgramPath as h}from"./utils.js";let f=["@moneko/core",`@moneko/${l}`,"neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],g={library:{"@":h("site"),"@pkg":h("components"),[c]:h("components")},mobile:{},site:{},backstage:{},micro:{}},x={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{NODE_ENV:process.env.NODE_ENV},basename:"/",publicPath:"/",rem:{designSize:"mobile"===a?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":h("src")},g[a]),moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:i.webpackCachePath,devServer:{allowedHosts:[".baidu.com"],host:"localhost",port:3e3,https:!1,compress:!1},htmlPluginOption:{template:`node_modules/${m}/template/index.html`,favicon:`node_modules/${m}/template/favicon.ico`,tags:[]},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],splitChunk:{chunks:"all",minSize:1024,minChunks:1,cacheGroups:{route:{test:/[\\/].git[\\/]router/,priority:-10,reuseExistingChunk:!0,name:"route"},example:{test:/[\\/].git[\\/]example/,priority:-10,reuseExistingChunk:!0,name:"example"}}},runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:f,js:f,media:f,font:f,wasm:[]},mdx:{jsxImportSource:p,useDynamicImport:!0,remarkPlugins:[],rehypePlugins:[]},jsxDomExpressions:{moduleName:"solid-js/web",builtIns:["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"],contextToCustomElements:!0,wrapConditionals:!0,generate:"dom",hydratable:!1},bar:{name:"编译中",color:"#6f42c1"},virtualModule:{},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${i.httpCachePath}/http.lock`,cacheLocation:`${i.httpCachePath}/data`,upgrade:!0}};export const log=e=>{o.cursorTo(process.stdout,0),process.stdout.write(e)};let C=x,w=null,b={},y={};try{w=i.defaultConfigPath,e(w,t.R_OK)}catch(e){w=null}if(w)try{let e=(await d(w,"index")).default;b=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}if(n){let o=null;try{o=`${i.programPath}/config/${n}.ts`,e(o,t.R_OK)}catch(e){o=null}if(null!==o)try{let e=(await d(o,n)).default;y=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}}C=r(C,b,y);export const isTsc="tsc"===C.compiler;isTsc&&C.minifier&&(C.minifier.js||Object.assign(C.minifier,{js:{type:"terser"}}),C.minifier.css||Object.assign(C.minifier,{css:{type:"cssnano"}})),!1===C.devtool&&(C.sourceMap=!1),!1===C.sourceMap&&(C.devtool=!1),C.fixBrowserRouter&&C.htmlPluginOption&&(C.htmlPluginOption.tags||(C.htmlPluginOption.tags=[]),C.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=C;export const PUBLICPATH=CONFIG.publicPath||"/";export let hasCustomRouter;try{e(`${CONFIG.alias["@"]}/router/index.ts`,t.R_OK),hasCustomRouter=!0}catch(e){hasCustomRouter=!1}global.NEKOCLICONFIG={CONFIG,log};
|
package/lib/coverage.js
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import paths from './paths.js';
|
|
4
|
-
import { PACKAGENAME, isLibrary } from './process-env.js';
|
|
5
|
-
export const coverage = {};
|
|
6
|
-
if (isLibrary) {
|
|
7
|
-
try {
|
|
8
|
-
accessSync(paths.coveragePath, constants.R_OK);
|
|
9
|
-
const parseString = new Parser({
|
|
10
|
-
explicitArray: false,
|
|
11
|
-
async: false
|
|
12
|
-
}).parseString;
|
|
13
|
-
const cover = readFileSync(paths.coveragePath, {
|
|
14
|
-
encoding: 'utf-8'
|
|
15
|
-
});
|
|
16
|
-
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) {
|
|
31
|
-
// error
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import{accessSync as e,constants as r,readFileSync as c}from"fs";import{Parser as o}from"xml2js";import t from"./paths.js";import{PACKAGENAME as a,isLibrary as s}from"./process-env.js";export const coverage={};if(s)try{e(t.coveragePath,r.R_OK);let s=new o({explicitArray:!1,async:!1}).parseString,i=c(t.coveragePath,{encoding:"utf-8"});s(i,(e,r)=>{if(!e){let e=r.coverage.project.metrics.$,c=r.coverage.project.package;Object.assign(coverage,{[a]:e}),c.forEach(e=>{Object.assign(coverage,{[e.$.name]:e.metrics.$})})}})}catch(e){// error
|
|
2
|
+
}
|