@moneko/core 4.8.6-beta.15 → 4.8.6-beta.17
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/bin/pure-lint.mjs +1 -1
- package/lib/build/common.mjs +1 -1
- package/lib/config.mjs +1 -1
- package/lib/create-development-configuration.mjs +1 -1
- package/lib/index.d.mts +1 -0
- package/lib/index.mjs +1 -1
- package/lib/plugin/copy.d.mts +27 -9
- package/lib/plugin/copy.mjs +1 -1
- package/lib/plugin/lightningcss-plugin.mjs +1 -1
- package/lib/plugins.config.mjs +1 -1
- package/lib/polyfills/public-path.d.mts +4 -0
- package/lib/polyfills/public-path.mjs +1 -1
- package/lib/vm/app.mjs +1 -1
- package/lib/vm/dts.mjs +1 -1
- package/lib/vm/virtual.mjs +1 -1
- package/package.json +1 -1
- package/typings/global.d.ts +8 -29
package/lib/bin/pure-lint.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawnSync as t}from"node:child_process";import{join as e}from"node:path";import{argv as i,cwd as o,exit as r,stdout as n}from"node:process";import{ESLint as l}from"@moneko/eslint";import{stylelint as a}from"@moneko/stylelint";import{
|
|
2
|
+
import{spawnSync as t}from"node:child_process";import{join as e}from"node:path";import{argv as i,cwd as o,exit as r,stdout as n}from"node:process";import{ESLint as l}from"@moneko/eslint";import{stylelint as a}from"@moneko/stylelint";import{fileExists as s,ink as m,loadFile as c,println as d}from"@moneko/utils";import f from"../commom/log.mjs";import u from"../commom/parse-args.mjs";import p from"../commom/timer.mjs";let y=u(i.slice(2)),w=y.fix,h=y.cache||!0,S=e(o(),"node_modules/.cache"),j={ci:["diff","--name-only","HEAD^","HEAD"],commit:["diff","--cached","--name-only","--diff-filter=ACM"]},$=/.*(?<!\.d)\.(j|t|mj|mt|cj|ct)sx?$/i,g=/.*(?<!\.d)\.vue$/i,v=/.*(?<!\.d)\.(c|sc|sa|le)ss$/i,E=/\.min\.(j|t|mj|mt|cj|ct)sx?$/i,L=t("git",j[y.mode||"ci"]||j.ci).stdout.toString().trim().split("\n");async function x(){let t=m("ESLint","cyan");d(`${t}: ${m("runing...","yellow")}`,!0);try{p.start("ESLint");let t=L.filter(t=>!(t.endsWith("iconfont.js")||E.test(t))&&!!s(t)&&($.test(t)||g.test(t)));if(0===t.length)return void p.end("ESLint");let e=new l({cache:h,cacheLocation:`${S}/.eslintcache`,fix:w}),i=await e.lintFiles(t),o=await e.loadFormatter("stylish"),a=await o.format(i,{cwd:process.cwd(),rulesMeta:{}});w&&await l.outputFixes(i),a&&n.write(a);let m=i.some(t=>t.errorCount>0);p.end("ESLint"),m&&r(1)}catch(t){f(t)}}let k=L.filter(t=>v.test(t)||g.test(t));async function A(){let t=m("Stylelint","cyan");if(d(`${t}: ${m("runing...","yellow")}`,!0),p.start("Stylelint"),0===k.length)return void p.end("Stylelint");let e=await Promise.allSettled(k.map(async t=>{let e=await c(t);if(e)return await a.lint({codeFilename:t,code:e,cache:h,cacheLocation:`${S}/.stylelintcache`,fix:w,formatter:"string"}).catch(f)})),i=!1;e.forEach(t=>{"fulfilled"===t.status?t.value&&(t.value.report&&n.write(t.value.report),t.value.errored&&(i=!!t.value.errored)):t.reason&&(n.write(t.reason),i=!1)}),p.end("Stylelint"),i&&r(1)}await Promise.allSettled([x(),A()]);
|
package/lib/build/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import{merge as i}from"webpack-merge";import{commonConfig as n}from"../common.mjs";import{CONFIG as r}from"../config.mjs";import{LightningCssMinifyPlugin as t}from"../plugin/lightningcss-plugin.mjs";import{SwcMinifyPlugin as
|
|
1
|
+
import e from"webpack";import{merge as i}from"webpack-merge";import{commonConfig as n}from"../common.mjs";import{CONFIG as r}from"../config.mjs";import{LightningCssMinifyPlugin as t}from"../plugin/lightningcss-plugin.mjs";import{SwcMinifyPlugin as l}from"../plugin/swc-minify-plugin.mjs";import{getLightningCssTargets as s}from"../polyfills/targets.mjs";import{isDev as o,isReact as m,refresh as p}from"../process-env.mjs";let a=[];if(r.minifier){let e=!!r.sourceMap||("string"==typeof r.devtool?r.devtool?.includes("source-map"):!!Array.isArray(r.devtool)&&r.devtool.some(e=>["all","css"].includes(e.type)));a.push(new l(r.minifier)),a.push(new t({targets:s(),sourceMap:e}))}let u={maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>!e.endsWith(".map")&&!e.endsWith("ce28377f3a428346.js"),...r.performance},c=i(n,{performance:r.performance&&u,optimization:{splitChunks:r.splitChunk,runtimeChunk:r.runtimeChunk,minimize:a.length>0,minimizer:a,chunkIds:"deterministic",moduleIds:"deterministic",concatenateModules:!0,emitOnErrors:!1,removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,sideEffects:!0,providedExports:!0,flagIncludedChunks:!0,innerGraph:!1,mangleExports:"deterministic",portableRecords:!0,realContentHash:!1}});if(o&&p&&(c.plugins.push(new e.HotModuleReplacementPlugin),m)){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;c.plugins.push(new e({overlay:!1}))}if(r.splitChunk&&c.plugins?.push(new e.optimize.MinChunkSizePlugin({minChunkSize:r.minChunkSize||1e3})),r.bundleAnalyzer){let e=(await import("webpack-bundle-analyzer")).BundleAnalyzerPlugin;c.plugins?.push(new e({analyzerMode:"static",reportFilename:"report.html",openAnalyzer:!1,defaultSizes:"gzip",logLevel:"silent",...r.bundleAnalyzer}))}export default c;
|
package/lib/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sep as e}from"node:path";import o from"node:process";import{merge as t}from"webpack-merge";import{CUSTOMCONFIG as n}from"./commom/custom-config.mjs";import s from"./commom/paths.mjs";import{join as
|
|
1
|
+
import{sep as e}from"node:path";import o from"node:process";import{merge as t}from"webpack-merge";import{CUSTOMCONFIG as n}from"./commom/custom-config.mjs";import s from"./commom/paths.mjs";import{join as i}from"./commom/posix.mjs";import a from"./commom/setup-env.mjs";import r from"./options/jsx-dom-expressions.mjs";import m from"./options/split-chunk.mjs";import{getConfigWithTypescript as l,isFunction as p,node_modules as c,resolveProgram as u}from"./utils/index.mjs";import{initDts as d}from"./vm/dts.mjs";import{APPTYPE as f,FRAMEWORK as h,frameworkVersion as g,isBuild as v,isCI as x,isDev as b,isLibrary as j,isMobile as C,isReact as P,jsxImportSource as k,mainDirectory as w,NODE_ENV as O,PACKAGENAME as y}from"./process-env.mjs";let S=[/(app|vm|docs|example):[a-zA-Z_0-9]/,"@moneko","neko-ui",".cache/http/data","@element-plus","ant-design-vue","element-plus","element-ui","ng-zorro-antd","@mui","@du","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design","monaco-editor"];export async function getConfig(e){let t=l(e).default;return(p(t)?await t(o):t)??{}}let I=await a(O,f,h,[],v,n),[z,F]=await Promise.all([getConfig(s.configPath),getConfig(s.customConfigPath)]),M={mode:O,strict:!1,devtool:!1,seo:!1,bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:(!!x||!b)&&{},sourceMap:{filename:"[file].map",publicPath:"",namespace:y,moduleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]",fallbackModuleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]"},env:I,basename:"/",publicPath:"auto",rem:{designSize:C?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":u(w)},P&&g<18?{"react/package.json":c("react/package.json"),"react/jsx-runtime":c("react/jsx-runtime.js"),"react/jsx-dev-runtime":c("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3,open:!0},htmlPluginOption:{title:y.toLocaleUpperCase(),favicon:"https://h5static.dewucdn.com/node-common/718d5e10-576d-8b14-b0b1-e4c58c3b3f40.webp"},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:m,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:S,js:S,media:S,font:S,wasm:[]},mdx:{jsx:!1,development:b,jsxImportSource:k,providerImportSource:`@moneko/${h}/mdx`},jsxDomExpressions:r,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69",quiet:x},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==h,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1},minChunkSize:1e3,compression:!1,manifest:{filename:"site.webmanifest"},corepack:!0,reactJsxRuntime:"automatic"};j&&(M.alias=Object.assign(M.alias,{"@pkg":s.componentsPath,[y]:s.componentsPath}));let A=M;if(A=t(A,z,F),"true"===o.env.CODESPACES&&A.devServer.https&&(A.devServer.https=!1),!1===A.devServer.https&&"darwin"===o.platform&&(A.devServer.open=!1),A.htmlPluginOption&&(A.htmlPluginOption.tags||(A.htmlPluginOption.tags=[]),A.fixBrowserRouter&&A.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))"}),A.manifest)){let o=A.manifest.publicPath??A.htmlPluginOption.publicPath??A.publicPath??"/";A.htmlPluginOption.tags.push({href:i("auto"===o?"/":o,A.manifest.filename).replaceAll(e,"/"),tag:"link",rel:"manifest"})}export const CONFIG=A;export const PUBLICPATH="auto"===CONFIG.publicPath?"":CONFIG.publicPath;d(CONFIG);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import{merge as i}from"webpack-merge";import{LightningCssMinifyPlugin as m}from"./plugin/lightningcss-plugin.mjs";import{SwcMinifyPlugin as
|
|
1
|
+
import e from"webpack";import{merge as i}from"webpack-merge";import{LightningCssMinifyPlugin as m}from"./plugin/lightningcss-plugin.mjs";import{SwcMinifyPlugin as o}from"./plugin/swc-minify-plugin.mjs";import{getLightningCssTargets as t}from"./polyfills/targets.mjs";import{commonConfig as r}from"./common.mjs";import{CONFIG as n}from"./config.mjs";import p from"./module.config.mjs";import{isReact as s,refresh as l}from"./process-env.mjs";export async function createDevelopmentConfiguration(u={}){let c=[];if(n.minifier){let e=!!n.sourceMap||("string"==typeof n.devtool?n.devtool?.includes("source-map"):!!Array.isArray(n.devtool)&&n.devtool.some(e=>["all","css"].includes(e.type)));c.push(new o({compress:{ecma:2015,toplevel:!1,module:!1,ie8:!1,keep_fnames:!1,top_retain:[],keep_infinity:!0},...n.minifier})),c.push(new m({targets:t(),sourceMap:e}))}let a=i(r,{module:p(!1),plugins:[new e.HotModuleReplacementPlugin],optimization:{runtimeChunk:n.runtimeChunk,minimize:c.length>0,minimizer:c,chunkIds:"deterministic",moduleIds:"deterministic"}});if(s&&l){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;a.plugins.push(new e({overlay:!1}))}return i(a,u)}
|
package/lib/index.d.mts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './mcp/module-federation/common.mjs';
|
|
|
20
20
|
export { type JsxDomExpressions, default as jsxDomExpressions } from './options/jsx-dom-expressions.mjs';
|
|
21
21
|
export { type OptimizationSplitChunksOptions, default as splitChunk } from './options/split-chunk.mjs';
|
|
22
22
|
export type { CompressionPluginOptions } from './plugin/compression.mjs';
|
|
23
|
+
export { collectCopyDestAssetNames } from './plugin/copy.mjs';
|
|
23
24
|
export { type HtmlMeta, HtmlPlugin, type HtmlPluginOption } from './plugin/html-plugin.mjs';
|
|
24
25
|
export * from './plugin/manifest/index.mjs';
|
|
25
26
|
export type { OverrideResolverOption } from './plugin/override-resolve.mjs';
|
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{bundleDts}from"./commom/bundle-dts.mjs";export{declToMd}from"./commom/decl-to-md.mjs";export*from"./commom/git.mjs";export{default as hasPkg}from"./commom/has-pkg.mjs";export{getIPv4,getPort}from"./commom/net.mjs";export{default as open}from"./commom/open.mjs";export{default as parseArgs}from"./commom/parse-args.mjs";export{CUSTOMCONFIG,default as paths,routeDir,yarnArgv}from"./commom/paths.mjs";export{default as printLog}from"./commom/print-log.mjs";export{default as require}from"./commom/require.mjs";export*as Rule from"./commom/rule.mjs";export{default as timer}from"./commom/timer.mjs";export{yApiMock,yApiSchemaMock}from"./dev/mock.mjs";export{convertUriToFileName}from"./dev/proxy.mjs";export*from"./mcp/module-federation/common.mjs";export{default as jsxDomExpressions}from"./options/jsx-dom-expressions.mjs";export{default as splitChunk}from"./options/split-chunk.mjs";export{HtmlPlugin}from"./plugin/html-plugin.mjs";export*from"./plugin/manifest/index.mjs";export{APPTYPE,coreName,FRAMEWORK,isCI,isDev,isLibrary,isMicro,mainDirectory,packageJson,PACKAGENAME}from"./process-env.mjs";export{digest,getConfigWithTypescript,md5,node_modules,resolveProgram,toCamelCase}from"./utils/index.mjs";export*from"@moneko/mdx";export*from"@moneko/utils";import o from"webpack";export{o as webpack};
|
|
1
|
+
export{bundleDts}from"./commom/bundle-dts.mjs";export{declToMd}from"./commom/decl-to-md.mjs";export*from"./commom/git.mjs";export{default as hasPkg}from"./commom/has-pkg.mjs";export{getIPv4,getPort}from"./commom/net.mjs";export{default as open}from"./commom/open.mjs";export{default as parseArgs}from"./commom/parse-args.mjs";export{CUSTOMCONFIG,default as paths,routeDir,yarnArgv}from"./commom/paths.mjs";export{default as printLog}from"./commom/print-log.mjs";export{default as require}from"./commom/require.mjs";export*as Rule from"./commom/rule.mjs";export{default as timer}from"./commom/timer.mjs";export{yApiMock,yApiSchemaMock}from"./dev/mock.mjs";export{convertUriToFileName}from"./dev/proxy.mjs";export*from"./mcp/module-federation/common.mjs";export{default as jsxDomExpressions}from"./options/jsx-dom-expressions.mjs";export{default as splitChunk}from"./options/split-chunk.mjs";export{collectCopyDestAssetNames}from"./plugin/copy.mjs";export{HtmlPlugin}from"./plugin/html-plugin.mjs";export*from"./plugin/manifest/index.mjs";export{APPTYPE,coreName,FRAMEWORK,isCI,isDev,isLibrary,isMicro,mainDirectory,packageJson,PACKAGENAME}from"./process-env.mjs";export{digest,getConfigWithTypescript,md5,node_modules,resolveProgram,toCamelCase}from"./utils/index.mjs";export*from"@moneko/mdx";export*from"@moneko/utils";import o from"webpack";export{o as webpack};
|
package/lib/plugin/copy.d.mts
CHANGED
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
import { type Compiler } from 'webpack';
|
|
2
|
+
export interface CopyPattern {
|
|
3
|
+
/** 来源地址 */ from: string;
|
|
4
|
+
/** 目标地址 */ to: string;
|
|
5
|
+
}
|
|
6
|
+
type DirSpec = {
|
|
7
|
+
kind: 'plain';
|
|
8
|
+
scanRoot: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'pattern';
|
|
11
|
+
scanRoot: string;
|
|
12
|
+
toPrefix: string;
|
|
13
|
+
};
|
|
2
14
|
/** 需要拷贝的文件列表
|
|
3
15
|
* @example
|
|
4
16
|
* ```ts
|
|
5
17
|
* export default {
|
|
6
18
|
* copy: {
|
|
7
|
-
* // 将 public 下的 a.json 和 s.txt
|
|
8
|
-
* files: ['public/a.json', 'public/s.txt'],
|
|
9
|
-
* // 将 static
|
|
10
|
-
* dirs: ['static']
|
|
19
|
+
* // 将 public 下的 a.json 和 s.txt 添加到资源, 并将 public3/a.json 添加到资源, 目标地址为 public4/a.json
|
|
20
|
+
* files: ['public/a.json', 'public/s.txt', { from: 'public3/a.json', to: 'public4/a.json' }],
|
|
21
|
+
* // 将 static 文件夹添加到资源, 并将 abv/static2 文件夹添加到到资源, 目标地址为 ccs/public2
|
|
22
|
+
* dirs: ['static', { from: 'abv/static2', to: 'ccs/public2' }]
|
|
11
23
|
* }
|
|
12
24
|
* }
|
|
13
25
|
* ```
|
|
14
26
|
*/ export interface CopyPluginOption {
|
|
15
|
-
/** 需要拷贝的文件列表 */ files?: string[];
|
|
16
|
-
/** 需要拷贝的文件夹 */ dirs?: string[];
|
|
27
|
+
/** 需要拷贝的文件列表 */ files?: (string | CopyPattern)[];
|
|
28
|
+
/** 需要拷贝的文件夹 */ dirs?: (string | CopyPattern)[];
|
|
17
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* 与 {@link CopyPlugin} 当前配置下会 emit 的资源名一致,供 `SourceMapDevToolPlugin` 的 `exclude` 等使用。
|
|
32
|
+
* 在构建配置阶段计算一次,避免在编译管线中反复改写资源。
|
|
33
|
+
*/ export declare function collectCopyDestAssetNames(opt: CopyPluginOption): Set<string>;
|
|
18
34
|
export declare class CopyPlugin {
|
|
19
|
-
private readonly
|
|
20
|
-
private readonly
|
|
21
|
-
private
|
|
35
|
+
private readonly fileEntries;
|
|
36
|
+
private readonly dirSpecs;
|
|
37
|
+
/** 上一轮已发出的资源路径(dest),用于删除检测 */ private cacheDests;
|
|
38
|
+
/** 当前配置下 dest → 源路径,用于在资源被移除时清理 mtime 缓存 */ private destToSrc;
|
|
22
39
|
private fileTimestamps;
|
|
23
40
|
constructor(option: CopyPluginOption);
|
|
24
41
|
private getFiles;
|
|
25
42
|
private hasFileChanged;
|
|
26
43
|
apply(compiler: Compiler): void;
|
|
27
44
|
}
|
|
45
|
+
export { };
|
package/lib/plugin/copy.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{statSync as e}from"node:fs";import{resolve as
|
|
1
|
+
import{statSync as e}from"node:fs";import{posix as t,relative as s,resolve as i}from"node:path";import{loadFileRaw as o,scanFolderSync as r}from"@moneko/utils";import a from"webpack";import l from"../commom/log.mjs";function n(e){return e.split(/[/\\]/).join("/")}function f(e){if("string"==typeof e){let t=i(e);return{src:t,dest:t}}return{src:i(e.from),dest:n(e.to)}}function m(e,o){let a=new Map;for(let t of e)a.set(t.dest,t);for(let e of o)r(e.scanRoot,["\\.*"]).forEach(o=>{if("plain"===e.kind)a.set(o,{src:o,dest:o});else{let r=i(o),l=n(s(e.scanRoot,r)),f=""===l?e.toPrefix:t.join(e.toPrefix,l);a.set(f,{src:r,dest:f})}});return a}export function collectCopyDestAssetNames(e){return new Set(m((e.files??[]).map(f),(e.dirs??[]).map(e=>"string"==typeof e?{kind:"plain",scanRoot:e}:{kind:"pattern",scanRoot:i(e.from),toPrefix:n(e.to)})).keys())}let c="CopyPlugin",p=a.sources.RawSource;export class CopyPlugin{constructor(e){this.cacheDests=[],this.destToSrc=new Map,this.fileTimestamps=new Map,this.fileEntries=(e.files??[]).map(f),this.dirSpecs=(e.dirs??[]).map(e=>"string"==typeof e?{kind:"plain",scanRoot:e}:{kind:"pattern",scanRoot:i(e.from),toPrefix:n(e.to)})}getFiles(){let e=m(this.fileEntries,this.dirSpecs),t=new Set(e.keys()),s={deleted:[],files:[...e.values()]};for(let e of new Set(this.cacheDests))t.has(e)||s.deleted.push(e);for(let e of s.deleted){let t=this.destToSrc.get(e);void 0!==t&&this.fileTimestamps.delete(t)}for(let t of(this.destToSrc.clear(),e.values()))this.destToSrc.set(t.dest,t.src);return this.cacheDests=[...t],s}hasFileChanged(t){try{let s=e(t).mtimeMs,i=this.fileTimestamps.get(t)||0;return this.fileTimestamps.set(t,s),s>i}catch(e){return l(e),!0}}apply(e){e.hooks.thisCompilation.tap({name:c,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},e=>{let t=e.getCache(c);e.hooks.processAssets.tapPromise(c,async()=>{let s=this.getFiles();await Promise.allSettled(s.files.map(async({src:s,dest:i})=>{let r=this.hasFileChanged(s),a=t.getItemCache(s,null),l=await a.getPromise();if(l&&!r)return void e.emitAsset(i,l.source);let n=await o(s);if(null!==n){let t=new p(Buffer.from(n));await a.storePromise({source:t,timestamp:this.fileTimestamps.get(s)}),e.emitAsset(i,t)}})),s.deleted.forEach(t=>{e.deleteAsset(t)})})})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as
|
|
1
|
+
import{Buffer as e}from"node:buffer";import{transform as s}from"lightningcss";import t from"webpack";let i=new TextEncoder,o=t.sources.RawSource,n=t.sources.SourceMapSource,a=t.ModuleFilenameHelpers.matchObject,r="lightning-css-minify",m=/\.(c|le|sc|sa)ss(?:\?.*)?$/i;export class LightningCssMinifyPlugin{constructor(e={}){let{implementation:t,...i}=e;if(t&&"function"!=typeof t.transform)throw TypeError(`[LightningCssMinifyPlugin]: implementation.transform must be an 'lightningcss' transform function. Received ${typeof t.transform}`);this.transform=t?.transform??s,this.options=i}apply(e){let s=JSON.stringify({name:r,version:"0.0.1",options:this.options});e.hooks.compilation.tap(r,e=>{e.hooks.chunkHash.tap(r,(e,t)=>t.update(s)),e.hooks.processAssets.tapPromise({name:r,stage:t.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,additionalAssets:!0},async()=>await this.transformAssets(e)),e.hooks.statsPrinter.tap(r,e=>{e.hooks.print.for("asset.info.minimized").tap(r,(e,{green:s,formatFlag:t})=>e?s(t("minimized")):void 0)})})}async transformAssets(s){let{include:t,exclude:c,test:f,sourceMap:p=this.options.sourceMap,...l}=this.options,h=s.getCache(r),u=s.getAssets().filter(e=>!e.info.minimized&&(f||m).test(e.name)&&a({include:t,exclude:c},e.name));await Promise.allSettled(u.map(async t=>{let a,r=h.getItemCache(JSON.stringify(t.name),h.getLazyHashedEtag(t.source)),m=await r.getPromise();if(m&&m.minimized)return void s.updateAsset(t.name,m.source,{...t.info,minimized:!0});let c=t.source.source(),f="string"==typeof c?i.encode(c):c,u=this.transform({filename:t.name,code:f,minify:!0,sourceMap:p,...l}),d=e.from(u.code),g={source:a=p?new n(d,t.name,u.map||"",c,u.map||"",!0):new o(d),minimized:!0};await r.storePromise(g),s.updateAsset(t.name,a,{...t.info,minimized:!0})}))}}
|
package/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import{CompressionPlugin as t}from"./plugin/compression.mjs";import{CopyPlugin as
|
|
1
|
+
import e from"webpack";import{CompressionPlugin as t}from"./plugin/compression.mjs";import{collectCopyDestAssetNames as o,CopyPlugin as i}from"./plugin/copy.mjs";import{CssModuleDtsPlugin as r}from"./plugin/css-module-dts.mjs";import{HtmlPlugin as n}from"./plugin/html-plugin.mjs";import{ManifestPlugin as p}from"./plugin/manifest/index.mjs";import s from"./plugin/module-federation.mjs";import{VirtualModulePlugin as m}from"./plugin/virtual-module.mjs";import{app_vm as l}from"./vm/app.mjs";import{docs_vm as a}from"./vm/docs.mjs";import{example_vm as c}from"./vm/example.mjs";import{mf_vm as u}from"./vm/mf.mjs";import{re_export_vm as f}from"./vm/re-export.mjs";import{scope_vm as h}from"./vm/scope.mjs";import{sw_vm as d}from"./vm/sw.mjs";import{virtual_vm as g}from"./vm/virtual.mjs";import{CONFIG as w}from"./config.mjs";import{app_schema as j,docs_schema as v,example_schema as y,isLibrary as x,module_federation_schema as b,packageJson as M,re_export_schema as P,scope_schema as A,service_worker_schema as O,virtual_schema as k}from"./process-env.mjs";let B="object"==typeof w.compression?w.compression:{},R=[...s,new m(u,b),new m(l,j),new m(d,O),new m(f,P),x&&new m(a,v),x&&new m(c,y),x&&new m(h,A),w.virtualModule&&new m(g,k),new i(w.copy),new e.EnvironmentPlugin(w.env),new e.DefinePlugin({"process.env":JSON.stringify(w.env)}),new e.IgnorePlugin({resourceRegExp:/\.d\.tsx?$/,contextRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),new r,...w.plugins].filter(Boolean);if(w.compression&&R.push(new t({algorithm:w.devServer.https?"brotli":"gzip",test:/\.(js|css|html|svg|ttf|woff|woff2|png|jpg|jpeg)$/,...B})),w.manifest&&R.push(new p(w.manifest)),w.htmlPluginOption){let e={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","mobile-web-app-capable":"yes",renderer:"webkit",description:M.description,keywords:Array.isArray(M.keywords)?M.keywords.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};w.seo&&(e.relCanonical={rel:"canonical",href:`https://${w.seo.domain}${w.basename}`}),w.htmlPluginOption.meta&&Object.assign(e,w.htmlPluginOption.meta),R.push(new n({...w.htmlPluginOption,meta:e}))}if(w.fixBrowserRouter){let e=w.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,o=w.fixBrowserRouter.pathSegmentsToKeep??e;R.push(new n({filename:w.fixBrowserRouter.path??t,inject:!1,templateContent:()=>`<html lang="en"><head><title>Redirect</title><script>const pathKeep = ${o};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}))}if(w.sourceMap){let t=w.copy?o(w.copy):new Set,i=[...Array.isArray(w.sourceMap.exclude)?w.sourceMap.exclude:[w.sourceMap.exclude],"iconfont.js",e=>t.has(e),e=>e.startsWith("assets/")||e.includes(".min.")].filter(Boolean),r={...w.sourceMap,exclude:i};R.push(new e.SourceMapDevToolPlugin(r))}export default R;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function set(
|
|
1
|
+
export function set(t){__webpack_public_path__=t}export function get(){return __webpack_public_path__}export function getPublicPath(){let t="string"==typeof __webpack_public_path__?__webpack_public_path__:"/";return t.startsWith("http://")||t.startsWith("https://")?t:"u">typeof self&&self.location?.origin?self.location.origin+(t.startsWith("/")?t:`/${t}`):t}
|
package/lib/vm/app.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e}from"node:path";import{getAppEntry as r,getAppFallback as o,getAppMergeRouter as m,getAppNormalizeCss as t,getAppPrefixRouter as s,getAppRem as
|
|
1
|
+
import{join as e}from"node:path";import{getAppEntry as r,getAppFallback as o,getAppMergeRouter as m,getAppNormalizeCss as t,getAppPrefixRouter as s,getAppRem as p,getAppSuspense as a}from"@moneko/mdx";import{loadFileSync as i}from"@moneko/utils";import n,{routeDir as l}from"../commom/paths.mjs";import c from"../commom/reactive-object.mjs";import{readJson as f}from"../commom/read-json.mjs";import{CONFIG as d}from"../config.mjs";import u from"../plugin/module-federation.mjs";import{app_schema as j,APPTYPE as x,FRAMEWORK as y,framework as h,frameworkVersionStr as b,SSR as g}from"../process-env.mjs";import k from"../utils/create-types.mjs";import{generateDeclaration as v}from"../utils/dts.mjs";import{convertToCamelCase as C,transformModule as D}from"../utils/index.mjs";import{getEnvDts as w,vm_dts as z}from"./dts.mjs";import{generateLocales as P}from"./locales.mjs";import M from"./render-app.mjs";import{getRouter as $}from"./routes.mjs";export const app_vm=new c({env:{type:".ts",source:()=>{let e=`${j}:env`,r=w(D(d.env));return z.setData(e,k(e,v(r,e))),r}},info:r=>{let o=e(n.programPath,"package.json"),m=f(o),t=D({...m,projectName:C(m.name),ssr:g,base:d.basename,type:x,routerMode:d.routerMode,prefixCls:d.prefixCls,theme:d.theme,frameworkVersion:b,framework:h}),s=`${j}:info`;return r?.addDependency(o),z.setData(s,k(s,v(t,s))),t},render:{type:".tsx",source:()=>"react"===y?M:""},entry:()=>r(e(d.alias["@"],"./index.ts"),!!u.length,!!d.rem,!!d.normalizeCss,x,y),fallback:()=>o(d.fallbackCompPath),"merge-router":()=>m(),"prefix-router":()=>s(),suspense:{type:".tsx",source:()=>a(x,y)},routes:e=>(e.addContextDependency(l),$()),locals:r=>{let o=e(d.alias["@"],"./locales");return r.addContextDependency(o),P()},normalize:{type:".css",source:()=>t()},rem:()=>p(d.rem?.designSize||1680),"public-path":()=>i(e(n.corePath,"./polyfills/public-path.mjs"))||""});
|
package/lib/vm/dts.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e}from"node:path";import{loadFileSync as t,updateFile as o,updateFileSync as r}from"@moneko/utils";import s from"../commom/paths.mjs";import n from"../commom/reactive-object.mjs";import{readJson as
|
|
1
|
+
import{join as e}from"node:path";import{loadFileSync as t,updateFile as o,updateFileSync as r}from"@moneko/utils";import s from"../commom/paths.mjs";import n from"../commom/reactive-object.mjs";import{readJson as a}from"../commom/read-json.mjs";import{app_schema as m,APPTYPE as p,CACHE_NAME as i,FRAMEWORK as d,framework as l,frameworkVersionStr as c,packageJson as v,service_worker_schema as f,SSR as u,virtual_schema as $}from"../process-env.mjs";import j from"../utils/create-types.mjs";import{generateDeclaration as h}from"../utils/dts.mjs";import{convertToCamelCase as y,transformModule as b}from"../utils/index.mjs";export const dts_path=e(s.nodeModules,"@types",i,"index.d.ts");export const vm_dts=new n({});export function getEnvDts(e){return`${e};declare global {import AppEnv from '${m}:env';type ImportMetaEnv = Readonly<typeof AppEnv>;interface ImportMeta {readonly env: ImportMetaEnv;}namespace NodeJS {interface ProcessEnv extends ImportMetaEnv {readonly [key: string]: string | number | boolean | undefined;}}}`}vm_dts.on("change",()=>{let e=Object.values(vm_dts.data).join("\n");o(dts_path,e)});export function initDts(o){let n=j(`${m}:env`,h(getEnvDts(b(o.env)),`${m}:env`));vm_dts.setData(`${m}:env`,n);let g=a(e(s.programPath,"package.json"));vm_dts.setData(`${m}:info`,j(`${m}:info`,h(b({...g,projectName:y(v.name),ssr:u,type:p,frameworkVersion:c,framework:l,base:o.basename,routerMode:o.routerMode,prefixCls:o.prefixCls,theme:o.theme}),`${m}:info`))),vm_dts.setData(`${m}:public-path`,j(`${m}:public-path`,t(e(s.corePath,"./polyfills/public-path.mjs"))||"")),vm_dts.setData(`${f}:precaching`,j(`${f}:precaching`,t(e(s.corePath,"./service-worker/precaching.d.ts"))||"")),o.virtualModule&&Object.keys(o.virtualModule).map(e=>{let t=b(o.virtualModule[e]),r=`${$}:${e}`;vm_dts.setData(r,j(r,h(t,r)))});let M=o.moduleFederation?.flatMap(e=>Array.isArray(e.remotes)?e.remotes.map(e=>e.name):[]).filter(Boolean);r(dts_path,Object.values(vm_dts.data).join("\n")),r(e(s.nodeModules,"@moneko/init.d.json"),JSON.stringify({extends:`@moneko/${d}/base`,compilerOptions:{types:[`@moneko/${d}/env.d.ts`,`@types/${i}/index.d.ts`,...M.map(e=>`@types/${i}/${e}.d.ts`)]}}))}
|
package/lib/vm/virtual.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"../commom/reactive-object.mjs";import{CONFIG as m}from"../config.mjs";import{virtual_schema as o}from"../process-env.mjs";import r from"../utils/create-types.mjs";import{generateDeclaration as e}from"../utils/dts.mjs";import{transformModule as s}from"../utils/index.mjs";import{vm_dts as i}from"./dts.mjs";export const virtual_vm=new t({});m.virtualModule&&Object.keys(m.virtualModule).map(t=>{let l=s(m.virtualModule[t]);virtual_vm.setData(t,l);let a=`${o}:${t}`;i.setData(a,r(a,e(l,a)))});
|
|
1
|
+
import t from"../commom/reactive-object.mjs";import{CONFIG as m}from"../config.mjs";import{virtual_schema as o}from"../process-env.mjs";import r from"../utils/create-types.mjs";import{generateDeclaration as e}from"../utils/dts.mjs";import{transformModule as s}from"../utils/index.mjs";import{vm_dts as i}from"./dts.mjs";export const virtual_vm=new t({});m.virtualModule&&Object.keys(m.virtualModule).map(t=>{let l=s(m.virtualModule[t]);virtual_vm.setData(t,{type:".tsx",source:()=>l});let a=`${o}:${t}`;i.setData(a,r(a,e(l,a)))});
|
package/package.json
CHANGED
package/typings/global.d.ts
CHANGED
|
@@ -41,32 +41,7 @@ export type { MiniCssExtractPluginOptions, SwcMinifyOptions, TerserMinifyOptions
|
|
|
41
41
|
export type MinifierType = 'swc' | 'terser';
|
|
42
42
|
export declare type AppType = 'mobile' | 'site' | 'backstage' | 'micro' | 'library';
|
|
43
43
|
export declare type Framework = 'react' | 'solid';
|
|
44
|
-
|
|
45
|
-
| 'eval'
|
|
46
|
-
| 'eval-cheap-source-map'
|
|
47
|
-
| 'eval-cheap-module-source-map'
|
|
48
|
-
| 'eval-source-map'
|
|
49
|
-
| 'cheap-source-map'
|
|
50
|
-
| 'cheap-module-source-map'
|
|
51
|
-
| 'source-map'
|
|
52
|
-
| 'inline-cheap-source-map'
|
|
53
|
-
| 'inline-cheap-module-source-map'
|
|
54
|
-
| 'inline-source-map'
|
|
55
|
-
| 'eval-nosources-cheap-source-map'
|
|
56
|
-
| 'eval-nosources-cheap-module-source-map'
|
|
57
|
-
| 'eval-nosources-source-map'
|
|
58
|
-
| 'inline-nosources-cheap-source-map'
|
|
59
|
-
| 'inline-nosources-cheap-module-source-map'
|
|
60
|
-
| 'inline-nosources-source-map'
|
|
61
|
-
| 'nosources-cheap-source-map'
|
|
62
|
-
| 'nosources-cheap-module-source-map'
|
|
63
|
-
| 'nosources-source-map'
|
|
64
|
-
| 'hidden-nosources-cheap-source-map'
|
|
65
|
-
| 'hidden-nosources-cheap-module-source-map'
|
|
66
|
-
| 'hidden-nosources-source-map'
|
|
67
|
-
| 'hidden-cheap-source-map'
|
|
68
|
-
| 'hidden-cheap-module-source-map'
|
|
69
|
-
| 'hidden-source-map';
|
|
44
|
+
|
|
70
45
|
export type RulesInclude = {
|
|
71
46
|
css?: RuleSetConditionAbsolute[];
|
|
72
47
|
js?: RuleSetConditionAbsolute[];
|
|
@@ -151,11 +126,15 @@ export declare type ConfigType = {
|
|
|
151
126
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
152
127
|
env: Record<string, any>;
|
|
153
128
|
/**
|
|
154
|
-
* @
|
|
129
|
+
* @description 建议
|
|
155
130
|
* 开发模式: 'cheap-module-source-map'
|
|
156
131
|
* 生产模式: 'eval-cheap-module-source-map'
|
|
157
132
|
*/
|
|
158
|
-
devtool?:
|
|
133
|
+
devtool?: Configuration['devtool'];
|
|
134
|
+
/**
|
|
135
|
+
* SourceMap 配置项
|
|
136
|
+
* @description 用于配置 SourceMapDevToolPlugin 的配置项, 当设置为 `false` 时, 不生成源码映射, 通常和 devtool 二选一
|
|
137
|
+
*/
|
|
159
138
|
sourceMap?: SourceMapDevToolPluginOptions | false;
|
|
160
139
|
/** 路径别名映射 */
|
|
161
140
|
alias: {
|
|
@@ -701,6 +680,6 @@ export declare interface SharedConfig {
|
|
|
701
680
|
version?: number | string;
|
|
702
681
|
}
|
|
703
682
|
|
|
704
|
-
export type SourceMapDevToolPluginOptions = ConstructorParameters<typeof SourceMapDevToolPlugin>[0]
|
|
683
|
+
export type SourceMapDevToolPluginOptions = NonNullable<ConstructorParameters<typeof SourceMapDevToolPlugin>[0]>;
|
|
705
684
|
|
|
706
685
|
export {};
|