@moneko/core 3.1.4 → 3.1.5-beta.1

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.js CHANGED
@@ -1,2 +1,177 @@
1
- import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import o from"webpack";import n from"webpackbar";import"./cleanup.js";import{CONFIG as l,PUBLICPATH as r}from"./config.js";import i from"./done.js";import a from"./html-add-entry-attr.js";import p from"./html-plugin-option.js";import{moduleFederation as m}from"./module-federation.js";import c from"./module.config.js";import u from"./paths.js";import{CUSTOMCONFIG as f,PACKAGENAME as h,hasEslintConfig as d,hasStylelintConfig as j,isDev as y,isLibrary as g,isMicro as b}from"./process-env.js";import{seo as w}from"./seo.js";import{resolveNodeModulesPath as x,resolveProgramPath as k}from"./utils.js";import v from"./virtual-module-plugin.js";import C from"./virtual-modules.js";let{AutomaticPrefetchPlugin:O,DefinePlugin:$,SourceMapDevToolPlugin:P,WatchIgnorePlugin:D}=o,N=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],S=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],A=e.readdirSync(u.programPath),B=!1,E=!1;for(let e=0,t=A.length;e<t;e++)S.includes(A[e])&&(E=!0),N.includes(A[e])&&(B=!0);B||(B=d),E||(E=j);let M=E?(await import("stylelint-webpack-plugin")).default:null,T=B?(await import("eslint-webpack-plugin")).default:null,_=l.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:k(g?"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:y,clean:!0,publicPath:r,asyncChunks:!0};let K={main:x("@app/entry")};l.entry&&("string"==typeof l.entry?K=l.entry:Object.keys(l.entry)&&Object.assign(K,l.entry)),l.output&&("string"==typeof l.output?outputConfig.path=l.output:Object.keys(l.output)&&Object.assign(outputConfig,l.output));let L=l.basename.split("/").filter(Boolean).length,F=`${Array(L).fill("..").join("/")+(L?"/":"")}404.html`,{pathSegmentsToKeep:J=L,path:R=F}=l.fixBrowserRouter||{},V=!1;l.cacheDirectory&&(V={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:l.cacheDirectory,memoryCacheUnaffected:!0,name:`${f||"default"}-${y?"development":"production"}`});export const clientConfig={entry:K,stats:"errors-only",cache:V,infrastructureLogging:{level:"none"},target:"web",externalsPresets:l.externalsPresets,plugins:[new O,...m,T&&new T({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"]}),M&&new M({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","docs/","coverage/","dist/"]}),l.htmlPluginOption&&new s(p),l.fixBrowserRouter&&new s({filename:R,inject:!1,templateContent:()=>`<html html><head><title>${p.title}</title><script>var pathSegmentsToKeep = ${J||L};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(_),b&&new a(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new $({"process.env":JSON.stringify({...l.env,// mf 需要 isDev
2
- NODE_ENV:process.env.NODE_ENV})}),new D({paths:[/\.d\.ts$/]}),l.sourceMap&&new P(l.sourceMap),l.bar&&new n(l.bar),new i({done:()=>{!y&&l.seo&&w(),l.done?.(),y||setTimeout(()=>{process.exit(0)},2e3)}}),new v(C),...l.plugins].filter(Boolean),experiments:{topLevelAwait:!0,syncWebAssembly:!0,asyncWebAssembly:!0},resolve:{extensions:[".tsx",".ts",".js",".jsx"],alias:l.alias,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:c,externals:l.externals,output:outputConfig};
1
+ import e from 'fs';
2
+ import t from 'add-asset-html-webpack-plugin';
3
+ import s from 'html-webpack-plugin';
4
+ import o from 'webpack';
5
+ import n from 'webpackbar';
6
+ import './cleanup.js';
7
+ import { CONFIG as l, PUBLICPATH as r } from './config.js';
8
+ import i from './done.js';
9
+ import a from './html-add-entry-attr.js';
10
+ import p from './html-plugin-option.js';
11
+ import { moduleFederation as c } from './module-federation.js';
12
+ import m from './module.config.js';
13
+ import u from './paths.js';
14
+ import {
15
+ CUSTOMCONFIG as f,
16
+ PACKAGENAME as d,
17
+ PACKAGEVERSION as h,
18
+ hasEslintConfig as j,
19
+ hasStylelintConfig as y,
20
+ isDev as g,
21
+ isLibrary as b,
22
+ isMicro as w,
23
+ } from './process-env.js';
24
+ import { seo as x } from './seo.js';
25
+ import { resolveNodeModulesPath as k, resolveProgramPath as v } from './utils.js';
26
+ import C from './virtual-module-plugin.js';
27
+ import $ from './virtual-modules.js';
28
+ let {
29
+ AutomaticPrefetchPlugin: O,
30
+ DefinePlugin: P,
31
+ SourceMapDevToolPlugin: M,
32
+ WatchIgnorePlugin: S,
33
+ } = o,
34
+ B = ['.eslintrc.js', '.eslintrc.json', '.eslintrc.yaml', '.eslintrc.json'],
35
+ D = [
36
+ '.stylelintrc',
37
+ '.stylelintrc.json',
38
+ '.stylelintrc.yaml',
39
+ '.stylelintrc.yml',
40
+ '.stylelintrc.js',
41
+ 'stylelint.config.js',
42
+ 'stylelint.config.cjs',
43
+ ],
44
+ T = e.readdirSync(u.programPath),
45
+ A = !1,
46
+ H = !1;
47
+ for (let e = 0, t = T.length; e < t; e++)
48
+ D.includes(T[e]) && (H = !0), B.includes(T[e]) && (A = !0);
49
+ A || (A = j), H || (H = y);
50
+ let K = H ? (await import('stylelint-webpack-plugin')).default : null,
51
+ L = A ? (await import('eslint-webpack-plugin')).default : null,
52
+ F = l.assetHtml.map((e) => ({ publicPath: '', ...e }));
53
+ export const outputConfig = {
54
+ path: v(b ? 'docs' : 'dist'),
55
+ filename: 'js/[name].bundle.js',
56
+ chunkFilename: `js/[${g ? 'name' : 'chunkhash'}].js`,
57
+ assetModuleFilename: 'assets/[hash][ext][query]',
58
+ library: { name: d, type: 'window' },
59
+ globalObject: 'window',
60
+ chunkLoadingGlobal: `webpackJsonp_${d}`,
61
+ pathinfo: g,
62
+ clean: !0,
63
+ publicPath: r,
64
+ asyncChunks: !0,
65
+ charset: !0,
66
+ };
67
+ let J = { main: k('@app/entry') };
68
+ l.entry &&
69
+ ('string' == typeof l.entry ? (J = l.entry) : Object.keys(l.entry) && Object.assign(J, l.entry)),
70
+ l.output &&
71
+ ('string' == typeof l.output
72
+ ? (outputConfig.path = l.output)
73
+ : Object.keys(l.output) && Object.assign(outputConfig, l.output));
74
+ let R = l.basename.split('/').filter(Boolean).length,
75
+ U = `${Array(R).fill('..').join('/') + (R ? '/' : '')}404.html`,
76
+ { pathSegmentsToKeep: _ = R, path: q = U } = l.fixBrowserRouter || {},
77
+ z = !1;
78
+ l.cacheDirectory &&
79
+ (z = {
80
+ type: 'filesystem',
81
+ store: 'pack',
82
+ allowCollectingMemory: !0,
83
+ cacheDirectory: l.cacheDirectory,
84
+ memoryCacheUnaffected: !0,
85
+ name: `${f || 'default'}-${g ? 'development' : 'production'}`,
86
+ version: h,
87
+ });
88
+ export const clientConfig = {
89
+ entry: J,
90
+ stats: 'errors-only',
91
+ cache: z,
92
+ infrastructureLogging: { level: 'none' },
93
+ target: 'web',
94
+ externalsPresets: l.externalsPresets,
95
+ plugins: [
96
+ new O(),
97
+ ...c,
98
+ L &&
99
+ new L({
100
+ fix: !0,
101
+ threads: !0,
102
+ extensions: [
103
+ 'js',
104
+ 'md',
105
+ 'mdx',
106
+ 'cjs',
107
+ 'ejs',
108
+ 'mjs',
109
+ 'jsx',
110
+ 'ts',
111
+ 'tsx',
112
+ 'json',
113
+ 'html',
114
+ 'coffee',
115
+ 'vue',
116
+ ],
117
+ }),
118
+ K &&
119
+ new K({
120
+ fix: !0,
121
+ threads: !0,
122
+ extensions: ['css', 'scss', 'sass', 'less', 'ts', 'tsx', 'js', 'jsx'],
123
+ exclude: ['node_modules/', 'es/', 'lib/', 'docs/', 'coverage/', 'dist/'],
124
+ }),
125
+ l.htmlPluginOption && new s(p),
126
+ l.fixBrowserRouter &&
127
+ new s({
128
+ filename: q,
129
+ inject: !1,
130
+ templateContent: () =>
131
+ `<html html><head><title>${p.title}</title><script>var pathSegmentsToKeep = ${
132
+ _ || R
133
+ };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>`,
134
+ }),
135
+ new t(F),
136
+ w && new a((e) => !!(e.match(/main\.(.*)\.bundle.js$/) || e.match('main.bundle.js'))),
137
+ new P({ 'process.env': JSON.stringify(l.env) }),
138
+ new S({ paths: [/\.d\.ts$/] }),
139
+ l.sourceMap && new M(l.sourceMap),
140
+ l.bar && new n(l.bar),
141
+ new i({
142
+ done: () => {
143
+ !g && l.seo && x(),
144
+ l.done?.(),
145
+ g ||
146
+ setTimeout(() => {
147
+ process.exit(0);
148
+ }, 2e3);
149
+ },
150
+ }),
151
+ new C($),
152
+ ...l.plugins,
153
+ ].filter(Boolean),
154
+ experiments: {
155
+ asset: true,
156
+ importAsync: true,
157
+ importAwait: true,
158
+ topLevelAwait: !0,
159
+ asyncWebAssembly: !0,
160
+ cacheUnaffected: !0,
161
+ layers: !0,
162
+ lazyCompilation: g && { imports: !1, entries: !1 },
163
+ buildHttp: l.buildHttp,
164
+ backCompat: !0,
165
+ futureDefaults: !0,
166
+ css: !1,
167
+ outputModule: !1,
168
+ },
169
+ resolve: {
170
+ extensions: ['.tsx', '.ts', '.js', '.jsx', '.wasm'],
171
+ alias: l.alias,
172
+ fallback: { path: !1, fs: !1, crypto: !1, assert: !1 },
173
+ },
174
+ module: m,
175
+ externals: l.externals,
176
+ output: outputConfig,
177
+ };
package/lib/config.js CHANGED
@@ -1 +1 @@
1
- import{accessSync as e,constants as t}from"fs";import o from"readline";import s from"chalk";import{merge as r}from"webpack-merge";import i from"./paths.js";import{APPTYPE as a,CUSTOMCONFIG as l,FRAMEWORK as n,PACKAGENAME as c,jsxImportSource as m,pkgName as p}from"./process-env.js";import{isFunction as u,readConf as d,resolveProgramPath as h}from"./utils.js";export const ENTRYPATH={mobile:"mobile",site:"site",backstage:"backstage",micro:"micro",library:"library"};let f=["@moneko/core",`@moneko/${n}`,"neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app"],g={library:{"@":h("site"),"@pkg":h("components"),[c]:h("components")},mobile:{},site:{},backstage:{},micro:{}},b={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{},basename:"/",publicPath:"/",rem:{designSize:"mobile"===a?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":h("src")},g[a]),moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:i.webpackCachePath,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:f,css:f,js:f,media:f,fonts:f},mdx:{jsxImportSource:m,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=>{o.cursorTo(process.stdout,0),process.stdout.write(e)};let x=b,y=null,C={},w={};try{y=i.defaultConfigPath,e(y,t.R_OK)}catch(e){y=null}if(y)try{let e=(await d(y,"index")).default;C=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}if(l){let o=null;try{o=`${i.programPath}/config/${l}.ts`,e(o,t.R_OK)}catch(e){o=null}if(null!==o)try{let e=(await d(o,l)).default;w=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}}"tsc"===(x=r(x,C,w)).compiler&&x.minifier&&(x.minifier.js||Object.assign(x.minifier,{js:{type:"terser"}}),x.minifier.css||Object.assign(x.minifier,{css:{type:"cssnano"}})),!1===x.devtool&&(x.sourceMap=!1),!1===x.sourceMap&&(x.devtool=!1),x.fixBrowserRouter&&x.htmlPluginOption&&(x.htmlPluginOption.tags||(x.htmlPluginOption.tags=[]),x.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=x;export const PUBLICPATH=CONFIG.publicPath||"/";export let hasCustomRouter=!1;try{e(`${CONFIG.alias["@"]}/router/index.ts`,t.R_OK),hasCustomRouter=!0}catch(e){hasCustomRouter=!1}global.NEKOCLICONFIG={CONFIG,log};
1
+ import{accessSync as e,constants as t}from"fs";import o from"readline";import s from"chalk";import{merge as r}from"webpack-merge";import i from"./paths.js";import{APPTYPE as a,CUSTOMCONFIG as l,FRAMEWORK as n,PACKAGENAME as c,jsxImportSource as m,pkgName as p}from"./process-env.js";import{isFunction as u,readConf as d,resolveProgramPath as h}from"./utils.js";export const ENTRYPATH={mobile:"mobile",site:"site",backstage:"backstage",micro:"micro",library:"library"};let f=["@moneko/core",`@moneko/${n}`,"neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app"],g={library:{"@":h("site"),"@pkg":h("components"),[c]:h("components")},mobile:{},site:{},backstage:{},micro:{}},b={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{NODE_ENV:process.env.NODE_ENV},basename:"/",publicPath:"/",rem:{designSize:"mobile"===a?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":h("src")},g[a]),moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:i.webpackCachePath,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:f,css:f,js:f,media:f,fonts:f,wasm:[]},mdx:{jsxImportSource:m,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:{},buildHttp:void 0};export const log=e=>{o.cursorTo(process.stdout,0),process.stdout.write(e)};let x=b,y=null,w={},C={};try{y=i.defaultConfigPath,e(y,t.R_OK)}catch(e){y=null}if(y)try{let e=(await d(y,"index")).default;w=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}if(l){let o=null;try{o=`${i.programPath}/config/${l}.ts`,e(o,t.R_OK)}catch(e){o=null}if(null!==o)try{let e=(await d(o,l)).default;C=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}}"tsc"===(x=r(x,w,C)).compiler&&x.minifier&&(x.minifier.js||Object.assign(x.minifier,{js:{type:"terser"}}),x.minifier.css||Object.assign(x.minifier,{css:{type:"cssnano"}})),!1===x.devtool&&(x.sourceMap=!1),!1===x.sourceMap&&(x.devtool=!1),x.fixBrowserRouter&&x.htmlPluginOption&&(x.htmlPluginOption.tags||(x.htmlPluginOption.tags=[]),x.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=x;export const PUBLICPATH=CONFIG.publicPath||"/";export let hasCustomRouter=!1;try{e(`${CONFIG.alias["@"]}/router/index.ts`,t.R_OK),hasCustomRouter=!0}catch(e){hasCustomRouter=!1}global.NEKOCLICONFIG={CONFIG,log};
@@ -1,4 +1,4 @@
1
- export default /**
1
+ import t from"html-webpack-plugin";export default /**
2
2
  * 向 html-webpack-plugin 导出的 HTML 模板 script 添加属性
3
3
  * ```javascript
4
4
  * // 假设输出 main chunk 为 main.[hash].chunk.js。
@@ -8,11 +8,12 @@ export default /**
8
8
  * })),
9
9
  * ```
10
10
  */class{// eslint-disable-next-line no-unused-vars
11
- constructor(t){this.entryMatchCallback=t}apply(t){t.hooks.compilation.tap("AddEntryAttributeWebpackPlugin",a=>{// 通过最终的 webpack 配置的 plugins 属性,根据插件的 constructor.name 拿到 html-webpack-plugin 实例
12
- let e=t.options.plugins.map(({constructor:t})=>t).find(t=>t&&"HtmlWebpackPlugin"===t.name);// .find(
13
- // (plugin) => plugin instanceof HtmlWebpackPlugin,
11
+ constructor(t){this.entryMatchCallback=t}apply(a){a.hooks.compilation.tap("AddEntryAttributeWebpackPlugin",e=>{// 通过最终的 webpack 配置的 plugins 属性,根据插件的 constructor.name 拿到 html-webpack-plugin 实例
12
+ let r=a.options.plugins// .map(({ constructor }) => constructor)
13
+ // .find(
14
+ // (constructor) => constructor && constructor.name === 'HtmlWebpackPlugin',
14
15
  // ) as typeof HtmlWebpackPlugin;
15
- if(e){// 获取 html-webpack-plugin 所有的 hooks
16
- let t=e.getHooks(a);// 在插入标签之前做些什么
16
+ .find(a=>a instanceof t);if(r){// 获取 html-webpack-plugin 所有的 hooks
17
+ let t=r.getHooks(e);// 在插入标签之前做些什么
17
18
  t.alterAssetTagGroups.tap("AddEntryAttributeWebpackPlugin",t=>(// 拿到所有的标签,如果是 script 标签,并且满足我们的匹配函数,则将其 attributes['entry'] 设为 true
18
19
  t.headTags.forEach(t=>{"script"===t.tagName&&this.entryMatchCallback(t.attributes.src)&&(t.attributes.entry=!0)}),t))}})}}
package/lib/locales.js CHANGED
@@ -1,3 +1,3 @@
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{FRAMEWORK as s,isLibrary as n}from"./process-env.js";import c from"./reactive-object.js";import{resolveProgramPath as i,tfc as g}from"./utils.js";let p={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},f={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 localesModuleName="@app/locales";export const locales=new c({[localesModuleName]:"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}}locales.setData(localesModuleName,`${p[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);${f}`)}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(n?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/]);
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{FRAMEWORK as n,isLibrary as s}from"./process-env.js";import c from"./reactive-object.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;'}[n];function u(e,t){return`${f[n]}
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(e)};const _res = ${JSON.stringify(t)};const resources = deepFreeze(_res);${p}`}export const localesModuleName="@app/locales";export const locales=new c({[localesModuleName]:u([],{})});let d={};// 要执行的函数
3
+ async function m(e,o){let a=t(e).replace(/\.[^.]+$/,"");if("deleted"===o)delete d[a];else{let t=await import(r`${g(e)}`);Object.assign(d,{[a]:t.default})}let l=[],n={};for(let e in d)if(Object.prototype.hasOwnProperty.call(d,e)){let t=d[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}}locales.setData(localesModuleName,u(l,n))}e(o(l.alias["@"],"./locales"))&&function(e,t){let o=[],l=a(e,{ignored:t,persistent:!0,ignoreInitial:!1});l.on("add",e=>{m(e,"added"),o.push(e)}),l.on("change",e=>{m(e,"change")}),l.on("unlink",e=>{m(e,"deleted"),o.splice(o.indexOf(e),1)}),l.on("ready",()=>{o.forEach(e=>{m(e,"change")})}),process.on("SIGINT",function(){l.close()})}(i(s?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/]);
@@ -1,3 +1,3 @@
1
- import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import{CONFIG as o,PUBLICPATH as t}from"./config.js";import{hasPkg as r}from"./has-pkg.js";import l from"./modify-vars.js";import a from"./paths.js";import{FRAMEWORK as i,isDev as n,isMicro as c}from"./process-env.js";import m from"./swcrc.js";import p from"./tsloader.config.js";import{resolveNodeModulesPath as d,resolveProgramPath as u}from"./utils.js";let f={loader:`${a.corePath}/loader/css-unicode.cjs`},y=c?t:"../",x={loader:e.loader,options:{publicPath:"/"!==y?y:"../"}},$=r("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};n&&(x="style-loader");let g=[...o.cssModules,`@moneko/${i}`,"neko-ui"].map(d),j=[...["src/styles/variables.less","src/styles/mixins.less","site/styles/variables.less","site/styles/mixins.less"].map(u)],v=["components","example","mock","site","src","server"].map(u),b=[x,n&&{loader:"@teamsupercell/typings-for-css-modules-loader",options:{verifyOnly:!n}},{loader:"css-loader",options:{modules:{// 根据文件名觉得是否启用cssModules | 排除 node_modules 和 *global.css 和 *global.less
1
+ import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import{CONFIG as o,PUBLICPATH as t}from"./config.js";import{hasPkg as l}from"./has-pkg.js";import r from"./modify-vars.js";import a from"./paths.js";import{FRAMEWORK as i,isDev as n,isMicro as c}from"./process-env.js";import m from"./swcrc.js";import p from"./tsloader.config.js";import{resolveNodeModulesPath as d,resolveProgramPath as u}from"./utils.js";let f={loader:`${a.corePath}/loader/css-unicode.cjs`},y=c?t:"../",x={loader:e.loader,options:{publicPath:"/"!==y?y:"../"}},$=l("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};n&&(x="style-loader");let g=[...o.cssModules,`@moneko/${i}`,"neko-ui"].map(d),j=[...["src/styles/variables.less","src/styles/mixins.less","site/styles/variables.less","site/styles/mixins.less"].map(u)],v=["components","example","mock","site","src","server"].map(u),w=[x,n&&{loader:"@teamsupercell/typings-for-css-modules-loader",options:{verifyOnly:!n}},{loader:"css-loader",options:{modules:{// 根据文件名觉得是否启用cssModules | 排除 node_modules 和 *global.css 和 *global.less
2
2
  auto:e=>{for(let s=0,o=g.length;s<o;s++)if(e&&e?.includes(g[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}},$,f,{loader:"less-loader",options:{sourceMap:!!o.sourceMap,lessOptions:{modifyVars:l,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:j}}].filter(Boolean),h={loader:"tsc"===o.compiler?"ts-loader":"swc-loader",options:"tsc"===o.compiler?p:m(n)},w=v.concat(o.rulesInclude?.media?.map(d)||[]),k=v.concat(o.rulesInclude?.fonts?.map(d)||[]),I=v.concat(o.rulesInclude?.less?.map(d)||[]),O=v.concat(o.rulesInclude?.css?.map(d)||[]),B=v.concat(o.rulesInclude?.js?.map(d)||[]),L={rules:[{test:/\.mdx?$/i,include:[u("components")],exclude:[/(.+)\/examples\/(.+).mdx?$/i],enforce:"pre",use:[{loader:`${a.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:w},{test:/\.svg$/i,type:"asset/inline",generator:{dataUrl:e=>s("string"!=typeof e?e.toString():e)},include:w},{test:/\.(gif|png|jpe?g|mp4)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext][query]"},include:w},{test:/\.(eot|ttf|otf|woff|woff2)$/i,type:"asset",generator:{filename:"assets/fonts/[name][ext][query]"},include:k},{test:/\.less$/i,use:b,include:I},{test:/\.css$/i,use:[x,"css-loader",$,f].filter(Boolean),include:O},{test:/\.(cj|mj|t|j)s(|x)$/i,use:[...o.prefixJsLoader,h].filter(Boolean),include:B},{test:/\.mdx?$/i,use:[...o.prefixJsLoader,h,{loader:"@mdx-js/loader",options:o.mdx}].filter(Boolean),include:v,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/i,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...o.moduleRules]};export default L;
3
+ localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},$,f,{loader:"less-loader",options:{sourceMap:!!o.sourceMap,lessOptions:{modifyVars:r,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:j}}].filter(Boolean),b={loader:"tsc"===o.compiler?"ts-loader":"swc-loader",options:"tsc"===o.compiler?p:m(n)},h=v.concat(o.rulesInclude?.media?.map(d)||[]),I=v.concat(o.rulesInclude?.fonts?.map(d)||[]),k=v.concat(o.rulesInclude?.less?.map(d)||[]),O=v.concat(o.rulesInclude?.css?.map(d)||[]),B=v.concat(o.rulesInclude?.js?.map(d)||[]),L=v.concat(o.rulesInclude?.wasm?.map(d)||[]),M={rules:[{test:/\.mdx?$/i,include:[u("components")],exclude:[/(.+)\/examples\/(.+).mdx?$/i],enforce:"pre",use:[{loader:`${a.corePath}/loader/frontmatter.cjs`}]},{oneOf:[{resourceQuery:/raw/,type:"asset/source"},{test:/\.wasm$/i,type:"webassembly/async",include:L},{test:/\.txt$/i,type:"asset/source"},{test:/\.ico$/i,type:"asset/inline",include:h},{test:/\.svg$/i,type:"asset/inline",generator:{dataUrl:e=>s("string"!=typeof e?e.toString():e)},include:h},{test:/\.(gif|png|jpe?g|mp4)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext][query]"},include:h},{test:/\.(eot|ttf|otf|woff|woff2)$/i,type:"asset",generator:{filename:"assets/fonts/[name][ext][query]"},include:I},{test:/\.less$/i,use:w,include:k},{test:/\.css$/i,use:[x,"css-loader",$,f].filter(Boolean),include:O},{test:/\.(cj|mj|t|j)s(|x)$/i,use:[...o.prefixJsLoader,b].filter(Boolean),include:B},{test:/\.mdx?$/i,use:[...o.prefixJsLoader,b,{loader:"@mdx-js/loader",options:o.mdx}].filter(Boolean),include:v,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/i,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...o.moduleRules]};export default M;
package/lib/prod.js CHANGED
@@ -1,5 +1,5 @@
1
- import e from"css-minimizer-webpack-plugin";import i from"mini-css-extract-plugin";import n from"terser-webpack-plugin";import m from"webpack";import{BundleAnalyzerPlugin as o}from"webpack-bundle-analyzer";import{merge as r}from"webpack-merge";import{clientConfig as s}from"./common.js";import{CONFIG as t}from"./config.js";import{getMinifyOption as p}from"./minify.js";let{optimize:l}=m,{cssnanoMinify:u,swcMinify:c}=e,a="swc"===t.compiler,f=[];t.minifier&&(t.minifier.js&&f.push(new n(p(t.minifier.js?.type||(a?"swc":"terser"),t.minifier.js?.options))),t.minifier.css&&f.push(new e({minify:{swc:c,cssnano:u}[t.minifier.css?.type||(a?"swc":"cssnano")],minimizerOptions:t.minifier.css?.options})));let d={splitChunks:t.splitChunk,runtimeChunk:t.runtimeChunk,chunkIds:"named",moduleIds:"named",// parent chunk中解决了的chunk会被删除
1
+ import e from"css-minimizer-webpack-plugin";import i from"mini-css-extract-plugin";import n from"terser-webpack-plugin";import m from"webpack";import{BundleAnalyzerPlugin as o}from"webpack-bundle-analyzer";import{merge as s}from"webpack-merge";import{clientConfig as r}from"./common.js";import{CONFIG as t}from"./config.js";import{getMinifyOption as p}from"./minify.js";let{optimize:l}=m,{cssnanoMinify:u,swcMinify:a}=e,c="swc"===t.compiler,f=[];t.minifier&&(t.minifier.js&&f.push(new n(p(t.minifier.js?.type||(c?"swc":"terser"),t.minifier.js?.options))),t.minifier.css&&f.push(new e({minify:{swc:a,cssnano:u}[t.minifier.css?.type||(c?"swc":"cssnano")],minimizerOptions:t.minifier.css?.options})));let d={splitChunks:t.splitChunk,runtimeChunk:t.runtimeChunk,chunkIds:"named",moduleIds:"named",// parent chunk中解决了的chunk会被删除
2
2
  removeAvailableModules:!0,// 删除空的chunks
3
3
  removeEmptyChunks:!0,// 合并重复的chunk
4
- mergeDuplicateChunks:!0,minimize:!0,minimizer:f},k=r(s,{devtool:!1===t.devtool||t.devtool?t.devtool:"cheap-module-source-map",mode:"production",optimization:d,plugins:[// 压缩 css
4
+ mergeDuplicateChunks:!0,mangleWasmImports:!0,minimize:!0,minimizer:f},k=s(r,{devtool:!1===t.devtool||t.devtool?t.devtool:"cheap-module-source-map",mode:"production",optimization:d,plugins:[// 压缩 css
5
5
  new i({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.css",experimentalUseImportModule:!0}),t.bundleAnalyzer&&new o(t.bundleAnalyzer),t.splitChunk&&new l.MinChunkSizePlugin({minChunkSize:1e4})].filter(Boolean)});export default[k];
@@ -1 +1 @@
1
- import o from"webpack-virtual-modules";import{docs as t}from"./docs.js";import{locales as e,localesModuleName as s}from"./locales.js";import{isLibrary as p}from"./process-env.js";import{exampleModuleName as r,examples as i,route as a,routesModuleName as l}from"./routes.js";import{resolveNodeModulesPath as n}from"./utils.js";export default class{constructor(o){this.options=o,this.hasTapped=!1}apply(f){let c=new o({[n(l)]:"export default []",[n(r)]:"export default []",[n(s)]:"export const locales = [];"});function h(o,t){c.writeModule(n(o),t||"")}c.apply(f),a.on("change",h),e.on("change",h),p&&(i.on("change",h),t.on("change",h)),f.hooks.compilation.tap("VirtualModulePlugin",()=>{if(!this.hasTapped){for(let o in this.options)if(Object.prototype.hasOwnProperty.call(this.options,o)){let t=this.options[o];h(o,"string"==typeof t?t:`export default ${JSON.stringify(t)}`)}for(let o of i)h(...o);for(let o of t)h(...o);this.hasTapped=!0}})}}
1
+ import o from"webpack-virtual-modules";import{docs as t}from"./docs.js";import{locales as e,localesModuleName as s}from"./locales.js";import{isLibrary as i}from"./process-env.js";import{exampleModuleName as p,examples as r,route as a,routesModuleName as l}from"./routes.js";import{resolveNodeModulesPath as n}from"./utils.js";export default class{constructor(o){this.options=o,this.hasTapped=!1}apply(f){let h=new o({[n(l)]:a.getData(l),[n(p)]:"export default []",[n(s)]:e.getData(s)});function c(o,t){h.writeModule(n(o),t||"")}h.apply(f),a.on("change",c),e.on("change",c),i&&(r.on("change",c),t.on("change",c)),f.hooks.compilation.tap("VirtualModulePlugin",()=>{if(!this.hasTapped){for(let o in this.options)if(Object.prototype.hasOwnProperty.call(this.options,o)){let t=this.options[o];c(o,"string"==typeof t?t:`export default ${JSON.stringify(t)}`)}for(let o of r)c(...o);for(let o of t)c(...o);this.hasTapped=!0}})}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.1.4",
3
+ "version": "3.1.5-beta.1",
4
4
  "description": "core",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -12,9 +12,9 @@
12
12
  "author": "moneko",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@mdx-js/loader": "2.3.0",
15
+ "@mdx-js/loader": "3.0.0",
16
16
  "@soda/friendly-errors-webpack-plugin": "1.8.1",
17
- "@swc/core": "1.3.94",
17
+ "@swc/core": "1.3.95",
18
18
  "@swc/css": "0.0.28",
19
19
  "@swc/helpers": "0.5.3",
20
20
  "@teamsupercell/typings-for-css-modules-loader": "2.5.2",
@@ -37,7 +37,7 @@
37
37
  "ts-import-plugin": "3.0.0",
38
38
  "ts-loader": "9.5.0",
39
39
  "typescript": "5.2.2",
40
- "webpack": "5.77.0",
40
+ "webpack": "5.89.0",
41
41
  "webpack-bundle-analyzer": "4.9.1",
42
42
  "webpack-cli": "5.1.4",
43
43
  "webpack-dev-server": "4.15.1",
@@ -219,6 +219,7 @@ export declare type ConfigType<T extends 'tsc' | 'swc' = 'swc'> = {
219
219
  js?: string[];
220
220
  media?: string[];
221
221
  fonts?: string[];
222
+ wasm?: string[];
222
223
  };
223
224
  /** bundle分析
224
225
  * @default false
@@ -280,7 +281,37 @@ export declare type ConfigType<T extends 'tsc' | 'swc' = 'swc'> = {
280
281
  */
281
282
  normalizeCss?: boolean;
282
283
  externalsPresets?: ExternalsPresets;
284
+ /** 允许构建以http(s):协议开头的远程资源 */
285
+ buildHttp?: HttpUriOptions | (string | RegExp | ((uri: string) => boolean))[];
283
286
  };
287
+ /**
288
+ * 用于构建 http 资源的选项
289
+ */
290
+ declare interface HttpUriOptions {
291
+ /** 允许的 URI 列表 */
292
+ allowedUris: (string | RegExp | ((uri: string) => boolean))[];
293
+ /**
294
+ * 存储锁定文件条目的资源内容的位置。
295
+ * 也可以通过传递 false 来禁用存储。
296
+ */
297
+ cacheLocation?: string | false;
298
+ /**
299
+ * 冻结; 设置后, 任何会导致锁定文件或任何资源内容修改的行为都将导致错误。
300
+ */
301
+ frozen?: boolean;
302
+ /**
303
+ * 锁定文件的位置
304
+ */
305
+ lockfileLocation?: string;
306
+ /**
307
+ * 代理配置,可用于指定用于 HTTP 请求的代理服务器
308
+ */
309
+ proxy?: string;
310
+ /**
311
+ * 升级, 设置后,将获取现有锁定文件条目的资源,并在资源内容更改时升级条目。
312
+ */
313
+ upgrade?: boolean;
314
+ }
284
315
  export declare interface ModuleFederationOption {
285
316
  /** 模块名称,唯一性,不能重名 */
286
317
  name: string;