@moneko/core 3.2.1-beta.1 → 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.js +345 -14
- 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 +4 -2
- package/typings/global.d.ts +1 -2
- package/lib/threads.d.ts +0 -1
- package/lib/threads.js +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* 向 html-webpack-plugin 导出的 HTML 模板 script 添加属性
|
|
3
3
|
* ```javascript
|
|
4
4
|
* // 假设输出 main chunk 为 main.[hash].chunk.js。
|
|
@@ -7,12 +7,34 @@ export default /**
|
|
|
7
7
|
* return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
|
|
8
8
|
* })),
|
|
9
9
|
* ```
|
|
10
|
-
*/class
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
*/ class AddEntryAttributeWebpackPlugin {
|
|
11
|
+
entryMatchCallback;
|
|
12
|
+
// eslint-disable-next-line no-unused-vars
|
|
13
|
+
constructor(matchCallback){
|
|
14
|
+
this.entryMatchCallback = matchCallback;
|
|
15
|
+
}
|
|
16
|
+
apply(compiler) {
|
|
17
|
+
compiler.hooks.compilation.tap('AddEntryAttributeWebpackPlugin', (compilation)=>{
|
|
18
|
+
// 通过最终的 webpack 配置的 plugins 属性,根据插件的 constructor.name 拿到 html-webpack-plugin 实例
|
|
19
|
+
const HtmlWebpackPluginInstance = compiler.options.plugins.map(({ constructor })=>constructor).find((constructor)=>constructor && constructor.name === 'HtmlWebpackPlugin');
|
|
20
|
+
// .find(
|
|
21
|
+
// (plugin) => plugin instanceof HtmlWebpackPlugin,
|
|
22
|
+
// ) as typeof HtmlWebpackPlugin;
|
|
23
|
+
if (HtmlWebpackPluginInstance) {
|
|
24
|
+
// 获取 html-webpack-plugin 所有的 hooks
|
|
25
|
+
const hooks = HtmlWebpackPluginInstance.getHooks(compilation);
|
|
26
|
+
// 在插入标签之前做些什么
|
|
27
|
+
hooks.alterAssetTagGroups.tap('AddEntryAttributeWebpackPlugin', (data)=>{
|
|
28
|
+
// 拿到所有的标签,如果是 script 标签,并且满足我们的匹配函数,则将其 attributes['entry'] 设为 true
|
|
29
|
+
data.headTags.forEach((tag)=>{
|
|
30
|
+
if (tag.tagName === 'script' && this.entryMatchCallback(tag.attributes.src)) {
|
|
31
|
+
tag.attributes.entry = true;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return data;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export default AddEntryAttributeWebpackPlugin;
|
|
@@ -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, coreName } from './process-env.js';
|
|
6
|
+
const { template, favicon, ...option } = Object.assign({
|
|
7
|
+
template: `node_modules/${coreName}/template/index.html`,
|
|
8
|
+
favicon: `node_modules/${coreName}/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,4 @@
|
|
|
1
|
-
export{default as paths}from
|
|
1
|
+
export { default as paths } from './paths.js';
|
|
2
|
+
export { CUSTOMCONFIG, FRAMEWORKNAME, PACKAGENAME, PACKAGEVERSION, coreName, isDev, isLibrary, isMicro } from './process-env.js';
|
|
3
|
+
export { realResolve, resolveNodeModulesPath, resolveProgramPath } from './utils.js';
|
|
4
|
+
export { getNetworkAdress, getIPv4, getPort } from './net.js';
|
package/lib/locales.js
CHANGED
|
@@ -1,3 +1,93 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { stat } 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 { FRAMEWORK, isLibrary } from './process-env.js';
|
|
7
|
+
import ReactiveObject from './reactive-object.js';
|
|
8
|
+
import { empty, 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
|
+
function getStr(lang, data) {
|
|
18
|
+
return `${prefixStr[FRAMEWORK]}
|
|
19
|
+
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(lang)};const _res = ${JSON.stringify(data)};const resources = deepFreeze(_res);${suffixStr}`;
|
|
20
|
+
}
|
|
21
|
+
export const localesModuleName = '@app/locales';
|
|
22
|
+
export const locales = new ReactiveObject({
|
|
23
|
+
[localesModuleName]: getStr([], {})
|
|
24
|
+
});
|
|
25
|
+
const caches = {};
|
|
26
|
+
// 要执行的函数
|
|
27
|
+
async function handleFileChange(filePath, type) {
|
|
28
|
+
const filename = basename(filePath).replace(/\.[^.]+$/, '');
|
|
29
|
+
if (type === 'deleted') {
|
|
30
|
+
delete caches[filename];
|
|
31
|
+
} else {
|
|
32
|
+
const option = await import(esm`${tfc(filePath)}`);
|
|
33
|
+
Object.assign(caches, {
|
|
34
|
+
[filename]: option.default
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const langs = [];
|
|
38
|
+
const resources = {};
|
|
39
|
+
for(const key in caches){
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(caches, key)) {
|
|
41
|
+
const item = caches[key];
|
|
42
|
+
const { language = filename, title = language, icon, translation = {} } = item;
|
|
43
|
+
langs.push({
|
|
44
|
+
language,
|
|
45
|
+
title,
|
|
46
|
+
icon
|
|
47
|
+
});
|
|
48
|
+
resources[language] = {
|
|
49
|
+
language,
|
|
50
|
+
title,
|
|
51
|
+
icon,
|
|
52
|
+
translation
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
locales.setData(localesModuleName, getStr(langs, resources));
|
|
57
|
+
}
|
|
58
|
+
function watchDirectory(paths, ignored) {
|
|
59
|
+
const files = [];
|
|
60
|
+
const watcher = watch(paths, {
|
|
61
|
+
ignored: ignored,
|
|
62
|
+
persistent: true,
|
|
63
|
+
ignoreInitial: false
|
|
64
|
+
});
|
|
65
|
+
watcher.on('add', (path)=>{
|
|
66
|
+
files.push(path);
|
|
67
|
+
handleFileChange(path, 'added').finally(empty);
|
|
68
|
+
});
|
|
69
|
+
watcher.on('change', (path)=>{
|
|
70
|
+
handleFileChange(path, 'change').finally(empty);
|
|
71
|
+
});
|
|
72
|
+
watcher.on('unlink', (path)=>{
|
|
73
|
+
files.splice(files.indexOf(path), 1);
|
|
74
|
+
handleFileChange(path, 'deleted').finally(empty);
|
|
75
|
+
});
|
|
76
|
+
watcher.on('ready', ()=>{
|
|
77
|
+
files.forEach((f)=>{
|
|
78
|
+
handleFileChange(f, 'change').finally(empty);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
process.on('SIGINT', function() {
|
|
82
|
+
watcher.close();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
stat(join(CONFIG.alias['@'], './locales'), (err, stats)=>{
|
|
86
|
+
if (!err && stats.isDirectory()) {
|
|
87
|
+
watchDirectory(resolveProgramPath(isLibrary ? 'site/locales' : 'src/locales'), [
|
|
88
|
+
/^\..*/,
|
|
89
|
+
/!\.ts$/,
|
|
90
|
+
/\.d\.ts$/
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
});
|
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,273 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
|
+
import svgToMiniDataURI from 'mini-svg-data-uri';
|
|
3
|
+
import { CONFIG, PUBLICPATH, isTsc } 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, isLibrary, 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')).default
|
|
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 cssLoader = {
|
|
52
|
+
loader: 'css-loader',
|
|
53
|
+
options: {
|
|
54
|
+
modules: {
|
|
55
|
+
// 根据文件名觉得是否启用cssModules | 排除 node_modules 和 *global.css 和 *global.less
|
|
56
|
+
auto: (resourcePath)=>{
|
|
57
|
+
for(let i = 0, len = customCssModules.length; i < len; i++){
|
|
58
|
+
if (resourcePath && resourcePath?.includes(customCssModules[i])) {
|
|
59
|
+
return /(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(resourcePath);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return /(^(?!.*node_modules))(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(resourcePath);
|
|
63
|
+
},
|
|
64
|
+
// localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
|
|
65
|
+
localIdentName: '[path][name]__[local]',
|
|
66
|
+
exportLocalsConvention: 'dashesOnly'
|
|
67
|
+
},
|
|
68
|
+
importLoaders: 2
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const lessLoaderRule = [
|
|
72
|
+
styleLoader,
|
|
73
|
+
isDev && {
|
|
74
|
+
loader: '@teamsupercell/typings-for-css-modules-loader',
|
|
75
|
+
options: {
|
|
76
|
+
verifyOnly: !isDev
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
cssLoader,
|
|
80
|
+
postcssLoader,
|
|
81
|
+
cssUnicode,
|
|
82
|
+
{
|
|
83
|
+
loader: 'less-loader',
|
|
84
|
+
options: {
|
|
85
|
+
sourceMap: !!CONFIG.sourceMap,
|
|
86
|
+
lessOptions: {
|
|
87
|
+
modifyVars: modifyVars,
|
|
88
|
+
javascriptEnabled: true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
loader: 'style-resources-loader',
|
|
94
|
+
options: {
|
|
95
|
+
patterns: styleResources
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
].filter(Boolean);
|
|
99
|
+
const jsLoader = {
|
|
100
|
+
loader: isTsc ? 'ts-loader' : 'swc-loader',
|
|
101
|
+
options: isTsc ? tsLoaderConfig : swcOption(isDev)
|
|
102
|
+
};
|
|
103
|
+
function include(type) {
|
|
104
|
+
return entryResolveProgramPath.concat(CONFIG.rulesInclude?.[type]?.map(resolveNodeModulesPath) || []);
|
|
105
|
+
}
|
|
106
|
+
const includeMedia = include('media');
|
|
107
|
+
const moduleOptions = {
|
|
108
|
+
rules: [
|
|
109
|
+
isLibrary && {
|
|
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/i,
|
|
128
|
+
type: 'asset/source'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
resourceQuery: /url/i,
|
|
132
|
+
type: 'asset/resource',
|
|
133
|
+
generator: {
|
|
134
|
+
filename: (pathData)=>{
|
|
135
|
+
const filename = pathData.filename;
|
|
136
|
+
if (filename && filename.endsWith('wasm?url')) {
|
|
137
|
+
return 'wasm/[name][ext]';
|
|
138
|
+
}
|
|
139
|
+
return 'assets/[name][ext]';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
test: /\.wasm$/i,
|
|
145
|
+
type: 'webassembly/async',
|
|
146
|
+
include: include('wasm')
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
test: /\.txt$/i,
|
|
150
|
+
type: 'asset/source'
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
test: /\.ico$/i,
|
|
154
|
+
type: 'asset/inline',
|
|
155
|
+
include: includeMedia
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
test: /\.svg$/i,
|
|
159
|
+
type: 'asset/inline',
|
|
160
|
+
generator: {
|
|
161
|
+
dataUrl (content) {
|
|
162
|
+
return svgToMiniDataURI(content.toString());
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
include: includeMedia
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
test: /\.(gif|png|jpe?g|mp4)$/i,
|
|
169
|
+
type: 'asset',
|
|
170
|
+
dependency: {
|
|
171
|
+
not: [
|
|
172
|
+
'url'
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
generator: {
|
|
176
|
+
filename: 'assets/images/[name][ext]'
|
|
177
|
+
},
|
|
178
|
+
include: includeMedia
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
test: /\.(eot|ttf|otf|woff|woff2)$/i,
|
|
182
|
+
type: 'asset',
|
|
183
|
+
dependency: {
|
|
184
|
+
not: [
|
|
185
|
+
'url'
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
generator: {
|
|
189
|
+
filename: 'assets/fonts/[name][ext]'
|
|
190
|
+
},
|
|
191
|
+
include: include('font')
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
test: /\.(sa|sc)ss$/i,
|
|
195
|
+
use: [
|
|
196
|
+
styleLoader,
|
|
197
|
+
isDev && {
|
|
198
|
+
loader: '@teamsupercell/typings-for-css-modules-loader',
|
|
199
|
+
options: {
|
|
200
|
+
verifyOnly: !isDev,
|
|
201
|
+
sass: true
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
cssLoader,
|
|
205
|
+
postcssLoader,
|
|
206
|
+
cssUnicode,
|
|
207
|
+
{
|
|
208
|
+
loader: 'sass-loader',
|
|
209
|
+
options: {
|
|
210
|
+
implementation: (await import('sass')).default,
|
|
211
|
+
sassOptions: {}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
].filter(Boolean),
|
|
215
|
+
include: include('css')
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
test: /\.less$/i,
|
|
219
|
+
use: lessLoaderRule,
|
|
220
|
+
include: include('css')
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
test: /\.css$/i,
|
|
224
|
+
use: [
|
|
225
|
+
styleLoader,
|
|
226
|
+
'css-loader',
|
|
227
|
+
postcssLoader,
|
|
228
|
+
cssUnicode
|
|
229
|
+
].filter(Boolean),
|
|
230
|
+
include: include('css')
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
test: /\.(cj|mj|t|j)s(|x)$/i,
|
|
234
|
+
use: [
|
|
235
|
+
...CONFIG.prefixJsLoader,
|
|
236
|
+
jsLoader
|
|
237
|
+
].filter(Boolean),
|
|
238
|
+
include: include('js')
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
test: /\.mdx?$/i,
|
|
242
|
+
use: [
|
|
243
|
+
...CONFIG.prefixJsLoader,
|
|
244
|
+
jsLoader,
|
|
245
|
+
{
|
|
246
|
+
loader: '@mdx-js/loader',
|
|
247
|
+
options: CONFIG.mdx
|
|
248
|
+
}
|
|
249
|
+
].filter(Boolean),
|
|
250
|
+
include: entryResolveProgramPath,
|
|
251
|
+
exclude: [
|
|
252
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
253
|
+
]
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
test: /\.mdx?$/i,
|
|
257
|
+
type: 'asset/source',
|
|
258
|
+
include: [
|
|
259
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
260
|
+
]
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
type: 'asset/source',
|
|
264
|
+
include: [
|
|
265
|
+
/(.+)\/examples\/(.+).*?$/i
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
},
|
|
270
|
+
...CONFIG.moduleRules
|
|
271
|
+
].filter((e)=>typeof e === 'object')
|
|
272
|
+
};
|
|
273
|
+
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
|
+
}
|