@moneko/core 3.2.1-beta.0 → 3.2.1-beta.2
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 +32 -1
- package/lib/app.js +40 -2
- package/lib/cleanup.js +19 -1
- package/lib/common.js +248 -1
- package/lib/config.js +234 -1
- package/lib/coverage.js +33 -2
- package/lib/dev.js +89 -5
- package/lib/docs.js +120 -2
- package/lib/done.js +12 -1
- package/lib/esm.js +7 -1
- package/lib/fallback.js +6 -1
- package/lib/generate-api.d.ts +1 -1
- package/lib/generate-api.js +345 -3
- package/lib/has-pkg.js +12 -1
- package/lib/html-add-entry-attr.js +32 -10
- package/lib/html-plugin-option.js +45 -1
- package/lib/index.js +4 -1
- package/lib/locales.js +93 -3
- package/lib/merge-router.js +1 -1
- package/lib/minify.js +47 -2
- package/lib/modify-vars.js +11 -1
- package/lib/module-federation.js +46 -1
- package/lib/module.config.js +273 -3
- package/lib/net.js +33 -1
- package/lib/normalize-css.js +6 -1
- package/lib/paths.js +21 -1
- package/lib/polyfills/replace-children.js +26 -3
- package/lib/polyfills.js +15 -3
- package/lib/prefix-router.js +6 -1
- package/lib/process-env.js +33 -2
- package/lib/prod.js +65 -5
- package/lib/reactive-object.js +47 -8
- package/lib/rem.js +6 -1
- package/lib/resolver-sync.js +27 -1
- package/lib/routes.js +196 -4
- package/lib/seo.js +41 -2
- package/lib/swcrc.js +100 -2
- package/lib/tsloader.config.js +26 -2
- package/lib/utils.js +71 -7
- package/lib/virtual-module-plugin.js +49 -1
- package/lib/virtual-modules.js +37 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +6 -2
- package/typings/global.d.ts +1 -2
package/lib/app-entry.js
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { existsSync } from 'fs';
|
|
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;
|
package/lib/app.js
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { CONFIG } from './config.js';
|
|
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;
|
package/lib/cleanup.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync, readdirSync, rmdirSync, statSync, unlinkSync } from 'fs';
|
|
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
|
+
});
|
package/lib/common.js
CHANGED
|
@@ -1 +1,248 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
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
|
+
};
|
package/lib/config.js
CHANGED
|
@@ -1 +1,234 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { accessSync, constants } from 'fs';
|
|
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
|
+
};
|
package/lib/coverage.js
CHANGED
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
import{accessSync
|
|
2
|
-
}
|
|
1
|
+
import { accessSync, constants, readFileSync } from 'fs';
|
|
2
|
+
import { Parser } from 'xml2js';
|
|
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
|
+
}
|