@moneko/core 3.1.0-beta.3 → 3.1.0-beta.5
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 +2 -221
- package/lib/config.js +1 -230
- package/lib/coverage.js +3 -33
- package/lib/dev.js +5 -89
- package/lib/docs.js +2 -107
- package/lib/done.js +1 -11
- package/lib/esm.js +1 -7
- package/lib/fallback.js +1 -6
- package/lib/generate-api.js +3 -341
- package/lib/has-pkg.js +1 -12
- package/lib/html-add-entry-attr.js +10 -31
- package/lib/html-plugin-option.js +1 -45
- package/lib/index.js +1 -1
- package/lib/locales.js +3 -90
- 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 -228
- package/lib/net.js +1 -33
- package/lib/normalize-css.js +1 -6
- package/lib/object-listener.js +1 -28
- package/lib/paths.js +1 -20
- package/lib/polyfills.d.ts +2 -0
- package/lib/polyfills.js +4 -0
- package/lib/prefix-router.js +1 -6
- package/lib/process-env.js +1 -33
- package/lib/prod.js +5 -64
- package/lib/rem.js +1 -6
- package/lib/resolver-sync.js +1 -27
- package/lib/routes.js +4 -209
- package/lib/seo.js +2 -41
- package/lib/swcrc.js +3 -107
- package/lib/tsloader.config.js +2 -26
- package/lib/utils.js +6 -68
- package/lib/virtual-module-plugin.js +1 -63
- package/lib/virtual-modules.js +1 -37
- package/lib/yarn-argv.js +1 -9
- package/package.json +3 -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,221 +1,2 @@
|
|
|
1
|
-
import fs from '
|
|
2
|
-
|
|
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, 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/[chunkhash].js',
|
|
63
|
-
assetModuleFilename: 'assets/[hash][ext][query]',
|
|
64
|
-
library: {
|
|
65
|
-
name: PACKAGENAME,
|
|
66
|
-
type: 'window'
|
|
67
|
-
},
|
|
68
|
-
globalObject: 'window',
|
|
69
|
-
chunkLoadingGlobal: `webpackJsonp_${PACKAGENAME}`,
|
|
70
|
-
pathinfo: isDev,
|
|
71
|
-
clean: true,
|
|
72
|
-
publicPath: PUBLICPATH,
|
|
73
|
-
asyncChunks: true
|
|
74
|
-
};
|
|
75
|
-
let entryMap = {
|
|
76
|
-
main: resolveNodeModulesPath('@app/entry')
|
|
77
|
-
};
|
|
78
|
-
if (CONFIG.entry) {
|
|
79
|
-
if (typeof CONFIG.entry === 'string') {
|
|
80
|
-
entryMap = CONFIG.entry;
|
|
81
|
-
} else if (Object.keys(CONFIG.entry)) {
|
|
82
|
-
Object.assign(entryMap, CONFIG.entry);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (CONFIG.output) {
|
|
86
|
-
if (typeof CONFIG.output === 'string') {
|
|
87
|
-
outputConfig.path = CONFIG.output;
|
|
88
|
-
} else if (Object.keys(CONFIG.output)) {
|
|
89
|
-
Object.assign(outputConfig, CONFIG.output);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const dirDeep = CONFIG.basename.split('/').filter(Boolean).length;
|
|
93
|
-
const page404 = `${Array(dirDeep).fill('..').join('/') + (dirDeep ? '/' : '')}404.html`;
|
|
94
|
-
const { pathSegmentsToKeep = dirDeep, path = page404 } = CONFIG.fixBrowserRouter || {};
|
|
95
|
-
let cacheConfig = false;
|
|
96
|
-
if (CONFIG.cacheDirectory) {
|
|
97
|
-
cacheConfig = {
|
|
98
|
-
type: 'filesystem',
|
|
99
|
-
allowCollectingMemory: true,
|
|
100
|
-
cacheDirectory: CONFIG.cacheDirectory,
|
|
101
|
-
memoryCacheUnaffected: true,
|
|
102
|
-
name: `${CUSTOMCONFIG || 'default'}-${isDev ? 'development' : 'production'}`
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
export const clientConfig = {
|
|
106
|
-
entry: entryMap,
|
|
107
|
-
stats: 'errors-only',
|
|
108
|
-
cache: cacheConfig,
|
|
109
|
-
infrastructureLogging: {
|
|
110
|
-
level: 'none'
|
|
111
|
-
},
|
|
112
|
-
target: 'web',
|
|
113
|
-
externalsPresets: CONFIG.externalsPresets,
|
|
114
|
-
plugins: [
|
|
115
|
-
new AutomaticPrefetchPlugin(),
|
|
116
|
-
...moduleFederation,
|
|
117
|
-
ESLintPlugin && new ESLintPlugin({
|
|
118
|
-
fix: true,
|
|
119
|
-
threads: true,
|
|
120
|
-
extensions: [
|
|
121
|
-
'js',
|
|
122
|
-
'md',
|
|
123
|
-
'mdx',
|
|
124
|
-
'cjs',
|
|
125
|
-
'ejs',
|
|
126
|
-
'mjs',
|
|
127
|
-
'jsx',
|
|
128
|
-
'ts',
|
|
129
|
-
'tsx',
|
|
130
|
-
'json',
|
|
131
|
-
'html',
|
|
132
|
-
'coffee',
|
|
133
|
-
'vue'
|
|
134
|
-
]
|
|
135
|
-
}),
|
|
136
|
-
StylelintPlugin && new StylelintPlugin({
|
|
137
|
-
fix: true,
|
|
138
|
-
threads: true,
|
|
139
|
-
extensions: [
|
|
140
|
-
'css',
|
|
141
|
-
'scss',
|
|
142
|
-
'sass',
|
|
143
|
-
'less',
|
|
144
|
-
'ts',
|
|
145
|
-
'tsx',
|
|
146
|
-
'js',
|
|
147
|
-
'jsx'
|
|
148
|
-
],
|
|
149
|
-
exclude: [
|
|
150
|
-
'node_modules/',
|
|
151
|
-
'es/',
|
|
152
|
-
'lib/',
|
|
153
|
-
'docs/',
|
|
154
|
-
'coverage/',
|
|
155
|
-
'dist/'
|
|
156
|
-
]
|
|
157
|
-
}),
|
|
158
|
-
CONFIG.htmlPluginOption && new HtmlWebpackPlugin(htmlPluginOption),
|
|
159
|
-
CONFIG.fixBrowserRouter && new HtmlWebpackPlugin({
|
|
160
|
-
filename: path,
|
|
161
|
-
inject: false,
|
|
162
|
-
templateContent: ()=>`<html html><head><title>${htmlPluginOption.title}</title><script>var pathSegmentsToKeep = ${pathSegmentsToKeep || dirDeep};var l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`
|
|
163
|
-
}),
|
|
164
|
-
new AddAssetHtmlPlugin(assetHtmlOption),
|
|
165
|
-
isMicro && new AddEntryAttributeWebpackPlugin((src)=>{
|
|
166
|
-
return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
|
|
167
|
-
}),
|
|
168
|
-
new DefinePlugin({
|
|
169
|
-
'process.env': JSON.stringify({
|
|
170
|
-
...CONFIG.env,
|
|
171
|
-
// mf 需要 isDev
|
|
172
|
-
NODE_ENV: process.env.NODE_ENV
|
|
173
|
-
})
|
|
174
|
-
}),
|
|
175
|
-
new WatchIgnorePlugin({
|
|
176
|
-
paths: [
|
|
177
|
-
/\.d\.ts$/
|
|
178
|
-
]
|
|
179
|
-
}),
|
|
180
|
-
CONFIG.sourceMap && new SourceMapDevToolPlugin(CONFIG.sourceMap),
|
|
181
|
-
CONFIG.bar && new WebpackBar(CONFIG.bar),
|
|
182
|
-
new DoneWebpackPlugin({
|
|
183
|
-
done: ()=>{
|
|
184
|
-
if (!isDev && CONFIG.seo) {
|
|
185
|
-
seo();
|
|
186
|
-
}
|
|
187
|
-
CONFIG.done?.();
|
|
188
|
-
if (!isDev) {
|
|
189
|
-
setTimeout(()=>{
|
|
190
|
-
process.exit(0);
|
|
191
|
-
}, 2000);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}),
|
|
195
|
-
new VirtualModulePlugin(virtualModules),
|
|
196
|
-
...CONFIG.plugins
|
|
197
|
-
].filter(Boolean),
|
|
198
|
-
experiments: {
|
|
199
|
-
topLevelAwait: true,
|
|
200
|
-
syncWebAssembly: true,
|
|
201
|
-
asyncWebAssembly: true
|
|
202
|
-
},
|
|
203
|
-
resolve: {
|
|
204
|
-
extensions: [
|
|
205
|
-
'.tsx',
|
|
206
|
-
'.ts',
|
|
207
|
-
'.js',
|
|
208
|
-
'.jsx'
|
|
209
|
-
],
|
|
210
|
-
alias: CONFIG.alias,
|
|
211
|
-
fallback: {
|
|
212
|
-
path: false,
|
|
213
|
-
fs: false,
|
|
214
|
-
crypto: false,
|
|
215
|
-
assert: false
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
module: moduleConfig,
|
|
219
|
-
externals: CONFIG.externals,
|
|
220
|
-
output: outputConfig
|
|
221
|
-
};
|
|
1
|
+
import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import o from"webpack";import n from"webpackbar";import"./cleanup.js";import{CONFIG as l,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 m}from"./module-federation.js";import c from"./module.config.js";import u from"./paths.js";import{CUSTOMCONFIG as f,PACKAGENAME as d,hasEslintConfig as h,hasStylelintConfig as j,isDev as y,isLibrary as g,isMicro as b}from"./process-env.js";import{seo as w}from"./seo.js";import{resolveNodeModulesPath as x,resolveProgramPath as v}from"./utils.js";import k from"./virtual-module-plugin.js";import C from"./virtual-modules.js";let{AutomaticPrefetchPlugin:O,DefinePlugin:$,SourceMapDevToolPlugin:P,WatchIgnorePlugin:D}=o,N=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],S=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],A=e.readdirSync(u.programPath),B=!1,E=!1;for(let e=0,t=A.length;e<t;e++)S.includes(A[e])&&(E=!0),N.includes(A[e])&&(B=!0);B||(B=h),E||(E=j);let M=E?(await import("stylelint-webpack-plugin")).default:null,T=B?(await import("eslint-webpack-plugin")).default:null,_=l.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:v(g?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:"js/[name].js",assetModuleFilename:"assets/[hash][ext][query]",library:{name:d,type:"window"},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${d}`,pathinfo:y,clean:!0,publicPath:r,asyncChunks:!0};let K={main:x("@app/entry")};l.entry&&("string"==typeof l.entry?K=l.entry:Object.keys(l.entry)&&Object.assign(K,l.entry)),l.output&&("string"==typeof l.output?outputConfig.path=l.output:Object.keys(l.output)&&Object.assign(outputConfig,l.output));let L=l.basename.split("/").filter(Boolean).length,F=`${Array(L).fill("..").join("/")+(L?"/":"")}404.html`,{pathSegmentsToKeep:J=L,path:R=F}=l.fixBrowserRouter||{},V=!1;l.cacheDirectory&&(V={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:l.cacheDirectory,memoryCacheUnaffected:!0,name:`${f||"default"}-${y?"development":"production"}`});export const clientConfig={entry:K,stats:"errors-only",cache:V,infrastructureLogging:{level:"none"},target:"web",externalsPresets:l.externalsPresets,plugins:[new O,...m,T&&new T({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"]}),M&&new M({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","docs/","coverage/","dist/"]}),l.htmlPluginOption&&new s(p),l.fixBrowserRouter&&new s({filename:R,inject:!1,templateContent:()=>`<html html><head><title>${p.title}</title><script>var pathSegmentsToKeep = ${J||L};var l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}),new t(_),b&&new a(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new $({"process.env":JSON.stringify({...l.env,// mf 需要 isDev
|
|
2
|
+
NODE_ENV:process.env.NODE_ENV})}),new D({paths:[/\.d\.ts$/]}),l.sourceMap&&new P(l.sourceMap),l.bar&&new n(l.bar),new i({done:()=>{!y&&l.seo&&w(),l.done?.(),y||setTimeout(()=>{process.exit(0)},2e3)}}),new k(C),...l.plugins].filter(Boolean),experiments:{topLevelAwait:!0,syncWebAssembly:!0,asyncWebAssembly:!0},resolve:{extensions:[".tsx",".ts",".js",".jsx"],alias:l.alias,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:c,externals:l.externals,output:outputConfig};
|
package/lib/config.js
CHANGED
|
@@ -1,230 +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, jsxImportSource, pkgName } from './process-env.js';
|
|
7
|
-
import { isFunction, readConf, resolveProgramPath } from './utils.js';
|
|
8
|
-
export const ENTRYPATH = {
|
|
9
|
-
mobile: 'mobile',
|
|
10
|
-
site: 'site',
|
|
11
|
-
backstage: 'backstage',
|
|
12
|
-
micro: 'micro',
|
|
13
|
-
library: 'library'
|
|
14
|
-
};
|
|
15
|
-
const includeModule = [
|
|
16
|
-
'@moneko/core',
|
|
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
|
-
'@app'
|
|
28
|
-
];
|
|
29
|
-
const defaultSplitChunk = {
|
|
30
|
-
chunks: 'all',
|
|
31
|
-
minSize: 1024,
|
|
32
|
-
minChunks: 1,
|
|
33
|
-
cacheGroups: {
|
|
34
|
-
route: {
|
|
35
|
-
test: /[\\/].git[\\/]router/,
|
|
36
|
-
priority: -10,
|
|
37
|
-
reuseExistingChunk: true,
|
|
38
|
-
name: 'route'
|
|
39
|
-
},
|
|
40
|
-
example: {
|
|
41
|
-
test: /[\\/].git[\\/]example/,
|
|
42
|
-
priority: -10,
|
|
43
|
-
reuseExistingChunk: true,
|
|
44
|
-
name: 'example'
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const defaultAlias = {
|
|
49
|
-
library: {
|
|
50
|
-
'@': resolveProgramPath('site'),
|
|
51
|
-
'@pkg': resolveProgramPath('components'),
|
|
52
|
-
[PACKAGENAME]: resolveProgramPath('components')
|
|
53
|
-
},
|
|
54
|
-
mobile: {},
|
|
55
|
-
site: {},
|
|
56
|
-
backstage: {},
|
|
57
|
-
micro: {}
|
|
58
|
-
};
|
|
59
|
-
const defaultConfig = {
|
|
60
|
-
seo: false,
|
|
61
|
-
mode: 'csr',
|
|
62
|
-
compiler: 'swc',
|
|
63
|
-
bundleAnalyzer: false,
|
|
64
|
-
entry: {},
|
|
65
|
-
minifier: {
|
|
66
|
-
js: {},
|
|
67
|
-
css: {}
|
|
68
|
-
},
|
|
69
|
-
sourceMap: {
|
|
70
|
-
filename: '[file].map',
|
|
71
|
-
publicPath: ''
|
|
72
|
-
},
|
|
73
|
-
env: {},
|
|
74
|
-
basename: '/',
|
|
75
|
-
publicPath: '/',
|
|
76
|
-
rem: {
|
|
77
|
-
designSize: APPTYPE === 'mobile' ? 375 : 1680
|
|
78
|
-
},
|
|
79
|
-
fallbackCompPath: null,
|
|
80
|
-
modifyVars: {},
|
|
81
|
-
prefixCls: 'n',
|
|
82
|
-
alias: Object.assign({
|
|
83
|
-
'@': resolveProgramPath('src')
|
|
84
|
-
}, defaultAlias[APPTYPE]),
|
|
85
|
-
moduleRules: [],
|
|
86
|
-
prefixJsLoader: [],
|
|
87
|
-
cssModules: [],
|
|
88
|
-
importOnDemand: {},
|
|
89
|
-
proxy: [],
|
|
90
|
-
cacheDirectory: paths.webpackCachePath,
|
|
91
|
-
devServer: {
|
|
92
|
-
allowedHosts: [
|
|
93
|
-
'.baidu.com'
|
|
94
|
-
],
|
|
95
|
-
host: 'localhost',
|
|
96
|
-
port: 3000,
|
|
97
|
-
https: false,
|
|
98
|
-
compress: false
|
|
99
|
-
},
|
|
100
|
-
htmlPluginOption: {
|
|
101
|
-
template: `node_modules/${pkgName}/template/index.html`,
|
|
102
|
-
favicon: `node_modules/${pkgName}/template/favicon.ico`,
|
|
103
|
-
tags: []
|
|
104
|
-
},
|
|
105
|
-
assetHtml: [],
|
|
106
|
-
routerMode: 'browser',
|
|
107
|
-
fixBrowserRouter: false,
|
|
108
|
-
plugins: [],
|
|
109
|
-
splitChunk: defaultSplitChunk,
|
|
110
|
-
runtimeChunk: 'single',
|
|
111
|
-
moduleFederation: [],
|
|
112
|
-
rulesInclude: {
|
|
113
|
-
less: includeModule,
|
|
114
|
-
css: includeModule,
|
|
115
|
-
js: includeModule,
|
|
116
|
-
media: includeModule,
|
|
117
|
-
fonts: includeModule
|
|
118
|
-
},
|
|
119
|
-
mdx: {
|
|
120
|
-
jsxImportSource: jsxImportSource,
|
|
121
|
-
useDynamicImport: true,
|
|
122
|
-
remarkPlugins: [],
|
|
123
|
-
rehypePlugins: []
|
|
124
|
-
},
|
|
125
|
-
jsxDomExpressions: {
|
|
126
|
-
moduleName: 'solid-js/web',
|
|
127
|
-
builtIns: [
|
|
128
|
-
'For',
|
|
129
|
-
'Show',
|
|
130
|
-
'Switch',
|
|
131
|
-
'Match',
|
|
132
|
-
'Suspense',
|
|
133
|
-
'SuspenseList',
|
|
134
|
-
'Portal',
|
|
135
|
-
'Index',
|
|
136
|
-
'Dynamic',
|
|
137
|
-
'ErrorBoundary'
|
|
138
|
-
],
|
|
139
|
-
contextToCustomElements: true,
|
|
140
|
-
wrapConditionals: true,
|
|
141
|
-
generate: 'dom',
|
|
142
|
-
hydratable: false
|
|
143
|
-
},
|
|
144
|
-
bar: {
|
|
145
|
-
name: '编译中',
|
|
146
|
-
color: '#6f42c1'
|
|
147
|
-
},
|
|
148
|
-
virtualModule: {},
|
|
149
|
-
normalizeCss: true,
|
|
150
|
-
externalsPresets: {}
|
|
151
|
-
};
|
|
152
|
-
export const log = (msg)=>{
|
|
153
|
-
readline.cursorTo(process.stdout, 0);
|
|
154
|
-
process.stdout.write(msg);
|
|
155
|
-
};
|
|
156
|
-
let customConf = defaultConfig;
|
|
157
|
-
let configPath = null;
|
|
158
|
-
let normalConf = {};
|
|
159
|
-
let envConf = {};
|
|
160
|
-
try {
|
|
161
|
-
configPath = paths.defaultConfigPath;
|
|
162
|
-
accessSync(configPath, constants.R_OK);
|
|
163
|
-
} catch (error) {
|
|
164
|
-
configPath = null;
|
|
165
|
-
}
|
|
166
|
-
if (configPath) {
|
|
167
|
-
try {
|
|
168
|
-
const conf = (await readConf(configPath, 'index')).default;
|
|
169
|
-
normalConf = isFunction(conf) ? conf(process) : conf;
|
|
170
|
-
} catch (error) {
|
|
171
|
-
process.stdout.write(chalk.red(error));
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (CUSTOMCONFIG) {
|
|
175
|
-
let customConfigPath = null;
|
|
176
|
-
try {
|
|
177
|
-
customConfigPath = `${paths.programPath}/config/${CUSTOMCONFIG}.ts`;
|
|
178
|
-
accessSync(customConfigPath, constants.R_OK);
|
|
179
|
-
} catch (error) {
|
|
180
|
-
customConfigPath = null;
|
|
181
|
-
}
|
|
182
|
-
if (customConfigPath !== null) {
|
|
183
|
-
try {
|
|
184
|
-
const conf = (await readConf(customConfigPath, CUSTOMCONFIG)).default;
|
|
185
|
-
envConf = isFunction(conf) ? conf(process) : conf;
|
|
186
|
-
} catch (error) {
|
|
187
|
-
process.stdout.write(chalk.red(error));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
customConf = merge(customConf, normalConf, envConf);
|
|
192
|
-
if (customConf.compiler === 'tsc' && customConf.minifier) {
|
|
193
|
-
if (!customConf.minifier.js) {
|
|
194
|
-
Object.assign(customConf.minifier, {
|
|
195
|
-
js: {
|
|
196
|
-
type: 'terser'
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
if (!customConf.minifier.css) {
|
|
201
|
-
Object.assign(customConf.minifier, {
|
|
202
|
-
css: {
|
|
203
|
-
type: 'cssnano'
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (customConf.devtool === false) customConf.sourceMap = false;
|
|
209
|
-
if (customConf.sourceMap === false) customConf.devtool = false;
|
|
210
|
-
if (customConf.fixBrowserRouter && customConf.htmlPluginOption) {
|
|
211
|
-
if (!customConf.htmlPluginOption.tags) {
|
|
212
|
-
customConf.htmlPluginOption.tags = [];
|
|
213
|
-
}
|
|
214
|
-
customConf.htmlPluginOption.tags.push({
|
|
215
|
-
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))"
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
export const CONFIG = customConf;
|
|
219
|
-
export const PUBLICPATH = CONFIG.publicPath || '/';
|
|
220
|
-
export let hasCustomRouter = false;
|
|
221
|
-
try {
|
|
222
|
-
accessSync(`${CONFIG.alias['@']}/router/index.ts`, constants.R_OK);
|
|
223
|
-
hasCustomRouter = true;
|
|
224
|
-
} catch (error) {
|
|
225
|
-
hasCustomRouter = false;
|
|
226
|
-
}
|
|
227
|
-
global.NEKOCLICONFIG = {
|
|
228
|
-
CONFIG,
|
|
229
|
-
log
|
|
230
|
-
};
|
|
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,jsxImportSource as m,pkgName as p}from"./process-env.js";import{isFunction as u,readConf as d,resolveProgramPath as h}from"./utils.js";export const ENTRYPATH={mobile:"mobile",site:"site",backstage:"backstage",micro:"micro",library:"library"};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"],g={library:{"@":h("site"),"@pkg":h("components"),[c]:h("components")},mobile:{},site:{},backstage:{},micro:{}},b={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},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/${p}/template/index.html`,favicon:`node_modules/${p}/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:{less:f,css:f,js:f,media:f,fonts:f},mdx:{jsxImportSource:m,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:{}};export const log=e=>{o.cursorTo(process.stdout,0),process.stdout.write(e)};let x=b,y=null,C={},w={};try{y=i.defaultConfigPath,e(y,t.R_OK)}catch(e){y=null}if(y)try{let e=(await d(y,"index")).default;C=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;w=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}}"tsc"===(x=r(x,C,w)).compiler&&x.minifier&&(x.minifier.js||Object.assign(x.minifier,{js:{type:"terser"}}),x.minifier.css||Object.assign(x.minifier,{css:{type:"cssnano"}})),!1===x.devtool&&(x.sourceMap=!1),!1===x.sourceMap&&(x.devtool=!1),x.fixBrowserRouter&&x.htmlPluginOption&&(x.htmlPluginOption.tags||(x.htmlPluginOption.tags=[]),x.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=x;export const PUBLICPATH=CONFIG.publicPath||"/";export let hasCustomRouter=!1;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,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
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 parser = new Parser({
|
|
10
|
-
explicitArray: false,
|
|
11
|
-
async: false
|
|
12
|
-
});
|
|
13
|
-
const cover = readFileSync(paths.coveragePath, {
|
|
14
|
-
encoding: 'utf-8'
|
|
15
|
-
});
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
parser.parseString(cover, (error, result)=>{
|
|
18
|
-
if (!error) {
|
|
19
|
-
const projectMetrics = result.coverage.project.metrics.$;
|
|
20
|
-
const components = result.coverage.project.package;
|
|
21
|
-
Object.assign(coverage, {
|
|
22
|
-
[PACKAGENAME]: projectMetrics
|
|
23
|
-
});
|
|
24
|
-
components.forEach((pkg)=>{
|
|
25
|
-
Object.assign(coverage, {
|
|
26
|
-
[pkg.$.name]: pkg.metrics.$
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
// eslint-disable-next-line no-empty
|
|
32
|
-
} catch (error) {}
|
|
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}),i=c(t.coveragePath,{encoding:"utf-8"});// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
s.parseString(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.$})})}});// eslint-disable-next-line no-empty
|
|
3
|
+
}catch(e){}
|