@moneko/core 3.0.0-beta.116 → 3.0.0-beta.118
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/common/localisable.txt +34 -0
- package/lib/common.js +1 -1
- package/lib/locales.d.ts +10 -0
- package/lib/locales.js +2 -0
- package/lib/virtual-module-plugin.js +1 -1
- package/lib/webpack.common.js +1 -1
- package/package.json +1 -1
- package/typings/global.d.ts +11 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const locale = createRoot(() => {
|
|
2
|
+
const storageKey = 'localizable.language';
|
|
3
|
+
const language = localStorage.getItem(storageKey) || 'zh_CN';
|
|
4
|
+
const { translation, ...defaultLocale } = Object.assign(
|
|
5
|
+
{ title: '简体中文', language: 'zh_CN', translation: {} },
|
|
6
|
+
resources[language] || resources.zh_CN,
|
|
7
|
+
);
|
|
8
|
+
const [localizable, setLocalizable] = createStore({
|
|
9
|
+
lang: defaultLocale,
|
|
10
|
+
t: translation,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
createEffect(() => {
|
|
14
|
+
const _t = resources[localizable.lang.language]?.translation;
|
|
15
|
+
|
|
16
|
+
if (_t) {
|
|
17
|
+
setLocalizable('t', _t);
|
|
18
|
+
localStorage.setItem(storageKey, localizable.lang.language);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function setLang(localeName) {
|
|
22
|
+
const { translation: _t, ...lang } = resources[localeName] || {};
|
|
23
|
+
|
|
24
|
+
if (_t) {
|
|
25
|
+
setLocalizable('lang', lang);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { localizable, setLocalizable, setLang };
|
|
29
|
+
}, getOwner());
|
|
30
|
+
|
|
31
|
+
export const setLocalizable = locale.setLocalizable;
|
|
32
|
+
export const t = locale.localizable.t;
|
|
33
|
+
export const lang = locale.localizable.lang;
|
|
34
|
+
export const setLang = locale.setLang;
|
package/lib/common.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{accessSync as e,constants as t}from"fs";import{join as o}from"path";import s from"readline";import r from"chalk";import{merge as i}from"webpack-merge";import{APPTYPE as n,CUSTOMCONFIG as a,FRAMEWORK as l,PACKAGENAME as c,PROGRAMPATH as m,jsxImportSource as
|
|
1
|
+
import{accessSync as e,constants as t}from"fs";import{join as o}from"path";import s from"readline";import r from"chalk";import{merge as i}from"webpack-merge";import{APPTYPE as n,CUSTOMCONFIG as a,FRAMEWORK as l,PACKAGENAME as c,PROGRAMPATH as m,jsxImportSource as u,pkgName as p}from"./process-env.js";import{isFunction as d,readConf as h,resolveProgramPath as f}from"./utils.js";export const ENTRYPATH={mobile:"mobile",site:"site",backstage:"backstage",micro:"micro",library:"library"};let g=[`@moneko/${l}`,"neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app"],x={library:{"@":f("site"),"@pkg":f("components"),[c]:f("components")},mobile:{},site:{},backstage:{},micro:{}},b={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{},routeBaseName:"/",publicPath:"/",rem:{designSize:"mobile"===n?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":f("src")},x[n]),layoutSider:{},moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:`${m}/node_modules/.temp_cache`,devServer:{allowedHosts:[".baidu.com"],host:"localhost",port:3e3,https:!1,compress:!1},htmlPluginOption:{template:`./node_modules/${p}/template/index.html`,favicon:`./node_modules/${p}/template/favicon.ico`,tags:[]},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],splitChunk:{chunks:"all",minSize:1024,minChunks:1,cacheGroups:{route:{test:/[\\/].git[\\/]router/,priority:-10,reuseExistingChunk:!0,name:"route"},example:{test:/[\\/].git[\\/]example/,priority:-10,reuseExistingChunk:!0,name:"example"}}},runtimeChunk:"single",moduleFederation:[],rulesInclude:{less:g,css:g,js:g,media:g,fonts:g},mdx:{jsxImportSource:u,useDynamicImport:!0,remarkPlugins:[],rehypePlugins:[]},jsxDomExpressions:{moduleName:"solid-js/web",builtIns:["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"],contextToCustomElements:!0,wrapConditionals:!0,generate:"dom",hydratable:!1},bar:{name:"编译中",color:"#6f42c1"},virtualModule:{},normalizeCss:!0,externalsPresets:{}};export const log=e=>{s.cursorTo(process.stdout,0),process.stdout.write(e)};let y=b,C=null,w={},k={};try{C=o(m,"./config/index.ts"),e(C,t.R_OK)}catch(e){C=null}if(C)try{let e=(await h(C,"index")).default;w=d(e)?e(process):e}catch(e){process.stdout.write(r.red(e))}if(a){let s=null;try{s=o(m,`./config/${a}.ts`),e(s,t.R_OK)}catch(e){s=null}if(null!==s)try{let e=(await h(s,a)).default;k=d(e)?e(process):e}catch(e){process.stdout.write(r.red(e))}}"tsc"===(y=i(y,w,k)).compiler&&y.minifier&&(y.minifier.js||Object.assign(y.minifier,{js:{type:"terser"}}),y.minifier.css||Object.assign(y.minifier,{css:{type:"cssnano"}})),!1===y.devtool&&(y.sourceMap=!1),!1===y.sourceMap&&(y.devtool=!1),y.fixBrowserRouter&&y.htmlPluginOption&&(y.htmlPluginOption.tags||(y.htmlPluginOption.tags=[]),y.htmlPluginOption.tags.push({textContent:'!function(n){var a=location.search.slice(1);if("/"===a[0]){for(var o=[],c=decodeURIComponent(a).split("&"),e=0,t=c.length;e<t;e++)o.push(c[e].replace(/~and~/g,"&"));var l=o.join("&");l!==a&&window.history.replaceState(null,null,"".concat(n.pathname.slice(0,-1),"?").concat(l).concat(n.hash))}}(window.location);'}));export const CONFIG=y;export const PUBLICPATH=CONFIG.publicPath||"/";export let hasCustomRouter=!1;try{e(o(CONFIG.alias["@"],"./router/index.ts"),t.R_OK),hasCustomRouter=!0}catch(e){hasCustomRouter=!1}global.NEKOCLICONFIG={CONFIG,log};
|
package/lib/locales.d.ts
ADDED
package/lib/locales.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{readFileSync as e}from"fs";import{basename as o,join as t}from"path";import{watch as r}from"chokidar";import s from"./app.js";import n from"./esm.js";import c from"./object-listener.js";import{FRAMEWORK as i,__dirname as l,isLibrary as a}from"./process-env.js";import{resolveProgramPath as p,tfc as f}from"./utils.js";let d={react:"",solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},m={react:"",solid:e(t(l,"./common/localisable.txt"),{encoding:"utf-8"})};export const locales=c({name:"@app/locales",data:"export const locales = [];export const resources = {};"});let u={};async function g(e,t){let r=o(e).replace(/\.[^.]+$/,"");if("deleted"===t)delete u[r];else{let o=await import(n`${f(e)}`);Object.assign(u,{[r]:o.default})}let s=[],c={};for(let e in u)if(Object.prototype.hasOwnProperty.call(u,e)){let o=u[e],{language:t=r,title:n=t,icon:i,translation:l={}}=o;s.push({language:t,title:n,icon:i}),c[t]={language:t,title:n,icon:i,translation:l}}Object.assign(locales.data,{data:`${d[i]}
|
|
2
|
+
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(s)};const _res = ${JSON.stringify(c)};const resources = deepFreeze(_res);${m[i]}`})}s.locales&&function(e,o){let t=[],s=r(e,{ignored:o,persistent:!0,ignoreInitial:!1});s.on("add",e=>{g(e,"added"),t.push(e)}),s.on("change",e=>{g(e,"change")}),s.on("unlink",e=>{g(e,"deleted"),t.splice(t.indexOf(e),1)}),s.on("ready",()=>{t.forEach(e=>{g(e,"change")})}),process.on("SIGINT",function(){s.close()})}(p(a?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"webpack-virtual-modules";import{docs as
|
|
1
|
+
import t from"webpack-virtual-modules";import{docs as e}from"./docs.js";import{locales as o}from"./locales.js";import{isLibrary as a}from"./process-env.js";import{example as r,route as i}from"./routes.js";import{resolveNodeModulesPath as l}from"./utils.js";export default class{constructor(t){this.options=t}apply(s){let p=new t({[l(i.data.name)]:i.data.data,[l(r.data.name)]:"export default []",[l(o.data.name)]:o.data.data});i.listener(t=>{t.data&&p.writeModule(l(t.name),t.data)}),o.listener(t=>{t.data&&p.writeModule(l(t.name),t.data)}),a&&(r.listener(t=>{let e=t.data;for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&e[t]&&p.writeModule(l(t),e[t])}),e.listener(t=>{for(let e in t)Object.prototype.hasOwnProperty.call(t,e)&&t[e]&&p.writeModule(l(e),t[e])})),p.apply(s),s.hooks.compilation.tap("VirtualModulePlugin",()=>{for(let t in this.options)if(Object.prototype.hasOwnProperty.call(this.options,t)){let e=this.options[t];"string"==typeof e?p.writeModule(l(t),e):p.writeModule(l(t),`export default ${JSON.stringify(e)}`)}})}};
|
package/lib/webpack.common.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import o from"webpack";import l from"webpackbar";import"./cleanup.js";import{CONFIG as n,PUBLICPATH as r}from"./common.js";import i from"./define.js";import a from"./done.js";import p from"./html-add-entry-attr.js";import m from"./html-plugin-option.js";import{moduleFederation as c}from"./module-federation.js";import u from"./module.config.js";import{CUSTOMCONFIG as f,DEV as
|
|
1
|
+
import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import o from"webpack";import l from"webpackbar";import"./cleanup.js";import{CONFIG as n,PUBLICPATH as r}from"./common.js";import i from"./define.js";import a from"./done.js";import p from"./html-add-entry-attr.js";import m from"./html-plugin-option.js";import{moduleFederation as c}from"./module-federation.js";import u from"./module.config.js";import{CUSTOMCONFIG as f,DEV as d,PACKAGENAME as h,PROGRAMPATH as j,hasEslintConfig as y,hasStylelintConfig as g,isLibrary as w,isMicro as b}from"./process-env.js";import{seo as x}from"./seo.js";import{resolveNodeModulesPath as k,resolveProgramPath as v}from"./utils.js";import C from"./virtual-module-plugin.js";import $ from"./virtual-modules.js";let{AutomaticPrefetchPlugin:O,DefinePlugin:B,SourceMapDevToolPlugin:P,WatchIgnorePlugin:A}=o,M=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],S=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],T=e.readdirSync(j),D=!1,K=!1;for(let e=0,t=T.length;e<t;e++)S.includes(T[e])&&(K=!0),M.includes(T[e])&&(D=!0);D||(D=y),K||(K=g);let L=K?(await import("stylelint-webpack-plugin")).default:null,F=D?(await import("eslint-webpack-plugin")).default:null,R=n.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:v(w?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:"js/[chunkhash].js",assetModuleFilename:"assets/[hash][ext][query]",library:{name:h,type:"window"},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${h}`,pathinfo:d,clean:!0,publicPath:r,asyncChunks:!0};let W={main:k("@app/entry")};n.entry&&("string"==typeof n.entry?W=n.entry:Object.keys(n.entry)&&Object.assign(W,n.entry)),n.output&&("string"==typeof n.output?outputConfig.path=n.output:Object.keys(n.output)&&Object.assign(outputConfig,n.output));let _=n.routeBaseName.split("/").filter(Boolean).length,q=`${Array(_).fill("..").join("/")+(_?"/":"")}404.html`,{pathSegmentsToKeep:G=_,path:H=q}=n.fixBrowserRouter||{},J=!1;n.cacheDirectory&&(J={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:n.cacheDirectory,memoryCacheUnaffected:!0,name:`${f||"default"}-${d?"development":"production"}`});export const clientConfig={entry:W,stats:"errors-only",cache:J,infrastructureLogging:{level:"none"},target:"web",externalsPresets:n.externalsPresets,plugins:[new O,...c,F&&new F({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"]}),L&&new L({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","docs/","coverage/","dist/"]}),n.htmlPluginOption&&new s(m),n.fixBrowserRouter&&new s({filename:H,inject:!1,templateContent:()=>`<html html><head><title>${m.title}</title><script>var pathSegmentsToKeep = ${G||_};var l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}),new t(R),b&&new p(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new B(i),new A({paths:[/\.d\.ts$/]}),n.sourceMap&&new P(n.sourceMap),n.bar&&new l(n.bar),new a({done:()=>{!d&&n.seo&&x(),n.done?.(),d||setTimeout(()=>{process.exit(0)},2e3)}}),new C($),...n.plugins].filter(Boolean),experiments:{topLevelAwait:!0,syncWebAssembly:!0,asyncWebAssembly:!0},resolve:{extensions:[".tsx",".ts",".js",".jsx"],alias:n.alias,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:u,externals:n.externals,output:outputConfig};
|
package/package.json
CHANGED
package/typings/global.d.ts
CHANGED
|
@@ -242,7 +242,17 @@ export declare type ConfigType<T extends 'tsc' | 'swc' = 'swc'> = {
|
|
|
242
242
|
media?: string[];
|
|
243
243
|
fonts?: string[];
|
|
244
244
|
};
|
|
245
|
-
|
|
245
|
+
/** bundle分析
|
|
246
|
+
* @default false
|
|
247
|
+
* @example
|
|
248
|
+
* // 推荐
|
|
249
|
+
* {
|
|
250
|
+
* analyzerMode: 'static',
|
|
251
|
+
* reportFilename: 'report.html',
|
|
252
|
+
* openAnalyzer: false,
|
|
253
|
+
* }
|
|
254
|
+
*/
|
|
255
|
+
bundleAnalyzer: BundleAnalyzerPlugin.Options | false;
|
|
246
256
|
/** seo优化
|
|
247
257
|
* @default false
|
|
248
258
|
*/
|