@moneko/core 3.46.3 → 3.47.0
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/build/common.d.mts +1 -1
- package/lib/build/common.mjs +1 -1
- package/lib/build.d.mts +1 -1
- package/lib/build.mjs +1 -1
- package/lib/common.d.mts +1 -1
- package/lib/common.mjs +1 -1
- package/lib/dev.d.mts +2 -2
- package/lib/dev.mjs +1 -1
- package/lib/plugin/compression.d.mts +1 -2
- package/lib/plugin/compression.mjs +1 -1
- package/lib/plugin/done.d.mts +2 -2
- package/lib/plugin/done.mjs +1 -1
- package/lib/plugin/eslint.d.mts +1 -2
- package/lib/plugin/eslint.mjs +1 -1
- package/lib/plugin/external-remotes.d.mts +1 -2
- package/lib/plugin/external-remotes.mjs +1 -1
- package/lib/plugin/manifest.d.mts +2 -2
- package/lib/plugin/manifest.mjs +1 -1
- package/lib/plugin/module-federation.d.mts +1 -1
- package/lib/plugin/module-federation.mjs +1 -1
- package/lib/plugin/override-resolve.d.mts +1 -2
- package/lib/plugin/override-resolve.mjs +1 -1
- package/lib/plugin/stylelint.d.mts +1 -2
- package/lib/plugin/stylelint.mjs +1 -1
- package/lib/plugin/swc-minify-plugin.d.mts +1 -2
- package/lib/plugin/swc-minify-plugin.mjs +1 -1
- package/lib/plugins.config.d.mts +2 -2
- package/lib/plugins.config.mjs +1 -1
- package/package.json +1 -1
package/lib/build/common.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { merge } from 'webpack-merge';
|
|
|
4
4
|
import { commonConfig } from '../common.mjs';
|
|
5
5
|
import { CONFIG } from '../config.mjs';
|
|
6
6
|
import { LightningCssMinifyPlugin } from '../plugin/lightningcss-plugin.mjs';
|
|
7
|
-
import SwcMinifyPlugin from '../plugin/swc-minify-plugin.mjs';
|
|
7
|
+
import { SwcMinifyPlugin } from '../plugin/swc-minify-plugin.mjs';
|
|
8
8
|
import { getLightningCssTargets } from '../polyfills/targets.mjs';
|
|
9
9
|
declare const minimizer: readonly [];
|
|
10
10
|
declare const defaultPerformance: Configuration['performance'];
|
package/lib/build/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"mini-css-extract-plugin";import i from"webpack";import{merge as n}from"webpack-merge";import{commonConfig as t}from"../common.mjs";import{CONFIG as r}from"../config.mjs";import{LightningCssMinifyPlugin as m}from"../plugin/lightningcss-plugin.mjs";import s
|
|
1
|
+
import e from"mini-css-extract-plugin";import i from"webpack";import{merge as n}from"webpack-merge";import{commonConfig as t}from"../common.mjs";import{CONFIG as r}from"../config.mjs";import{LightningCssMinifyPlugin as m}from"../plugin/lightningcss-plugin.mjs";import{SwcMinifyPlugin as s}from"../plugin/swc-minify-plugin.mjs";import{getLightningCssTargets as l}from"../polyfills/targets.mjs";let o=[];r.minifier&&(o.push(new s(r.minifier)),o.push(new m({targets:l()})));let p={maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>!e.endsWith(".map")&&!e.endsWith("ce28377f3a428346.js"),...r.performance},a=n(t,{performance:r.performance&&p,plugins:[new e({filename:"style/[contenthash].css",chunkFilename:"style/[contenthash].css",ignoreOrder:!0})],optimization:{splitChunks:r.splitChunk,runtimeChunk:r.runtimeChunk,chunkIds:"deterministic",moduleIds:"deterministic",concatenateModules:!0,emitOnErrors:!1,removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,minimize:!0,minimizer:o,sideEffects:!0,providedExports:!0,flagIncludedChunks:!0,innerGraph:!1,mangleExports:"deterministic",portableRecords:!0,realContentHash:!1}});if(r.splitChunk&&a.plugins?.push(new i.optimize.MinChunkSizePlugin({minChunkSize:r.minChunkSize||1e3})),r.bundleAnalyzer){let e=(await import("webpack-bundle-analyzer")).BundleAnalyzerPlugin;a.plugins?.push(new e({analyzerMode:"static",reportFilename:"report.html",openAnalyzer:!1,defaultSizes:"gzip",logLevel:"silent",...r.bundleAnalyzer}))}export default a;
|
package/lib/build.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import webpack, { type Compiler, type Configuration, type Stats } from 'webpack'
|
|
|
5
5
|
import { merge } from 'webpack-merge';
|
|
6
6
|
import buildCommon from './build/common.mjs';
|
|
7
7
|
import paths from './commom/paths.mjs';
|
|
8
|
-
import DonePlugin from './plugin/done.mjs';
|
|
8
|
+
import { DonePlugin } from './plugin/done.mjs';
|
|
9
9
|
import { empty } from './utils/index.mjs';
|
|
10
10
|
import seo from './utils/seo.mjs';
|
|
11
11
|
import { CONFIG } from './config.mjs';
|
package/lib/build.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{relative as o}from"node:path";import r from"node:process";import{analyzeBundleSize as m,completedInfo as t,ink as i,println as e,progressBar as n}from"@moneko/utils";import s from"webpack";import{merge as a}from"webpack-merge";import p from"./build/common.mjs";import l from"./commom/paths.mjs";import u
|
|
1
|
+
import{relative as o}from"node:path";import r from"node:process";import{analyzeBundleSize as m,completedInfo as t,ink as i,println as e,progressBar as n}from"@moneko/utils";import s from"webpack";import{merge as a}from"webpack-merge";import p from"./build/common.mjs";import l from"./commom/paths.mjs";import{DonePlugin as u}from"./plugin/done.mjs";import{empty as g}from"./utils/index.mjs";import c from"./utils/seo.mjs";import{CONFIG as f}from"./config.mjs";import d from"./module.config.mjs";let h=a(p,{module:d(!1),plugins:[]});if(f.done&&h.plugins.push(new u({done:f.done})),f.bar){let o=f.bar,m=o.name||"Build";h.plugins.push(new s.ProgressPlugin({handler(t,i,...e){let s=e.length?`[${i}] ${e.join(" ")}`:" ";o.quiet?r.stdout.write(`${s}
|
|
2
2
|
`):(n(t||0,1,{msg:s,name:m,barColor:o.barColor,nameColor:o.nameColor,barBgColor:o.barBgColor,msgColor:o.msgColor}),1===t&&r.stdout.write("\r\x1b[2K"))}}))}let w=s(h);async function b(){let r=await new Promise((o,r)=>{w.run((m,t)=>{m&&r(m),t?o(t):r(Error("编译过程中没有生成统计信息"))})});(r.hasErrors()||r.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation;r.forEach(o=>{e(i(o.message,"178"))}),m.forEach(o=>{e(i(o.message,"red"))})}(r),await new Promise(n=>{r.compilation.compiler.cache.shutdown(s=>{s&&e(i(s.toString(),"red")),m(r.compilation.outputOptions.path,["\\.js$"]),t(~~((r.endTime-r.startTime)/10)/100,o(l.programPath,r.compilation.outputOptions.path)),n()})}),f.seo&&c()}r.on("exit",g),await b();
|
package/lib/common.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { extname, join, resolve } from 'node:path';
|
|
|
2
2
|
import type { Configuration, FileCacheOptions } from 'webpack';
|
|
3
3
|
import paths, { config_files, CUSTOMCONFIG, TMP_DIR } from './commom/paths.mjs';
|
|
4
4
|
import require from './commom/require.mjs';
|
|
5
|
-
import
|
|
5
|
+
import { type OverrideResolverOption, OverrideResolverPlugin } from './plugin/override-resolve.mjs';
|
|
6
6
|
import { isObject, node_modules, resolveProgram } from './utils/index.mjs';
|
|
7
7
|
import { exampleModuleName } from './vm/example.mjs';
|
|
8
8
|
import app from './vm/info.mjs';
|
package/lib/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extname as e,join as t,resolve as o}from"node:path";import s,{config_files as a,CUSTOMCONFIG as n,TMP_DIR as i}from"./commom/paths.mjs";import r from"./commom/require.mjs";import l
|
|
1
|
+
import{extname as e,join as t,resolve as o}from"node:path";import s,{config_files as a,CUSTOMCONFIG as n,TMP_DIR as i}from"./commom/paths.mjs";import r from"./commom/require.mjs";import{OverrideResolverPlugin as l}from"./plugin/override-resolve.mjs";import{isObject as m,node_modules as c,resolveProgram as p}from"./utils/index.mjs";import{exampleModuleName as u}from"./vm/example.mjs";import d from"./vm/info.mjs";import{CONFIG as h,PUBLICPATH as f}from"./config.mjs";import g from"./plugins.config.mjs";import{isCI as b,isDev as y,isLibrary as j,NODE_ENV as v,packageJson as C}from"./process-env.mjs";export const outputConfig={path:p(j?"docs":"dist"),filename:"js/[name].[contenthash].bundle.js",chunkFilename:"js/[contenthash].chunk.js",assetModuleFilename:t=>{let o=e(t.filename||"").substring(1);return`assets/${o}/[hash][ext]`},library:{name:`${d.projectName}`,type:"umd",umdNamedDefine:!0},globalObject:"self",chunkLoadingGlobal:`webpackJsonp_${C.name}`,pathinfo:y,clean:!y,publicPath:f,asyncChunks:!0,charset:!0,iife:!0,crossOriginLoading:"use-credentials",enabledWasmLoadingTypes:["fetch"]};let P={main:[c("@app/entry")]};if(h.polyfill&&P.main.unshift(t(s.corePath,"./polyfills/replace-children.mjs")),y&&h.refresh&&h.env.injectRemoteReactRefresh&&P.main.unshift(r.resolve("@moneko/react/lib/injectRemoteReactRefresh.js")),h.entry&&("string"==typeof h.entry?P={main:[h.entry]}:Object.keys(h.entry)&&(P=Object.assign(P,h.entry))),"string"==typeof P.main&&(P.main=[P.main]),h.output){if("string"==typeof h.output)outputConfig.path=h.output;else if(Object.keys(h.output)){let e=h.output,t={...outputConfig.library};Object.assign(outputConfig,e),"object"==typeof h.output&&e.library&&(outputConfig.library=Object.assign(t,e.library))}}let x={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:s.webpackCachePath,memoryCacheUnaffected:!0,name:`.${[n,v].filter(Boolean).join("-")}`,version:`${C.version}`,buildDependencies:{config:a},maxMemoryGenerations:1};!1===h.cache?x=!1:m(h.cache)&&(x=Object.assign(x,h.cache)),b&&(void 0===h.cache||h.cache&&!h.cache.cacheDirectory)&&(x.cacheDirectory=o(i,C.name));export const commonConfig={name:"client",target:"web",devtool:h.devtool,entry:P,mode:y?"development":"production",stats:"errors-only",cache:x,snapshot:{immutablePaths:[s.pnpmNodeModules,s.denoNodeModules,/node_modules\/(?!(@app)\/)/],managedPaths:[s.pnpmNodeModules,s.denoNodeModules,/node_modules\/(?!(@app)\/)/],resolveBuildDependencies:{timestamp:!0,hash:!0},resolve:{timestamp:!0,hash:!0},module:{timestamp:!0,hash:!0},buildDependencies:{timestamp:!0,hash:!0}},infrastructureLogging:{level:"error"},externalsPresets:h.externalsPresets,plugins:g,node:{global:!1,__filename:!1,__dirname:!1},experiments:{topLevelAwait:!0,asyncWebAssembly:!0,cacheUnaffected:!0,layers:!0,lazyCompilation:h.lazyCompilation&&y&&{imports:!0,entries:!0,test:e=>{let t=e.nameForCondition();return!!(t&&(t.startsWith(c(u))||t.startsWith(c("@app/comment"))||t.startsWith(s.pagesPath)||t.startsWith(s.componentsPath)))}},buildHttp:m(h.buildHttp)?{allowedUris:[],lockfileLocation:o(s.httpCachePath,"http.lock"),cacheLocation:o(s.httpCachePath,"data"),upgrade:!0,...h.buildHttp}:h.buildHttp,backCompat:!0,futureDefaults:!0,css:!1,outputModule:!1},resolve:{extensions:[".mts",".mjs",".ts",".tsx",".js",".jsx",".json",".wasm"],alias:h.alias,modules:[s.nodeModules,s.pnpmNodeModules,s.denoNodeModules],mainFields:["browser","module","main"],mainFiles:["index"],plugins:h.resolvePlugins,preferAbsolute:!0,cache:!0,fallback:{}},externals:h.externals,output:outputConfig,recordsPath:h.recordsPath?t(s.programPath,h.recordsPath):t(s.webpackCachePath,"records.json")};h.overrideResolve&&commonConfig.resolve.plugins.push(new l(Object.assign({original:h.alias["@"],override:n&&p(n)},h.overrideResolve)));
|
package/lib/dev.d.mts
CHANGED
|
@@ -14,8 +14,8 @@ import { devLog, PORT } from './dev/config.mjs';
|
|
|
14
14
|
import generateProgressHtml, { type CompliationProcess } from './dev/generate-progress-html.mjs';
|
|
15
15
|
import server, { type FileSystem, type Server } from './dev/server.mjs';
|
|
16
16
|
import reslove from './options/reslove.mjs';
|
|
17
|
-
import ESLintPlugin from './plugin/eslint.mjs';
|
|
18
|
-
import StylelintPlugin from './plugin/stylelint.mjs';
|
|
17
|
+
import { ESLintPlugin } from './plugin/eslint.mjs';
|
|
18
|
+
import { StylelintPlugin } from './plugin/stylelint.mjs';
|
|
19
19
|
import { empty } from './utils/index.mjs';
|
|
20
20
|
import { commonConfig } from './common.mjs';
|
|
21
21
|
import { CONFIG, getConfig } from './config.mjs';
|
package/lib/dev.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import i from"node:process";import{URL as n}from"node:url";import{ink as s,print as m,println as a,progressBar as l}from"@moneko/utils";import p from"webpack";import c from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as f}from"./commom/diff-object.mjs";import u,{config_files as d}from"./commom/paths.mjs";import g from"./commom/sigint-exit.mjs";import{devLog as w,PORT as y}from"./dev/config.mjs";import $ from"./dev/generate-progress-html.mjs";import j from"./dev/server.mjs";import v from"./options/reslove.mjs";import b
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import i from"node:process";import{URL as n}from"node:url";import{ink as s,print as m,println as a,progressBar as l}from"@moneko/utils";import p from"webpack";import c from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as f}from"./commom/diff-object.mjs";import u,{config_files as d}from"./commom/paths.mjs";import g from"./commom/sigint-exit.mjs";import{devLog as w,PORT as y}from"./dev/config.mjs";import $ from"./dev/generate-progress-html.mjs";import j from"./dev/server.mjs";import v from"./options/reslove.mjs";import{ESLintPlugin as b}from"./plugin/eslint.mjs";import{StylelintPlugin as x}from"./plugin/stylelint.mjs";import{empty as C}from"./utils/index.mjs";import{commonConfig as P}from"./common.mjs";import{CONFIG as _,getConfig as S}from"./config.mjs";import{outputFileSystem as k}from"./file-system.mjs";import H from"./module.config.mjs";import{isLibrary as B,isReact as I,refresh as O}from"./process-env.mjs";let T=!1,q="/____progress____",G={percentage:0,info:""},L="/__hmr__",R=new URLSearchParams({name:"client",path:L.substring(1),dynamicPublicPath:!0,timeout:2e3,reload:!O,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),U=h(P,{watchOptions:{stdin:!0,aggregateTimeout:300,ignored:/node_modules\/(?!(@app)\/)/},entry:{main:[`${v.hotMiddlewareClient}?${R}`]},module:H(!1),plugins:[new p.HotModuleReplacementPlugin,new p.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app)\/)/,/\.d\.ts$/]}),new p.ProgressPlugin({handler(e,t,...o){let r=o.length?`[${t}] ${o.join(" ")}`:" ";T||(G.info=r,G.percentage=e,T=1===e);let n=_.bar;if(n){let t=n.name||"Build";n.quiet?i.stdout.write(`${r}
|
|
2
2
|
`):(l(e||0,1,{msg:r,name:t,barColor:n.barColor,nameColor:n.nameColor,barBgColor:n.barBgColor,msgColor:n.msgColor}),1===e&&i.stdout.write("\r\x1b[2K"))}}})]});if(I){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;U.plugins.push(new e({overlay:!1}))}function E(e){let t=e.join(","),o=[r(u.programPath,`${_.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return B&&o.push(r(u.programPath,`${_.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}_.eslint&&U.plugins.push(new b({fix:!0,cache:!0,cacheLocation:`${u.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:E(["js","jsx","ts","tsx","json","html","vue"]),..._.eslint})),_.stylelint&&U.plugins.push(new x({fix:!0,cache:!0,cacheLocation:`${u.lintCachePath}/.stylelintcache`,files:E(["css","scss","sass","less","ts","tsx","js","jsx"]),..._.stylelint}));let F=p(U);F.outputFileSystem=k;let M=F.watch(F.options.watchOptions,w);F.hooks.done.tap("client-log",e=>{w(null,e)});let N=`${_.publicPath}/${L}`.replace(/\/+/g,"/"),J=c(F,{log:!1,path:N,heartbeat:2e3}),K=await j({port:y,root_dir:F.options.output.path,fileSystem:F.outputFileSystem,headers:_.devServer.headers,https:_.devServer.https,host:_.devServer.host,open:_.devServer.open,basename:_.basename,onRequest(e,t){let o=new n(`${_.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if("GET"===e.method){if(o.pathname===q)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(G)),!0;if(!T)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end($(q,G)),!0;if(o.pathname===N&&"text/event-stream"===e.headers.accept)return J(e,t,C),!0}return!1}});function W(){i.exit(0)}K.on("close",()=>{M.close(C),J.close()});let z=await Promise.all(d.map(S)),A=h(z[0]||{},z[1]||{});d.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(d.map(S)),n=h(o||{},r||{}),l=f(A,n);1===Object.keys(l).length&&"proxy"in l?(m(s(`代理更新中...`,"yellow"),!0),m(s(`代理更新完成...`,"green"),!0),_.proxy=n.proxy,A.proxy=n.proxy,A=n):(A=n,a(s(`检测到工程配置${s(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e(D?`netstat -ano | findstr :${y}`:`lsof -i :${y} -t`,(e,t)=>{if(e){a(s(`查找端口 ${y} 时发生错误: ${e.message}`,"red")),a(s("请尝试手动重启程序","yellow"));return}let o=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),r=D?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){a(s(`未找到占用端口 ${y} 的进程, 请尝试手动重启程序`,"yellow"));return}try{i.kill(Number(r),"SIGHUP")}catch(e){a(s(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let D="win32"===i.platform;i.on("SIGHUP",function(){K.close(C),function(){let e=t(i.argv[0],i.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",W)}()}),i.on("exit",function(){K.close(C)}),g(W);
|
|
@@ -5,7 +5,7 @@ export interface CompressionPluginOptions {
|
|
|
5
5
|
test: RegExp;
|
|
6
6
|
algorithm: 'gzip' | 'brotli';
|
|
7
7
|
}
|
|
8
|
-
declare class CompressionPlugin {
|
|
8
|
+
export declare class CompressionPlugin {
|
|
9
9
|
private name: string;
|
|
10
10
|
private options: CompressionPluginOptions & {
|
|
11
11
|
filename: string;
|
|
@@ -15,4 +15,3 @@ declare class CompressionPlugin {
|
|
|
15
15
|
async compress(compiler: Compiler, compilation: Compilation, assets: Record<string, Source>);
|
|
16
16
|
apply(compiler: Compiler);
|
|
17
17
|
}
|
|
18
|
-
export default CompressionPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compression as e}from"@moneko/utils";export
|
|
1
|
+
import{compression as e}from"@moneko/utils";export class CompressionPlugin{constructor(e){this.name="compression-plugin";let{test:s,algorithm:t="brotli"}=e||{};this.options={test:s,algorithm:t,filename:`[path][base].${"brotli"===t?"br":"gz"}`}}runCompressionAlgorithm(s){return Buffer.from(e(Buffer.isBuffer(s)?Array.from(s):s,this.options.algorithm))}async compress(e,s,t){let o=s.getCache(this.name),{RawSource:i}=e.webpack.sources;await Promise.all(Object.keys(t).map(async t=>{let r;let a="gzip"===this.options.algorithm?"gzipped":`${this.options.algorithm}ed`,{info:m,source:p}=s.getAsset(t);if(m.compressed||!e.webpack.ModuleFilenameHelpers.matchObject.bind(void 0,this.options)(t)||m.related&&m.related[a])return!1;let n=o.getItemCache(JSON.stringify(`${t}${this.options.algorithm}`),o.getLazyHashedEtag(p)),l=await n.getPromise()||{};if(!l.source){if("function"==typeof p.buffer)r=p.buffer();else{let e=p.source();r=Buffer.isBuffer(e)?e:Buffer.from(e)}if(!l.compressed&&r)try{l.compressed=this.runCompressionAlgorithm(r)}catch(e){s.errors.push(e);return}l.compressed&&(l.source=new i(l.compressed)),await n.storePromise(l)}let f=s.getPath(this.options.filename,{filename:t}),c={compressed:!0};m.immutable&&/(\[name]|\[base]|\[file])/.test(this.options.filename)&&(c.immutable=!0),s.updateAsset(t,p,{related:{[a]:f}}),s.emitAsset(f,l.source,c)}))}apply(e){let s=this.name;e.hooks.thisCompilation.tap(s,t=>{t.hooks.processAssets.tapPromise({name:s,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,additionalAssets:!0},s=>this.compress(e,t,s))})}}
|
package/lib/plugin/done.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Compiler, Stats } from 'webpack';
|
|
2
2
|
export type DoneCallback = (stats: Stats) => void;
|
|
3
|
-
declare class DonePlugin {
|
|
3
|
+
export declare class DonePlugin {
|
|
4
|
+
private name: string;
|
|
4
5
|
private options;
|
|
5
6
|
constructor(options: {
|
|
6
7
|
done: DoneCallback;
|
|
@@ -8,4 +9,3 @@ declare class DonePlugin {
|
|
|
8
9
|
apply(compiler: Compiler);
|
|
9
10
|
}
|
|
10
11
|
export type DonePluginOption = ConstructorParameters<typeof DonePlugin>[0]['done'];
|
|
11
|
-
export default DonePlugin;
|
package/lib/plugin/done.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export class DonePlugin{constructor(o){this.name="DonePlugin",this.options=Object.assign({},o)}apply(o){o.hooks.done.tap(this.name,o=>{this.options.done(o)})}}
|
package/lib/plugin/eslint.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ export interface ESLintOption extends ESLint.Options {
|
|
|
10
10
|
files: string[];
|
|
11
11
|
lintDirtyModulesOnly?: boolean;
|
|
12
12
|
}
|
|
13
|
-
declare class ESLintPlugin {
|
|
13
|
+
export declare class ESLintPlugin {
|
|
14
14
|
private name: string;
|
|
15
15
|
private worker: Worker;
|
|
16
16
|
private options: ESLintOption;
|
|
@@ -20,4 +20,3 @@ declare class ESLintPlugin {
|
|
|
20
20
|
apply(compiler: Compiler): void;
|
|
21
21
|
private report(compilation: Compilation, lints?: ESLintWorkerMessage);
|
|
22
22
|
}
|
|
23
|
-
export default ESLintPlugin;
|
package/lib/plugin/eslint.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileURLToPath as t}from"node:url";import e from"webpack";import{Worker as s}from"worker_threads";class o extends e.WebpackError{constructor(t){super(`[ESLint] ${t}`),this.name="ESLintError",this.stack=""}}export
|
|
1
|
+
import{fileURLToPath as t}from"node:url";import e from"webpack";import{Worker as s}from"worker_threads";class o extends e.WebpackError{constructor(t){super(`[ESLint] ${t}`),this.name="ESLintError",this.stack=""}}export class ESLintPlugin{constructor(e={files:[]}){this.name="ESLintPlugin",this.options=e,this.worker=new s(t(new URL("../worker/eslint.mjs",import.meta.url)))}apply(t){t.hooks.thisCompilation.tap(this.name,e=>{let s=t.modifiedFiles||new Set;e.hooks.finishModules.tap(this.name,t=>{let o=this.options;if(this.options?.lintDirtyModulesOnly){let e=[];for(let o of t){let t=o.resource;s.has(t)&&e.push(t)}o.files=e}this.worker.postMessage({options:o}),this.worker.once("message",t=>{this.report(e,t)})})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,e){e?.length&&t&&(e[0]?.length&&t.warnings.push(new o(e[0])),e[1]?.length&&t.errors.push(new o(e[1])))}}
|
|
@@ -3,7 +3,6 @@ declare const sources: typeof webpack.sources;
|
|
|
3
3
|
declare const PLUGIN_NAME: string;
|
|
4
4
|
declare function toExpression(templateUrl: string);
|
|
5
5
|
declare function extractUrlAndGlobal(urlAndGlobal: string);
|
|
6
|
-
declare class ExternalRemotesPlugin {
|
|
6
|
+
export declare class ExternalRemotesPlugin {
|
|
7
7
|
apply(compiler: Compiler);
|
|
8
8
|
}
|
|
9
|
-
export default ExternalRemotesPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";let t=e.sources,r="ExternalRemotesPlugin";export
|
|
1
|
+
import e from"webpack";let t=e.sources,r="ExternalRemotesPlugin";export class ExternalRemotesPlugin{apply(e){e.hooks.make.tap(r,e=>{let n=[];e.hooks.buildModule.tap(r,e=>{"ExternalModule"===e.constructor.name&&"script"===e.externalType&&n.push(e)}),e.hooks.afterCodeGeneration.tap(r,function(){n.map(r=>{let n=function(e){let t=e.indexOf("@");if(t<=0||t===e.length-1)throw Error(`Invalid request "${e}"`);return[e.substring(t+1),e.substring(0,t)]}(r.request)[0],o=function(e){let t=[],r=[],n=!1,o=!1;for(let s of e)if("["===s){if(n){o=!0;break}n=!0,r.length&&(t.push(`"${r.join("")}"`),r.length=0)}else if("]"===s){if(!n){o=!0;break}n=!1,r.length&&(t.push(`${r.join("")}`),r.length=0),r.length=0}else r.push(s);if(n||o)throw Error(`Invalid template URL "${e}"`);return r.length&&t.push(`"${r.join("")}"`),t.join(" + ")}(n),s=e.codeGenerationResults.get(r,void 0).sources,l=s.get("javascript")?.source();l&&s.set("javascript",new t.RawSource(l.replace(`"${n}"`,o)))})})})}}
|
|
@@ -33,9 +33,9 @@ export interface ManifestPluginOption {
|
|
|
33
33
|
content_assets?: string[];
|
|
34
34
|
[key: string]: unknown;
|
|
35
35
|
}
|
|
36
|
-
declare class ManifestPlugin {
|
|
36
|
+
export declare class ManifestPlugin {
|
|
37
|
+
private name: string;
|
|
37
38
|
private options: ManifestPluginOption;
|
|
38
39
|
constructor(options?: ManifestPluginOption);
|
|
39
40
|
apply(compiler: Compiler);
|
|
40
41
|
}
|
|
41
|
-
export default ManifestPlugin;
|
package/lib/plugin/manifest.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{packageJson as s}from"../process-env.mjs";export
|
|
1
|
+
import{packageJson as s}from"../process-env.mjs";export class ManifestPlugin{constructor(e){this.name="ManifestPlugin",this.options=Object.assign({filename:"manifest.json",name:s.name,short_name:s.shortName,description:s.description,start_url:s.startUrl??"/?source=pwa",display:s.display??"standalone",background_color:s.backgroundColor??"#fff",theme_color:s.themeColor,icons:[{src:"/favicon.ico",sizes:"48x48",type:"image/x-icon"}]},e??{})}apply(e){let o=this.name,{filename:t,...a}=this.options;e.hooks.thisCompilation.tap({name:o,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT},o=>{o.emitAsset(t,new e.webpack.sources.RawSource(JSON.stringify({...a,version:`${s.version}-${o.hash}`,hash:o.fullHash,content_assets:Object.keys(o.assets)})),{javascriptModule:!1})})}}
|
|
@@ -4,7 +4,7 @@ import { CONFIG } from '../config.mjs';
|
|
|
4
4
|
import fetchModuleFederationDts from '../utils/fetch-module-federation-dts.mjs';
|
|
5
5
|
import { resolveProgram } from '../utils/index.mjs';
|
|
6
6
|
import { ModuleFederationExposesDeclarationPlugin } from './exposes-declararion.mjs';
|
|
7
|
-
import ExternalRemotesPlugin from './external-remotes.mjs';
|
|
7
|
+
import { ExternalRemotesPlugin } from './external-remotes.mjs';
|
|
8
8
|
type ModuleFederationPluginOption = ConstructorParameters<typeof ModuleFederationPlugin>[0];
|
|
9
9
|
type Remote = {
|
|
10
10
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import r from"../commom/require.mjs";import{CONFIG as t}from"../config.mjs";import o from"../utils/fetch-module-federation-dts.mjs";import{resolveProgram as s}from"../utils/index.mjs";import{ModuleFederationExposesDeclarationPlugin as m}from"./exposes-declararion.mjs";import a
|
|
1
|
+
import e from"webpack";import r from"../commom/require.mjs";import{CONFIG as t}from"../config.mjs";import o from"../utils/fetch-module-federation-dts.mjs";import{resolveProgram as s}from"../utils/index.mjs";import{ModuleFederationExposesDeclarationPlugin as m}from"./exposes-declararion.mjs";import{ExternalRemotesPlugin as a}from"./external-remotes.mjs";let i=e.NormalModuleReplacementPlugin,l=e.container.ModuleFederationPlugin,n={},p=[],f=t.moduleFederation?.map(e=>{let t={},a={},i={};if(Array.isArray(e.remotes))for(let r=0,t=e.remotes.length;r<t;r++){let t=e.remotes[r],s=t.alias||t.name,m=t.filename||"remote_entry.js";if(a[s]=`${t.name}@${t.host}/${m}`,Array.isArray(t.library))for(let e=0,r=t.library.length;e<r;e++)n[t.library[e]]=`${s}/${t.library[e]}`;o(t.host,t.name)}if(Array.isArray(e.exposes)){for(let o=0,m=e.exposes.length;o<m;o++){let m=e.exposes[o];if("string"==typeof m){let e=m.startsWith(".");t[`./${m}`]=r.resolve(e?s(m):m),e&&(i[m]=t[`./${m}`])}else if("[object Object]"===Object.prototype.toString.call(m)){let e=m.path.startsWith(".");t[`./${m.name}`]=r.resolve(e?s(m.path):m.path),e&&(i[`./${m.name}`]=t[`./${m.name}`])}}e.exposes?.length&&p.push(new m({exposes:i,name:e.name}))}return new l({filename:"remote_entry.js",...e,remotes:a,exposes:t})});f.length>0&&(f.push(new a),f.push(new i(/(.*)/,e=>{n[e.request]&&(e.request=n[e.request])})),p.forEach(e=>f.push(e))),t.env.injectRemoteReactRefresh=Object.keys(n).includes("react-dom");export default f;
|
|
@@ -7,9 +7,8 @@ export interface OverrideResolverOption {
|
|
|
7
7
|
override?: string;
|
|
8
8
|
}
|
|
9
9
|
declare const PLUGIN_NAME: string;
|
|
10
|
-
declare class OverrideResolverPlugin {
|
|
10
|
+
export declare class OverrideResolverPlugin {
|
|
11
11
|
private readonly options: Required<OverrideResolverOption>;
|
|
12
12
|
constructor(options: Required<OverrideResolverOption>);
|
|
13
13
|
apply(resolver: Resolver);
|
|
14
14
|
}
|
|
15
|
-
export default OverrideResolverPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{relative as e}from"node:path";import{fileExists as t}from"@moneko/utils";import r from"../commom/paths.mjs";let o="OverrideResolverPlugin";export
|
|
1
|
+
import{relative as e}from"node:path";import{fileExists as t}from"@moneko/utils";import r from"../commom/paths.mjs";let o="OverrideResolverPlugin";export class OverrideResolverPlugin{constructor(e){this.options=e}apply(i){let s=i.ensureHook("resolved"),{override:a,original:l}=this.options;if(a&&l){let n=`./${e(r.programPath,l)}`,p=`./${e(r.programPath,a)}`;i.getHook("existing-file").tapAsync(o,(e,r,h)=>{let m=e.request||e.path;if(m&&m.startsWith(l)&&e.relativePath){let u=m.replace(l,a);if(t(u)){let t=e.relativePath.replace(n,p);return Object.assign(e,{path:u,relativePath:t,__innerRequest_relativePath:t,__innerRequest:t}),i.doResolve(s,e,`${o} 使用目标模块${a}`,r,h)}}return h()})}}}
|
|
@@ -9,7 +9,7 @@ declare class StylelintError extends webpack.WebpackError {
|
|
|
9
9
|
export interface StylelintOption extends LinterOptions {
|
|
10
10
|
files: string[];
|
|
11
11
|
}
|
|
12
|
-
declare class StylelintPlugin {
|
|
12
|
+
export declare class StylelintPlugin {
|
|
13
13
|
private name: string;
|
|
14
14
|
private worker: Worker;
|
|
15
15
|
private options: StylelintOption;
|
|
@@ -19,4 +19,3 @@ declare class StylelintPlugin {
|
|
|
19
19
|
apply(compiler: Compiler): void;
|
|
20
20
|
private report(lints?: StylelintWorkerMessage, compilation?: Compilation);
|
|
21
21
|
}
|
|
22
|
-
export default StylelintPlugin;
|
package/lib/plugin/stylelint.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileURLToPath as t}from"node:url";import r from"webpack";import{Worker as e}from"worker_threads";class s extends r.WebpackError{constructor(t){super(`[Stylelint] ${t}`),this.name="StylelintError",this.stack=""}}export
|
|
1
|
+
import{fileURLToPath as t}from"node:url";import r from"webpack";import{Worker as e}from"worker_threads";class s extends r.WebpackError{constructor(t){super(`[Stylelint] ${t}`),this.name="StylelintError",this.stack=""}}export class StylelintPlugin{constructor(r={files:[]}){this.name="StylelintPlugin",this.options=r,this.worker=new e(t(new URL("../worker/stylelint.mjs",import.meta.url)))}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{this.worker.postMessage({options:this.options}),this.worker.once("message",r=>{this.report(r,t)})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,r){t?.length&&r&&(t[0]?.length&&r.warnings.push(new s(t[0])),t[1]?.length&&r.errors.push(new s(t[1])))}}
|
|
@@ -5,10 +5,9 @@ interface CacheItem {
|
|
|
5
5
|
source: sources.SourceMapSource;
|
|
6
6
|
minimized: boolean;
|
|
7
7
|
}
|
|
8
|
-
declare class SwcMinifyPlugin {
|
|
8
|
+
export declare class SwcMinifyPlugin {
|
|
9
9
|
private name: string;
|
|
10
10
|
private options: JsMinifyOptions;
|
|
11
11
|
constructor(options: JsMinifyOptions);
|
|
12
12
|
apply(compiler: Compiler);
|
|
13
13
|
}
|
|
14
|
-
export default SwcMinifyPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{minify as e}from"@swc/core";import s from"webpack";let o=s.sources.SourceMapSource;export
|
|
1
|
+
import{minify as e}from"@swc/core";import s from"webpack";let o=s.sources.SourceMapSource;export class SwcMinifyPlugin{constructor(e){this.name="SwcMinifyPlugin",this.options={format:{comments:!1},ecma:2015,compress:{drop_console:!0,drop_debugger:!0,global_defs:{"@alert":"console.log"},pure_funcs:["console.log","console.warn","console.error","console.info"],ecma:2015,toplevel:!1,module:!1,ie8:!1,keep_classnames:void 0,keep_fnames:!1,top_retain:[],keep_infinity:!0},mangle:!0,sourceMap:!0,...e}}apply(t){t.hooks.compilation.tap(this.name,t=>{t.hooks.processAssets.tapAsync({name:this.name,stage:s.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,additionalAssets:!0},async(s,i)=>{let a=t.getCache(this.name),n=Object.keys(s).filter(e=>e.endsWith(".js")&&!e.endsWith(".min.js"));try{await Promise.all(n.map(async s=>{let i=t.getAsset(s);if(!i||i.info.minimized)return;let n=a.getItemCache(JSON.stringify(i.name),a.getLazyHashedEtag(i.source)),r=await n.getPromise();if(r&&r.minimized){t.updateAsset(i.name,r.source,{...i.info,minimized:!0});return}let c=i.source.sourceAndMap();try{let s=await e(c.source.toString().replace(/\r\n/g,"\n"),this.options),a={sources:[i.name]};s.map&&((a=JSON.parse(s.map)).sources=[i.name],delete a.sourcesContent);let r={source:new o(s.code,i.name,a||"",c.source,c.map||"",!0),minimized:!0};await n.storePromise(r),t.updateAsset(i.name,r.source,{...i.info,minimized:!0})}catch(e){t.errors.push(e)}})),i()}catch(e){i(e)}})})}}
|
package/lib/plugins.config.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import webpack, { type WebpackPluginInstance } from 'webpack';
|
|
2
|
-
import CompressionPlugin,
|
|
2
|
+
import { CompressionPlugin, type CompressionPluginOptions } from './plugin/compression.mjs';
|
|
3
3
|
import { CopyPlugin } from './plugin/copy.mjs';
|
|
4
4
|
import { HtmlMeta, HtmlPlugin } from './plugin/html-plugin.mjs';
|
|
5
|
-
import ManifestPlugin from './plugin/manifest.mjs';
|
|
5
|
+
import { ManifestPlugin } from './plugin/manifest.mjs';
|
|
6
6
|
import moduleFederation from './plugin/module-federation.mjs';
|
|
7
7
|
import { VirtualModuleWebpackPlugin } from './plugin/virtual-module.mjs';
|
|
8
8
|
import { CONFIG } from './config.mjs';
|
package/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import t
|
|
1
|
+
import e from"webpack";import{CompressionPlugin as t}from"./plugin/compression.mjs";import{CopyPlugin as o}from"./plugin/copy.mjs";import{HtmlPlugin as i}from"./plugin/html-plugin.mjs";import{ManifestPlugin as r}from"./plugin/manifest.mjs";import p from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as n}from"./plugin/virtual-module.mjs";import{CONFIG as l}from"./config.mjs";import{packageJson as s}from"./process-env.mjs";let a="object"==typeof l.compression?l.compression:{},m=[...p,new n(l.virtualModule),new o(l.copy),new e.DefinePlugin({"process.env":JSON.stringify(l.env)}),new e.IgnorePlugin({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),...l.plugins].filter(Boolean);if(l.compression&&m.push(new t({algorithm:l.devServer.https?"brotli":"gzip",test:/\.(js|css|html|svg|ttf|woff|woff2|png|jpg|jpeg)$/,...a})),l.manifest&&m.push(new r(l.manifest)),l.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:s.description,keywords:Array.isArray(s.keywords)?s.keywords.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};l.seo&&(e.relCanonical={rel:"canonical",href:`https://${l.seo.domain}${l.basename}`}),l.htmlPluginOption.meta&&Object.assign(e,l.htmlPluginOption.meta),m.push(new i({...l.htmlPluginOption,meta:e}))}if(l.fixBrowserRouter){let e=l.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,o=l.fixBrowserRouter.pathSegmentsToKeep??e;m.push(new i({filename:l.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>`}))}l.sourceMap&&m.push(new e.SourceMapDevToolPlugin(l.sourceMap));export default m;
|