@moneko/core 3.1.0-beta.2 → 3.1.0-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 +32 -1
- package/lib/app.js +40 -2
- package/lib/cleanup.js +19 -1
- package/lib/common.js +221 -2
- package/lib/config.js +230 -1
- package/lib/coverage.js +33 -3
- package/lib/dev.js +89 -5
- package/lib/docs.js +107 -2
- package/lib/done.js +11 -1
- package/lib/esm.js +7 -1
- package/lib/fallback.js +6 -1
- package/lib/generate-api.js +341 -3
- package/lib/has-pkg.js +12 -1
- package/lib/html-add-entry-attr.js +31 -10
- package/lib/html-plugin-option.js +45 -1
- package/lib/index.js +1 -1
- package/lib/locales.js +90 -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 +228 -3
- package/lib/net.js +33 -1
- package/lib/normalize-css.js +6 -1
- package/lib/object-listener.js +28 -1
- package/lib/paths.js +20 -1
- package/lib/prefix-router.js +6 -1
- package/lib/process-env.js +33 -1
- package/lib/prod.js +64 -5
- package/lib/rem.js +6 -1
- package/lib/resolver-sync.js +27 -1
- package/lib/routes.js +209 -4
- package/lib/seo.js +41 -2
- package/lib/swcrc.js +107 -2
- package/lib/tsloader.config.js +26 -2
- package/lib/utils.js +68 -6
- package/lib/virtual-module-plugin.js +63 -1
- package/lib/virtual-modules.js +37 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +2 -2
|
@@ -1 +1,45 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { merge } from 'webpack-merge';
|
|
2
|
+
import app from './app.js';
|
|
3
|
+
import { CONFIG } from './config.js';
|
|
4
|
+
import paths from './paths.js';
|
|
5
|
+
import { PACKAGENAME, pkgName } from './process-env.js';
|
|
6
|
+
const { template, favicon, ...option } = Object.assign({
|
|
7
|
+
template: `node_modules/${pkgName}/template/index.html`,
|
|
8
|
+
favicon: `node_modules/${pkgName}/template/favicon.ico`
|
|
9
|
+
}, CONFIG.htmlPluginOption || {});
|
|
10
|
+
const htmlPluginOption = merge({
|
|
11
|
+
title: CONFIG.env?.PROJECTNAME || PACKAGENAME.toLocaleUpperCase() || 'Title',
|
|
12
|
+
filename: 'index.html',
|
|
13
|
+
hash: false,
|
|
14
|
+
minify: {
|
|
15
|
+
collapseWhitespace: true,
|
|
16
|
+
removeComments: true,
|
|
17
|
+
removeRedundantAttributes: false,
|
|
18
|
+
removeScriptTypeAttributes: false,
|
|
19
|
+
removeStyleLinkTypeAttributes: false,
|
|
20
|
+
removeAttributeQuotes: true,
|
|
21
|
+
useShortDoctype: true
|
|
22
|
+
},
|
|
23
|
+
meta: {
|
|
24
|
+
charset: 'UTF-8',
|
|
25
|
+
'X-UA-Compatible': {
|
|
26
|
+
'http-equiv': 'X-UA-Compatible',
|
|
27
|
+
content: 'IE=edge,Chrome=1'
|
|
28
|
+
},
|
|
29
|
+
HandheldFriendly: 'true',
|
|
30
|
+
MobileOptimized: '320',
|
|
31
|
+
'screen-orientation': 'portrait',
|
|
32
|
+
'x5-orientation': 'portrait',
|
|
33
|
+
browsermode: 'application',
|
|
34
|
+
'x5-page-mode': 'app',
|
|
35
|
+
'msapplication-tap-highlight': 'no',
|
|
36
|
+
viewport: 'width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no',
|
|
37
|
+
'apple-mobile-web-app-capable': 'yes',
|
|
38
|
+
renderer: 'webkit',
|
|
39
|
+
description: app.description || ''
|
|
40
|
+
},
|
|
41
|
+
tags: [],
|
|
42
|
+
template: `${paths.programPath}/${template}`,
|
|
43
|
+
favicon: `${paths.programPath}/${favicon}`
|
|
44
|
+
}, option);
|
|
45
|
+
export default htmlPluginOption;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from
|
|
1
|
+
export * from '../typings/global.js';
|
package/lib/locales.js
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { basename, join } from 'path';
|
|
3
|
+
import { watch } from 'chokidar';
|
|
4
|
+
import { CONFIG } from './config.js';
|
|
5
|
+
import esm from './esm.js';
|
|
6
|
+
import objectListener from './object-listener.js';
|
|
7
|
+
import { FRAMEWORK, isLibrary } from './process-env.js';
|
|
8
|
+
import { resolveProgramPath, tfc } from './utils.js';
|
|
9
|
+
const prefixStr = {
|
|
10
|
+
react: 'import sso from "shared-store-object";',
|
|
11
|
+
solid: 'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'
|
|
12
|
+
};
|
|
13
|
+
const suffixStr = {
|
|
14
|
+
react: 'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',
|
|
15
|
+
solid: 'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'
|
|
16
|
+
}[FRAMEWORK];
|
|
17
|
+
export const locales = objectListener({
|
|
18
|
+
name: '@app/locales',
|
|
19
|
+
data: 'export const locales = [];'
|
|
20
|
+
});
|
|
21
|
+
const caches = {};
|
|
22
|
+
// 要执行的函数
|
|
23
|
+
async function handleFileChange(filePath, type) {
|
|
24
|
+
const filename = basename(filePath).replace(/\.[^.]+$/, '');
|
|
25
|
+
if (type === 'deleted') {
|
|
26
|
+
delete caches[filename];
|
|
27
|
+
} else {
|
|
28
|
+
const option = await import(esm`${tfc(filePath)}`);
|
|
29
|
+
Object.assign(caches, {
|
|
30
|
+
[filename]: option.default
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const langs = [];
|
|
34
|
+
const resources = {};
|
|
35
|
+
for(const key in caches){
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(caches, key)) {
|
|
37
|
+
const item = caches[key];
|
|
38
|
+
const { language = filename, title = language, icon, translation = {} } = item;
|
|
39
|
+
langs.push({
|
|
40
|
+
language,
|
|
41
|
+
title,
|
|
42
|
+
icon
|
|
43
|
+
});
|
|
44
|
+
resources[language] = {
|
|
45
|
+
language,
|
|
46
|
+
title,
|
|
47
|
+
icon,
|
|
48
|
+
translation
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
Object.assign(locales.data, {
|
|
53
|
+
data: `${prefixStr[FRAMEWORK]}
|
|
54
|
+
export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(langs)};const _res = ${JSON.stringify(resources)};const resources = deepFreeze(_res);${suffixStr}`
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function watchDirectory(paths, ignored) {
|
|
58
|
+
const files = [];
|
|
59
|
+
const watcher = watch(paths, {
|
|
60
|
+
ignored: ignored,
|
|
61
|
+
persistent: true,
|
|
62
|
+
ignoreInitial: false
|
|
63
|
+
});
|
|
64
|
+
watcher.on('add', (path)=>{
|
|
65
|
+
handleFileChange(path, 'added');
|
|
66
|
+
files.push(path);
|
|
67
|
+
});
|
|
68
|
+
watcher.on('change', (path)=>{
|
|
69
|
+
handleFileChange(path, 'change');
|
|
70
|
+
});
|
|
71
|
+
watcher.on('unlink', (path)=>{
|
|
72
|
+
handleFileChange(path, 'deleted');
|
|
73
|
+
files.splice(files.indexOf(path), 1);
|
|
74
|
+
});
|
|
75
|
+
watcher.on('ready', ()=>{
|
|
76
|
+
files.forEach((f)=>{
|
|
77
|
+
handleFileChange(f, 'change');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
process.on('SIGINT', function() {
|
|
81
|
+
watcher.close();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (existsSync(join(CONFIG.alias['@'], './locales'))) {
|
|
85
|
+
watchDirectory(resolveProgramPath(isLibrary ? 'site/locales' : 'src/locales'), [
|
|
86
|
+
/^\..*/,
|
|
87
|
+
/!\.ts$/,
|
|
88
|
+
/\.d\.ts$/
|
|
89
|
+
]);
|
|
90
|
+
}
|
package/lib/merge-router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default
|
|
1
|
+
export default 'function merge(e,r){if(!e.length)return void 0;const n=[];e.forEach(e=>{const t=n.findIndex(n=>n[r]==e[r]);if(t>-1){const i=[...n[t].children||[],...e.children||[]];n[t]=Object.assign(e,n[t],n[t].meta&&{meta:{...n[t].meta,...e.meta}});if(i.length){n[t].children=merge(i,r)}}else{n.push(Object.assign(e,Array.isArray(e.children)&&{children:merge(e.children,r)}))}});return n}export default merge;';
|
package/lib/minify.js
CHANGED
|
@@ -1,2 +1,47 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
2
|
+
import { merge } from 'webpack-merge';
|
|
3
|
+
import { swcMinifyOption } from './swcrc.js';
|
|
4
|
+
export const minify = {
|
|
5
|
+
terser: {
|
|
6
|
+
minify: TerserPlugin.terserMinify,
|
|
7
|
+
terserOptions: {
|
|
8
|
+
ecma: 2015,
|
|
9
|
+
parse: {},
|
|
10
|
+
compress: {
|
|
11
|
+
global_defs: {
|
|
12
|
+
'@alert': 'console.log'
|
|
13
|
+
},
|
|
14
|
+
drop_console: true,
|
|
15
|
+
drop_debugger: true,
|
|
16
|
+
pure_funcs: [
|
|
17
|
+
'console.log',
|
|
18
|
+
'console.warn',
|
|
19
|
+
'console.error',
|
|
20
|
+
'console.info'
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
toplevel: false,
|
|
24
|
+
mangle: true,
|
|
25
|
+
module: false,
|
|
26
|
+
format: {
|
|
27
|
+
comments: false
|
|
28
|
+
},
|
|
29
|
+
// nameCache: null,
|
|
30
|
+
ie8: false,
|
|
31
|
+
keep_classnames: void 0,
|
|
32
|
+
keep_fnames: false,
|
|
33
|
+
safari10: false
|
|
34
|
+
},
|
|
35
|
+
extractComments: false
|
|
36
|
+
},
|
|
37
|
+
swc: {
|
|
38
|
+
minify: TerserPlugin.swcMinify,
|
|
39
|
+
terserOptions: swcMinifyOption
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export const getMinifyOption = (type, options = {})=>{
|
|
43
|
+
const min = minify[type];
|
|
44
|
+
return Object.assign(min, {
|
|
45
|
+
terserOptions: merge(min.terserOptions, options)
|
|
46
|
+
});
|
|
47
|
+
};
|
package/lib/modify-vars.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{CONFIG
|
|
1
|
+
import { CONFIG } from './config.js';
|
|
2
|
+
import htmlPluginOption from './html-plugin-option.js';
|
|
3
|
+
const prefixCls = CONFIG.prefixCls || 'n';
|
|
4
|
+
const modifyVars = {
|
|
5
|
+
'@prefix-cls': prefixCls,
|
|
6
|
+
'@ant-prefix': prefixCls,
|
|
7
|
+
'@iconfont-css-prefix': `${prefixCls}-icon`,
|
|
8
|
+
'@favicon': JSON.stringify(htmlPluginOption.favicon)
|
|
9
|
+
};
|
|
10
|
+
Object.assign(modifyVars, CONFIG.modifyVars);
|
|
11
|
+
export default modifyVars;
|
package/lib/module-federation.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ExternalTemplateRemotesPlugin from 'external-remotes-plugin';
|
|
2
|
+
import webpack from 'webpack';
|
|
3
|
+
import ModuleFederationPlugin from 'webpack/lib/container/ModuleFederationPlugin.js';
|
|
4
|
+
import { CONFIG } from './config.js';
|
|
5
|
+
import { realResolve } from './utils.js';
|
|
6
|
+
const NormalModuleReplacementPlugin = webpack.NormalModuleReplacementPlugin;
|
|
7
|
+
const aliasLibrary = {};
|
|
8
|
+
const exposesMap = {};
|
|
9
|
+
const remoteMap = {};
|
|
10
|
+
export const moduleFederation = CONFIG.moduleFederation?.map((opt)=>{
|
|
11
|
+
if (Array.isArray(opt.remotes)) {
|
|
12
|
+
for(let r = 0, rlen = opt.remotes.length; r < rlen; r++){
|
|
13
|
+
const m = opt.remotes[r];
|
|
14
|
+
const aliasName = m.alias || m.name;
|
|
15
|
+
const filename = m.filename || 'remote_entry.js';
|
|
16
|
+
remoteMap[aliasName] = `${m.name}@${m.host}/${filename}`;
|
|
17
|
+
if (Array.isArray(m.library)) {
|
|
18
|
+
for(let i = 0, len = m.library.length; i < len; i++){
|
|
19
|
+
aliasLibrary[m.library[i]] = `${aliasName}/${m.library[i]}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(opt.exposes)) {
|
|
25
|
+
for(let i = 0, len = opt.exposes.length; i < len; i++){
|
|
26
|
+
const m = opt.exposes[i];
|
|
27
|
+
if (typeof m === 'string') {
|
|
28
|
+
exposesMap[`./${m}`] = realResolve(m);
|
|
29
|
+
} else if (Object.prototype.toString.call(m) === '[object Object]') {
|
|
30
|
+
exposesMap[`./${m.name}`] = realResolve(m.path);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return new ModuleFederationPlugin({
|
|
35
|
+
filename: 'remote_entry.js',
|
|
36
|
+
...opt,
|
|
37
|
+
remotes: remoteMap,
|
|
38
|
+
exposes: exposesMap
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
if (moduleFederation.length) {
|
|
42
|
+
moduleFederation.push(new ExternalTemplateRemotesPlugin());
|
|
43
|
+
moduleFederation.push(new NormalModuleReplacementPlugin(/(.*)/, (resource)=>{
|
|
44
|
+
if (aliasLibrary[resource.request]) resource.request = aliasLibrary[resource.request];
|
|
45
|
+
}));
|
|
46
|
+
}
|
package/lib/module.config.js
CHANGED
|
@@ -1,3 +1,228 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
|
+
import svgToMiniDataURI from 'mini-svg-data-uri';
|
|
3
|
+
import { CONFIG, PUBLICPATH } from './config.js';
|
|
4
|
+
import { hasPkg } from './has-pkg.js';
|
|
5
|
+
import modifyVars from './modify-vars.js';
|
|
6
|
+
import paths from './paths.js';
|
|
7
|
+
import { FRAMEWORK, isDev, isMicro } from './process-env.js';
|
|
8
|
+
import swcOption from './swcrc.js';
|
|
9
|
+
import tsLoaderConfig from './tsloader.config.js';
|
|
10
|
+
import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
|
|
11
|
+
const cssUnicode = {
|
|
12
|
+
loader: `${paths.corePath}/loader/css-unicode.cjs`
|
|
13
|
+
};
|
|
14
|
+
const cssAssetsPublicPath = isMicro ? PUBLICPATH : '../';
|
|
15
|
+
let styleLoader = {
|
|
16
|
+
loader: MiniCssExtractPlugin.loader,
|
|
17
|
+
options: {
|
|
18
|
+
publicPath: cssAssetsPublicPath !== '/' ? cssAssetsPublicPath : '../'
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const postcssLoader = hasPkg('@moneko/postcss') && {
|
|
22
|
+
loader: 'postcss-loader',
|
|
23
|
+
options: {
|
|
24
|
+
postcssOptions: await import('@moneko/postcss')
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
if (isDev) {
|
|
28
|
+
styleLoader = 'style-loader';
|
|
29
|
+
}
|
|
30
|
+
const customCssModules = [
|
|
31
|
+
...CONFIG.cssModules,
|
|
32
|
+
`@moneko/${FRAMEWORK}`,
|
|
33
|
+
'neko-ui'
|
|
34
|
+
].map(resolveNodeModulesPath);
|
|
35
|
+
const styleResources = [
|
|
36
|
+
...[
|
|
37
|
+
'src/styles/variables.less',
|
|
38
|
+
'src/styles/mixins.less',
|
|
39
|
+
'site/styles/variables.less',
|
|
40
|
+
'site/styles/mixins.less'
|
|
41
|
+
].map(resolveProgramPath)
|
|
42
|
+
];
|
|
43
|
+
const entryResolveProgramPath = [
|
|
44
|
+
'components',
|
|
45
|
+
'example',
|
|
46
|
+
'mock',
|
|
47
|
+
'site',
|
|
48
|
+
'src',
|
|
49
|
+
'server'
|
|
50
|
+
].map(resolveProgramPath);
|
|
51
|
+
const lessLoaderRule = [
|
|
52
|
+
styleLoader,
|
|
53
|
+
isDev && {
|
|
54
|
+
loader: '@teamsupercell/typings-for-css-modules-loader',
|
|
55
|
+
options: {
|
|
56
|
+
verifyOnly: !isDev
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
loader: 'css-loader',
|
|
61
|
+
options: {
|
|
62
|
+
modules: {
|
|
63
|
+
// 根据文件名觉得是否启用cssModules | 排除 node_modules 和 *global.css 和 *global.less
|
|
64
|
+
auto: (resourcePath)=>{
|
|
65
|
+
for(let i = 0, len = customCssModules.length; i < len; i++){
|
|
66
|
+
if (resourcePath && resourcePath?.includes(customCssModules[i])) {
|
|
67
|
+
return /(.*(?<!\.?global\.(le|c)ss)$)/i.test(resourcePath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return /(^(?!.*node_modules))(.*(?<!\.?global\.(le|c)ss)$)/i.test(resourcePath);
|
|
71
|
+
},
|
|
72
|
+
// localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
|
|
73
|
+
localIdentName: '[path][name]__[local]',
|
|
74
|
+
exportLocalsConvention: 'dashesOnly'
|
|
75
|
+
},
|
|
76
|
+
importLoaders: 2
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
postcssLoader,
|
|
80
|
+
cssUnicode,
|
|
81
|
+
{
|
|
82
|
+
loader: 'less-loader',
|
|
83
|
+
options: {
|
|
84
|
+
sourceMap: !!CONFIG.sourceMap,
|
|
85
|
+
lessOptions: {
|
|
86
|
+
modifyVars: modifyVars,
|
|
87
|
+
javascriptEnabled: true
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
loader: 'style-resources-loader',
|
|
93
|
+
options: {
|
|
94
|
+
patterns: styleResources
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
].filter(Boolean);
|
|
98
|
+
const tsLoader = {
|
|
99
|
+
loader: CONFIG.compiler === 'tsc' ? 'ts-loader' : 'swc-loader',
|
|
100
|
+
options: CONFIG.compiler === 'tsc' ? tsLoaderConfig : swcOption(isDev)
|
|
101
|
+
};
|
|
102
|
+
const includeMedia = entryResolveProgramPath.concat(CONFIG.rulesInclude?.media?.map(resolveNodeModulesPath) || []);
|
|
103
|
+
const includeFonts = entryResolveProgramPath.concat(CONFIG.rulesInclude?.fonts?.map(resolveNodeModulesPath) || []);
|
|
104
|
+
const includeLess = entryResolveProgramPath.concat(CONFIG.rulesInclude?.less?.map(resolveNodeModulesPath) || []);
|
|
105
|
+
const includeCss = entryResolveProgramPath.concat(CONFIG.rulesInclude?.css?.map(resolveNodeModulesPath) || []);
|
|
106
|
+
const includeJs = entryResolveProgramPath.concat(CONFIG.rulesInclude?.js?.map(resolveNodeModulesPath) || []);
|
|
107
|
+
const moduleOptions = {
|
|
108
|
+
rules: [
|
|
109
|
+
{
|
|
110
|
+
test: /\.mdx?$/i,
|
|
111
|
+
include: [
|
|
112
|
+
resolveProgramPath('components')
|
|
113
|
+
],
|
|
114
|
+
exclude: [
|
|
115
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
116
|
+
],
|
|
117
|
+
enforce: 'pre',
|
|
118
|
+
use: [
|
|
119
|
+
{
|
|
120
|
+
loader: `${paths.corePath}/loader/frontmatter.cjs`
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
oneOf: [
|
|
126
|
+
{
|
|
127
|
+
resourceQuery: /raw/,
|
|
128
|
+
type: 'asset/source'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
test: /\.wasm$/i,
|
|
132
|
+
type: 'webassembly/async'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
test: /\.txt$/i,
|
|
136
|
+
type: 'asset/source'
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
test: /\.ico$/i,
|
|
140
|
+
type: 'asset/inline',
|
|
141
|
+
include: includeMedia
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
test: /\.svg$/i,
|
|
145
|
+
type: 'asset/inline',
|
|
146
|
+
generator: {
|
|
147
|
+
dataUrl: (content)=>svgToMiniDataURI(typeof content !== 'string' ? content.toString() : content)
|
|
148
|
+
},
|
|
149
|
+
include: includeMedia
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
test: /\.(gif|png|jpe?g|mp4)$/i,
|
|
153
|
+
type: 'asset',
|
|
154
|
+
dependency: {
|
|
155
|
+
not: [
|
|
156
|
+
'url'
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
generator: {
|
|
160
|
+
filename: 'assets/images/[name][ext][query]'
|
|
161
|
+
},
|
|
162
|
+
include: includeMedia
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
test: /\.(eot|ttf|otf|woff|woff2)$/i,
|
|
166
|
+
type: 'asset',
|
|
167
|
+
generator: {
|
|
168
|
+
filename: 'assets/fonts/[name][ext][query]'
|
|
169
|
+
},
|
|
170
|
+
include: includeFonts
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
test: /\.less$/i,
|
|
174
|
+
use: lessLoaderRule,
|
|
175
|
+
include: includeLess
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
test: /\.css$/i,
|
|
179
|
+
use: [
|
|
180
|
+
styleLoader,
|
|
181
|
+
'css-loader',
|
|
182
|
+
postcssLoader,
|
|
183
|
+
cssUnicode
|
|
184
|
+
].filter(Boolean),
|
|
185
|
+
include: includeCss
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
test: /\.(cj|mj|t|j)s(|x)$/i,
|
|
189
|
+
use: [
|
|
190
|
+
...CONFIG.prefixJsLoader,
|
|
191
|
+
tsLoader
|
|
192
|
+
].filter(Boolean),
|
|
193
|
+
include: includeJs
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
test: /\.mdx?$/i,
|
|
197
|
+
use: [
|
|
198
|
+
...CONFIG.prefixJsLoader,
|
|
199
|
+
tsLoader,
|
|
200
|
+
{
|
|
201
|
+
loader: '@mdx-js/loader',
|
|
202
|
+
options: CONFIG.mdx
|
|
203
|
+
}
|
|
204
|
+
].filter(Boolean),
|
|
205
|
+
include: entryResolveProgramPath,
|
|
206
|
+
exclude: [
|
|
207
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
208
|
+
]
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
test: /\.mdx?$/i,
|
|
212
|
+
type: 'asset/source',
|
|
213
|
+
include: [
|
|
214
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
215
|
+
]
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
type: 'asset/source',
|
|
219
|
+
include: [
|
|
220
|
+
/(.+)\/examples\/(.+).*?$/i
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
...CONFIG.moduleRules
|
|
226
|
+
]
|
|
227
|
+
};
|
|
228
|
+
export default moduleOptions;
|
package/lib/net.js
CHANGED
|
@@ -1 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createConnection } from 'net';
|
|
2
|
+
import { networkInterfaces } from 'os';
|
|
3
|
+
import devServer from 'webpack-dev-server';
|
|
4
|
+
const { internalIPSync } = devServer;
|
|
5
|
+
export function getNetworkAdress() {
|
|
6
|
+
const interfaces = networkInterfaces();
|
|
7
|
+
for(const devName in interfaces){
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(interfaces, devName)) {
|
|
9
|
+
const iface = interfaces[devName];
|
|
10
|
+
for(let i = 0; i < iface.length; i++){
|
|
11
|
+
const alias = iface[i];
|
|
12
|
+
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith('169.254') && !alias.internal) {
|
|
13
|
+
return alias.address;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function getIPv4() {
|
|
20
|
+
return internalIPSync('v4');
|
|
21
|
+
}
|
|
22
|
+
export function getPort(start, end, host = '0.0.0.0') {
|
|
23
|
+
return new Promise((resolve)=>{
|
|
24
|
+
const tester = createConnection(start, host);
|
|
25
|
+
tester.on('connect', ()=>{
|
|
26
|
+
tester.destroy();
|
|
27
|
+
resolve(getPort(start + 1, end, host));
|
|
28
|
+
});
|
|
29
|
+
tester.on('error', ()=>{
|
|
30
|
+
resolve(start);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
package/lib/normalize-css.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import{CONFIG
|
|
1
|
+
import { CONFIG } from './config.js';
|
|
2
|
+
let normalizeCss = '';
|
|
3
|
+
if (CONFIG.normalizeCss) {
|
|
4
|
+
normalizeCss = 'html,body{margin:0;padding:0;line-height:1.8}input,textarea{caret-color:inherit}h1{margin:0.67em 0;font-size:2em}hr{overflow:visible;block-size:0;box-sizing:content-box}pre{font-size:1em;font-family:monospace}a{text-decoration:none;background-color:transparent;cursor:pointer}abbr[title]{border-block-end:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-size:1em;font-family:monospace}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sub{inset-block-end:-0.25em}sup{inset-block-start:-0.5em}img{border-style:none}img,button{outline:1px solid transparent}button,input,optgroup,select,textarea{margin:0;font-size:100%;font-family:inherit;line-height:1.15}button,input{overflow:visible}button,select{text-transform:none}button,[type="button"],[type="reset"],[type="submit"]{appearance:button}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted var(--primary-outline)}fieldset{padding:0.35em 0.75em 0.625em}legend{display:table;padding:0;max-inline-size:100%;white-space:normal;color:inherit;box-sizing:border-box}progress{vertical-align:baseline}textarea{overflow:auto}details{display:block}summary{display:list-item}template,[hidden]{display:none}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{block-size:auto}[type="search"]{appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-decoration{appearance:none}::-webkit-file-upload-button{appearance:button;font:inherit}::-webkit-scrollbar{inline-size:5px;block-size:5px}::-webkit-scrollbar-track,::-webkit-scrollbar-thumb{background-color:transparent}:hover::-webkit-scrollbar-thumb{background-color:var(--primary-selection)}::-webkit-scrollbar-thumb:hover{background-color:var(--primary-hover)}::-webkit-scrollbar-thumb:active{background-color:var(--primary-active)}::-webkit-scrollbar-button{display:none}';
|
|
5
|
+
}
|
|
6
|
+
export default normalizeCss;
|
package/lib/object-listener.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function objectListener(initialData) {
|
|
2
|
+
const listeners = [];
|
|
3
|
+
function notifyListeners(target) {
|
|
4
|
+
listeners.forEach((callback)=>{
|
|
5
|
+
callback(target);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function listener(callback) {
|
|
9
|
+
listeners.push(callback);
|
|
10
|
+
return ()=>{
|
|
11
|
+
const index = listeners.indexOf(callback);
|
|
12
|
+
if (index !== -1) {
|
|
13
|
+
listeners.splice(index, 1);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const data = new Proxy(initialData, {
|
|
18
|
+
set (target, property, value) {
|
|
19
|
+
target[property] = value;
|
|
20
|
+
notifyListeners(target);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
data,
|
|
26
|
+
listener
|
|
27
|
+
};
|
|
28
|
+
}
|
package/lib/paths.js
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync, mkdirSync } from 'fs';
|
|
2
|
+
import url from 'url';
|
|
3
|
+
const programPath = process.cwd();
|
|
4
|
+
const cachePath = `${programPath}/node_modules/.cache/.mo`;
|
|
5
|
+
if (!existsSync(cachePath)) {
|
|
6
|
+
mkdirSync(cachePath, {
|
|
7
|
+
recursive: true
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export default {
|
|
11
|
+
corePath: url.fileURLToPath(new URL('.', import.meta.url)),
|
|
12
|
+
programPath: programPath,
|
|
13
|
+
webpackCachePath: `${programPath}/node_modules/.temp_cache`,
|
|
14
|
+
cachePath: cachePath,
|
|
15
|
+
swcCachePath: `${programPath}/node_modules/.cache/.swc`,
|
|
16
|
+
defaultConfigPath: `${programPath}/config/index.ts`,
|
|
17
|
+
coveragePath: `${programPath}/coverage/clover.xml`,
|
|
18
|
+
pagesPath: `${programPath}/src/pages`,
|
|
19
|
+
componentsPath: `${programPath}/components`
|
|
20
|
+
};
|
package/lib/prefix-router.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import{isReact
|
|
1
|
+
import { isReact } from './process-env.js';
|
|
2
|
+
let prefixRouter = '';
|
|
3
|
+
if (isReact) {
|
|
4
|
+
prefixRouter = 'import { createElement, isValidElement } from "react";import { Outlet } from "react-router-dom";function prefix(e){return e.map(function(e){var n=Object.assign({key:e.path},e);return n.element?isValidElement(n.element)||(n.element=createElement(n.element,n.meta)):n.element=createElement(Outlet,null),Array.isArray(n.children)&&(n.children=prefix(n.children)),n})}export default prefix;';
|
|
5
|
+
}
|
|
6
|
+
export default prefixRouter;
|