@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.
@@ -1 +1,45 @@
1
- import{merge as e}from"webpack-merge";import t from"./app.js";import{CONFIG as i}from"./config.js";import o from"./paths.js";import{PACKAGENAME as a,pkgName as r}from"./process-env.js";let{template:p,favicon:m,...n}=Object.assign({template:`node_modules/${r}/template/index.html`,favicon:`node_modules/${r}/template/favicon.ico`},i.htmlPluginOption||{}),l=e({title:i.env?.PROJECTNAME||a.toLocaleUpperCase()||"Title",filename:"index.html",hash:!1,minify:{collapseWhitespace:!0,removeComments:!0,removeRedundantAttributes:!1,removeScriptTypeAttributes:!1,removeStyleLinkTypeAttributes:!1,removeAttributeQuotes:!0,useShortDoctype:!0},meta:{charset:"UTF-8","X-UA-Compatible":{"http-equiv":"X-UA-Compatible",content:"IE=edge,Chrome=1"},HandheldFriendly:"true",MobileOptimized:"320","screen-orientation":"portrait","x5-orientation":"portrait",browsermode:"application","x5-page-mode":"app","msapplication-tap-highlight":"no",viewport:"width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no","apple-mobile-web-app-capable":"yes",renderer:"webkit",description:t.description||""},tags:[],template:`${o.programPath}/${p}`,favicon:`${o.programPath}/${m}`},n);export default l;
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"../typings/global.js";
1
+ export * from '../typings/global.js';
package/lib/locales.js CHANGED
@@ -1,3 +1,90 @@
1
- import{existsSync as e}from"fs";import{basename as t,join as o}from"path";import{watch as a}from"chokidar";import{CONFIG as l}from"./config.js";import r from"./esm.js";import n from"./object-listener.js";import{FRAMEWORK as s,isLibrary as c}from"./process-env.js";import{resolveProgramPath as i,tfc as g}from"./utils.js";let f={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},p={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;',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;'}[s];export const locales=n({name:"@app/locales",data:"export const locales = [];"});let u={};// 要执行的函数
2
- async function d(e,o){let a=t(e).replace(/\.[^.]+$/,"");if("deleted"===o)delete u[a];else{let t=await import(r`${g(e)}`);Object.assign(u,{[a]:t.default})}let l=[],n={};for(let e in u)if(Object.prototype.hasOwnProperty.call(u,e)){let t=u[e],{language:o=a,title:r=o,icon:s,translation:c={}}=t;l.push({language:o,title:r,icon:s}),n[o]={language:o,title:r,icon:s,translation:c}}Object.assign(locales.data,{data:`${f[s]}
3
- 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(l)};const _res = ${JSON.stringify(n)};const resources = deepFreeze(_res);${p}`})}e(o(l.alias["@"],"./locales"))&&function(e,t){let o=[],l=a(e,{ignored:t,persistent:!0,ignoreInitial:!1});l.on("add",e=>{d(e,"added"),o.push(e)}),l.on("change",e=>{d(e,"change")}),l.on("unlink",e=>{d(e,"deleted"),o.splice(o.indexOf(e),1)}),l.on("ready",()=>{o.forEach(e=>{d(e,"change")})}),process.on("SIGINT",function(){l.close()})}(i(c?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/]);
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
+ }
@@ -1 +1 @@
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;";
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 e from"terser-webpack-plugin";import{merge as o}from"webpack-merge";import{swcMinifyOption as r}from"./swcrc.js";export const minify={terser:{minify:e.terserMinify,terserOptions:{ecma:2015,parse:{},compress:{global_defs:{"@alert":"console.log"},drop_console:!0,drop_debugger:!0,pure_funcs:["console.log","console.warn","console.error","console.info"]},toplevel:!1,mangle:!0,module:!1,format:{comments:!1},// nameCache: null,
2
- ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1},extractComments:!1},swc:{minify:e.swcMinify,terserOptions:r}};export const getMinifyOption=(e,r={})=>{let s=minify[e];return Object.assign(s,{terserOptions:o(s.terserOptions,r)})};
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
+ };
@@ -1 +1,11 @@
1
- import{CONFIG as i}from"./config.js";import o from"./html-plugin-option.js";let f=i.prefixCls||"n",n={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":JSON.stringify(o.favicon)};Object.assign(n,i.modifyVars);export default n;
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;
@@ -1 +1,46 @@
1
- import e from"external-remotes-plugin";import r from"webpack";import t from"webpack/lib/container/ModuleFederationPlugin.js";import{CONFIG as o}from"./config.js";import{realResolve as l}from"./utils.js";let i=r.NormalModuleReplacementPlugin,a={},n={},s={};export const moduleFederation=o.moduleFederation?.map(e=>{if(Array.isArray(e.remotes))for(let r=0,t=e.remotes.length;r<t;r++){let t=e.remotes[r],o=t.alias||t.name,l=t.filename||"remote_entry.js";if(s[o]=`${t.name}@${t.host}/${l}`,Array.isArray(t.library))for(let e=0,r=t.library.length;e<r;e++)a[t.library[e]]=`${o}/${t.library[e]}`}if(Array.isArray(e.exposes))for(let r=0,t=e.exposes.length;r<t;r++){let t=e.exposes[r];"string"==typeof t?n[`./${t}`]=l(t):"[object Object]"===Object.prototype.toString.call(t)&&(n[`./${t.name}`]=l(t.path))}return new t({filename:"remote_entry.js",...e,remotes:s,exposes:n})});moduleFederation.length&&(moduleFederation.push(new e),moduleFederation.push(new i(/(.*)/,e=>{a[e.request]&&(e.request=a[e.request])})));
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
+ }
@@ -1,3 +1,228 @@
1
- import{resolve as e}from"path";import s from"mini-css-extract-plugin";import o from"mini-svg-data-uri";import{CONFIG as t,PUBLICPATH as r}from"./config.js";import{hasPkg as l}from"./has-pkg.js";import a from"./modify-vars.js";import i from"./paths.js";import{FRAMEWORK as n,isDev as c,isMicro as m}from"./process-env.js";import p from"./swcrc.js";import d from"./tsloader.config.js";import{resolveNodeModulesPath as u,resolveProgramPath as f}from"./utils.js";let y={loader:e(i.corePath,"./loader/css-unicode.cjs")},x=m?r:"../",g={loader:s.loader,options:{publicPath:"/"!==x?x:"../"}},$=l("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};c&&(g="style-loader");let j=[...t.cssModules,`@moneko/${n}`,"neko-ui"].map(u),v=[...["src/styles/variables.less","src/styles/mixins.less","site/styles/variables.less","site/styles/mixins.less"].map(f)],h=["components","example","mock","site","src","server"].map(f),b=[g,c&&{loader:"@teamsupercell/typings-for-css-modules-loader",options:{verifyOnly:!c}},{loader:"css-loader",options:{modules:{// 根据文件名觉得是否启用cssModules | 排除 node_modules 和 *global.css 和 *global.less
2
- auto:e=>{for(let s=0,o=j.length;s<o;s++)if(e&&e?.includes(j[s]))return/(.*(?<!\.?global\.(le|c)ss)$)/i.test(e);return/(^(?!.*node_modules))(.*(?<!\.?global\.(le|c)ss)$)/i.test(e)},// localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
3
- localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},$,y,{loader:"less-loader",options:{sourceMap:!!t.sourceMap,lessOptions:{modifyVars:a,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:v}}].filter(Boolean),w={loader:"tsc"===t.compiler?"ts-loader":"swc-loader",options:"tsc"===t.compiler?d:p(c)},k=h.concat(t.rulesInclude?.media?.map(u)||[]),I=h.concat(t.rulesInclude?.fonts?.map(u)||[]),O=h.concat(t.rulesInclude?.less?.map(u)||[]),B=h.concat(t.rulesInclude?.css?.map(u)||[]),L=h.concat(t.rulesInclude?.js?.map(u)||[]),M={rules:[{test:/\.mdx?$/i,include:[f("components")],exclude:[/(.+)\/examples\/(.+).mdx?$/i],enforce:"pre",use:[{loader:e(i.corePath,"./loader/frontmatter.cjs")}]},{oneOf:[{resourceQuery:/raw/,type:"asset/source"},{test:/\.wasm$/i,type:"webassembly/async"},{test:/\.txt$/i,type:"asset/source"},{test:/\.ico$/i,type:"asset/inline",include:k},{test:/\.svg$/i,type:"asset/inline",generator:{dataUrl:e=>o("string"!=typeof e?e.toString():e)},include:k},{test:/\.(gif|png|jpe?g|mp4)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext][query]"},include:k},{test:/\.(eot|ttf|otf|woff|woff2)$/i,type:"asset",generator:{filename:"assets/fonts/[name][ext][query]"},include:I},{test:/\.less$/i,use:b,include:O},{test:/\.css$/i,use:[g,"css-loader",$,y].filter(Boolean),include:B},{test:/\.(cj|mj|t|j)s(|x)$/i,use:[...t.prefixJsLoader,w].filter(Boolean),include:L},{test:/\.mdx?$/i,use:[...t.prefixJsLoader,w,{loader:"@mdx-js/loader",options:t.mdx}].filter(Boolean),include:h,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/i,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...t.moduleRules]};export default M;
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{createConnection as t}from"net";import{networkInterfaces as e}from"os";import r from"webpack-dev-server";let{internalIPSync:o}=r;export function getNetworkAdress(){let t=e();for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e)){let r=t[e];for(let t=0;t<r.length;t++){let e=r[t];if("IPv4"===e.family&&"127.0.0.1"!==e.address&&!e.address.startsWith("169.254")&&!e.internal)return e.address}}}export function getIPv4(){return o("v4")}export function getPort(e,r,o="0.0.0.0"){return new Promise(n=>{let s=t(e,o);s.on("connect",()=>{s.destroy(),n(getPort(e+1,r,o))}),s.on("error",()=>{n(e)})})}
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
+ }
@@ -1 +1,6 @@
1
- import{CONFIG as e}from"./config.js";let t="";e.normalizeCss&&(t='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}');export default t;
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;
@@ -1 +1,28 @@
1
- export default function e(e){let t=[],n=new Proxy(e,{set:(e,n,r)=>(e[n]=r,t.forEach(t=>{t(e)}),!0)});return{data:n,listener:function(e){return t.push(e),()=>{let n=t.indexOf(e);-1!==n&&t.splice(n,1)}}}}
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 as e,mkdirSync as o}from"fs";import a from"url";let c=process.cwd(),t=`${c}/node_modules/.cache/.mo`;e(t)||o(t,{recursive:!0});export default{corePath:a.fileURLToPath(new URL(".",import.meta.url)),programPath:c,webpackCachePath:`${c}/node_modules/.temp_cache`,cachePath:t,swcCachePath:`${c}/node_modules/.cache/.swc/`,defaultConfigPath:`${c}/config/index.ts`,coveragePath:`${c}/coverage/clover.xml`,pagesPath:`${c}/src/pages`,componentsPath:`${c}/components`};
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
+ };
@@ -1 +1,6 @@
1
- import{isReact as e}from"./process-env.js";let t="";e&&(t='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;');export default t;
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;