@moneko/core 3.26.12-beta.3 → 3.26.12-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,10 @@
1
1
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
2
- import TerserPlugin from 'terser-webpack-plugin';
3
2
  import webpack, { type Configuration } from 'webpack';
4
3
  import { merge } from 'webpack-merge';
5
4
  import { commonConfig } from '../common.mjs';
6
5
  import { CONFIG } from '../config.mjs';
7
- import { getMinifyOption } from '../options/js-minify.mjs';
8
6
  import { LightningCssMinifyPlugin } from '../plugin/lightningcss-plugin.mjs';
7
+ import SwcMinifyPlugin from '../plugin/swc-minify-plugin.mjs';
9
8
  import { getLightningCssTargets } from '../polyfills/targets.mjs';
10
9
  declare const minimizer: readonly [];
11
10
  declare const defaultPerformance: Configuration['performance'];
@@ -1 +1 @@
1
- import e from"mini-css-extract-plugin";import i from"terser-webpack-plugin";import n from"webpack";import{merge as m}from"webpack-merge";import{commonConfig as r}from"../common.mjs";import{CONFIG as t}from"../config.mjs";import{getMinifyOption as s}from"../options/js-minify.mjs";import{LightningCssMinifyPlugin as l}from"../plugin/lightningcss-plugin.mjs";import{getLightningCssTargets as o}from"../polyfills/targets.mjs";let p=[];t.minifier&&(p.push(new i(s(t.minifier.type,t.minifier.options))),p.push(new l({targets:o()})));let a={maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>!e.endsWith(".map")&&!e.endsWith("ce28377f3a428346.js"),...t.performance},u=m(r,{performance:t.performance&&a,plugins:[new e({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.css",ignoreOrder:!0})],optimization:{splitChunks:t.splitChunk,runtimeChunk:t.runtimeChunk,chunkIds:"deterministic",moduleIds:"deterministic",concatenateModules:!0,emitOnErrors:!1,removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,minimize:!0,minimizer:p}});if(t.splitChunk&&u.plugins?.push(new n.optimize.MinChunkSizePlugin({minChunkSize:51200})),t.bundleAnalyzer){let e=(await import("webpack-bundle-analyzer")).BundleAnalyzerPlugin;u.plugins?.push(new e({analyzerMode:"static",reportFilename:"report.html",openAnalyzer:!1,defaultSizes:"gzip",logLevel:"silent",...t.bundleAnalyzer}))}export default u;
1
+ import e from"mini-css-extract-plugin";import i from"webpack";import{merge as n}from"webpack-merge";import{commonConfig as m}from"../common.mjs";import{CONFIG as r}from"../config.mjs";import{LightningCssMinifyPlugin as t}from"../plugin/lightningcss-plugin.mjs";import l from"../plugin/swc-minify-plugin.mjs";import{getLightningCssTargets as s}from"../polyfills/targets.mjs";let o=[];r.minifier&&(o.push(new l(r.minifier)),o.push(new t({targets:s()})));let p={maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>!e.endsWith(".map")&&!e.endsWith("ce28377f3a428346.js"),...r.performance},u=n(m,{performance:r.performance&&p,plugins:[new e({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.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}});if(r.splitChunk&&u.plugins?.push(new i.optimize.MinChunkSizePlugin({minChunkSize:51200})),r.bundleAnalyzer){let e=(await import("webpack-bundle-analyzer")).BundleAnalyzerPlugin;u.plugins?.push(new e({analyzerMode:"static",reportFilename:"report.html",openAnalyzer:!1,defaultSizes:"gzip",logLevel:"silent",...r.bundleAnalyzer}))}export default u;
package/lib/build.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { relative } from 'node:path';
2
2
  import { analyzeBundleSize, completedInfo, ink, println, progressBar } from '@moneko/utils';
3
- import webpack, { type Stats, type WebpackPluginInstance } from 'webpack';
3
+ import webpack, { type Compiler, type Configuration, type Stats } from 'webpack';
4
4
  import { merge } from 'webpack-merge';
5
5
  import buildCommon from './build/common.mjs';
6
6
  import paths from './commom/paths.mjs';
@@ -9,13 +9,7 @@ import { empty } from './utils/index.mjs';
9
9
  import seo from './utils/seo.mjs';
10
10
  import { CONFIG } from './config.mjs';
11
11
  import moduleConfig from './module.config.mjs';
12
- declare const bar: {
13
- name: string;
14
- color: string;
15
- };
16
- declare const bar_name: string;
17
- declare const ProgressPlugin: typeof webpack.ProgressPlugin;
18
- declare const clientOption: webpack.Configuration;
19
- declare const instance: webpack.Compiler;
12
+ declare const clientOption: Configuration;
13
+ declare const instance: Compiler;
20
14
  declare function printCompilationMessages(stats: Stats);
21
15
  declare async function build();
package/lib/build.mjs CHANGED
@@ -1 +1 @@
1
- import{relative as o}from"node:path";import{analyzeBundleSize as r,completedInfo as m,ink as i,println as t,progressBar as e}from"@moneko/utils";import n from"webpack";import{merge as s}from"webpack-merge";import a from"./build/common.mjs";import p from"./commom/paths.mjs";import l from"./plugin/done.mjs";import{empty as c}from"./utils/index.mjs";import u from"./utils/seo.mjs";import{CONFIG as f}from"./config.mjs";import d from"./module.config.mjs";let g=f.bar.name||"Build",h=n.ProgressPlugin,w=n(s(a,{module:d(!1),plugins:[f.done&&new l({done:f.done}),!!f.bar&&new h({handler(o,r,...m){e(o||0,1,g,m.length?`[${r}] ${m.join(" ")}`:""),1===o&&process.stdout.write("\r\x1b[2K")}})].filter(Boolean)}));async function j(){let e=await new Promise((o,r)=>{w.run((m,i)=>{m&&r(m),i?o(i):r(Error("编译过程中没有生成统计信息"))})});(e.hasErrors()||e.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation;r.forEach(o=>{t(i(o.message,"178"))}),m.forEach(o=>{t(i(o.message,"red"))})}(e),await new Promise(n=>{e.compilation.compiler.cache.shutdown(s=>{s&&t(i(s.toString(),"red")),r(e.compilation.outputOptions.path,["\\.js$"]),m(~~((e.endTime-e.startTime)/10)/100,o(p.programPath,e.compilation.outputOptions.path)),n()})}),f.seo&&u()}process.on("exit",c),await j();
1
+ import{relative as o}from"node:path";import{analyzeBundleSize as m,completedInfo as r,ink as i,println as t,progressBar as e}from"@moneko/utils";import n from"webpack";import{merge as s}from"webpack-merge";import p from"./build/common.mjs";import a from"./commom/paths.mjs";import l from"./plugin/done.mjs";import{empty as u}from"./utils/index.mjs";import c from"./utils/seo.mjs";import{CONFIG as f}from"./config.mjs";import d from"./module.config.mjs";let g=s(p,{module:d(!1),plugins:[]});if(f.done&&g.plugins.push(new l({done:f.done})),f.bar){let o=f.bar.name||"Build";g.plugins.push(new n.ProgressPlugin({handler(m,r,...i){e(m||0,1,o,i.length?`[${r}] ${i.join(" ")}`:""),1===m&&process.stdout.write("\r\x1b[2K")}}))}let h=n(g);async function w(){let e=await new Promise((o,m)=>{h.run((r,i)=>{r&&m(r),i?o(i):m(Error("编译过程中没有生成统计信息"))})});(e.hasErrors()||e.hasWarnings())&&function(o){let{warnings:m,errors:r}=o.compilation;m.forEach(o=>{t(i(o.message,"178"))}),r.forEach(o=>{t(i(o.message,"red"))})}(e),await new Promise(n=>{e.compilation.compiler.cache.shutdown(s=>{s&&t(i(s.toString(),"red")),m(e.compilation.outputOptions.path,["\\.js$"]),r(~~((e.endTime-e.startTime)/10)/100,o(a.programPath,e.compilation.outputOptions.path)),n()})}),f.seo&&c()}process.on("exit",u),await w();
package/lib/config.d.mts CHANGED
@@ -7,13 +7,14 @@ import jsxDomExpressions from './options/jsx-dom-expressions.mjs';
7
7
  import splitChunk from './options/split-chunk.mjs';
8
8
  import { isFunction, resolveProgram } from './utils/index.mjs';
9
9
  import type { ConfigType } from './index.mjs';
10
- import { APPTYPE, FRAMEWORK, isDev, isLibrary, isMobile, jsxImportSource, mainDirectory, NODE_ENV, PACKAGENAME } from './process-env.mjs';
10
+ import { APPTYPE, coreName, FRAMEWORK, isDev, isLibrary, isMobile, jsxImportSource, mainDirectory, NODE_ENV, PACKAGENAME } from './process-env.mjs';
11
11
  declare const includeModule: readonly [string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string];
12
12
  export declare function getConfig(path: string): Promise<ConfigType>;
13
13
  type EnvType = {
14
14
  NODE_ENV: string;
15
15
  APPTYPE: string;
16
16
  FRAMEWORK: string;
17
+ PROJECTNAME?: string;
17
18
  };
18
19
  declare const resp: [EnvType, ConfigType, ConfigType];
19
20
  declare const env: EnvType;
package/lib/config.mjs CHANGED
@@ -1 +1 @@
1
- import{fileExists as e}from"@moneko/utils";import{merge as o}from"webpack-merge";import t from"./commom/paths.mjs";import n from"./commom/require.mjs";import s from"./commom/setup-env.mjs";import i from"./options/jsx-dom-expressions.mjs";import r from"./options/split-chunk.mjs";import{isFunction as l,resolveProgram as a}from"./utils/index.mjs";import{APPTYPE as m,FRAMEWORK as p,isDev as c,isLibrary as u,isMobile as d,jsxImportSource as f,mainDirectory as h,NODE_ENV as g,PACKAGENAME as x}from"./process-env.mjs";let v=["@app","@moneko","neko-ui",".cache/http/data","@ant-design","@antv","@antv/x6","@antv/x6-react-components","@element-plus","ant-design-vue","antd","antd-mini","antd-mobile","antd-mobile-icons","element-plus","element-ui","ng-zorro-antd","@antv","@mui","@du","ahooks","rc-queue-anim","umi","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design"];export function getConfig(o){return delete n.cache[o],new Promise(t=>{if(e(o)){let e=n(o).default;return t(l(e)?e(process):e)}return t({})})}let P=await Promise.all([s(g,m,p,[]),getConfig(t.configPath),getConfig(t.customConfigPath)]),b=P[0],w=P[1],C=P[2],j={devtool:c?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:b,basename:"/",publicPath:"/",rem:{designSize:d?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":a(h)},moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:r,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:v,js:v,media:v,font:v,wasm:[]},mdx:{jsx:!1,development:c,jsxImportSource:f,providerImportSource:`@moneko/${p}/mdx`},jsxDomExpressions:i,bar:{name:"Client",color:"#6f42c1"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==p,bundleId:"com.moneko.bid",bundles:[]};u&&(j.alias=Object.assign(j.alias,{"@pkg":t.componentsPath,[x]:t.componentsPath}));let k=j;(!1===(k=o(k,w,C)).devtool||!1===k.sourceMap)&&(k.sourceMap=!1,k.devtool=!1),k.fixBrowserRouter&&k.htmlPluginOption&&(k.htmlPluginOption.tags||(k.htmlPluginOption.tags=[]),k.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=k;export const PUBLICPATH=CONFIG.publicPath;
1
+ import{fileExists as e}from"@moneko/utils";import{merge as o}from"webpack-merge";import t from"./commom/paths.mjs";import n from"./commom/require.mjs";import i from"./commom/setup-env.mjs";import s from"./options/jsx-dom-expressions.mjs";import r from"./options/split-chunk.mjs";import{isFunction as l,resolveProgram as a}from"./utils/index.mjs";import{APPTYPE as m,coreName as p,FRAMEWORK as c,isDev as u,isLibrary as d,isMobile as f,jsxImportSource as h,mainDirectory as g,NODE_ENV as v,PACKAGENAME as x}from"./process-env.mjs";let P=["@app","@moneko","neko-ui",".cache/http/data","@ant-design","@antv","@antv/x6","@antv/x6-react-components","@element-plus","ant-design-vue","antd","antd-mini","antd-mobile","antd-mobile-icons","element-plus","element-ui","ng-zorro-antd","@antv","@mui","@du","ahooks","rc-queue-anim","umi","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design"];export function getConfig(o){return delete n.cache[o],new Promise(t=>{if(e(o)){let e=n(o).default;return t(l(e)?e(process):e)}return t({})})}let b=await Promise.all([i(v,m,c,[]),getConfig(t.configPath),getConfig(t.customConfigPath)]),C=b[0],w=b[1],j=b[2],k={devtool:u?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:C,basename:"/",publicPath:"/",rem:{designSize:f?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":a(g)},moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{title:x.toLocaleUpperCase(),favicon:`node_modules/${p}/lib/options/favicon.ico`},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:r,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:P,js:P,media:P,font:P,wasm:[]},mdx:{jsx:!1,development:u,jsxImportSource:h,providerImportSource:`@moneko/${c}/mdx`},jsxDomExpressions:s,bar:{name:"Client",color:"#6f42c1"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==c,bundleId:"com.moneko.bid",bundles:[]};d&&(k.alias=Object.assign(k.alias,{"@pkg":t.componentsPath,[x]:t.componentsPath}));let O=k;(!1===(O=o(O,w,j)).devtool||!1===O.sourceMap)&&(O.sourceMap=!1,O.devtool=!1),O.fixBrowserRouter&&O.htmlPluginOption&&(O.htmlPluginOption.tags||(O.htmlPluginOption.tags=[]),O.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=O;export const PUBLICPATH=CONFIG.publicPath;
package/lib/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  export type * from '../typings/global.js';
2
2
  export { default as hasPkg } from './commom/has-pkg.mjs';
3
3
  export { getIPv4, getPort } from './commom/net.mjs';
4
- export { default as osTmpDir } from './commom/os-tmp-dir.mjs';
5
4
  export { CUSTOMCONFIG, default as paths, routeDir, yarnArgv } from './commom/paths.mjs';
6
5
  export { default as require } from './commom/require.mjs';
7
6
  export { default as Rule } from './commom/rule.mjs';
@@ -9,7 +8,7 @@ export { type MockConfiguration, type ProxyFuncType, type RequestFormData, yApiM
9
8
  export type { ProxyConfig } from './dev/proxy.mjs';
10
9
  export { type JsxDomExpressions, default as jsxDomExpressions } from './options/jsx-dom-expressions.mjs';
11
10
  export { type OptimizationSplitChunksOptions, default as splitChunk } from './options/split-chunk.mjs';
12
- export type { HtmlWebpackOption } from './plugin/html-webpack-plugin.mjs';
11
+ export type { HtmlMeta, HtmlPluginOption } from './plugin/html-plugin.mjs';
13
12
  export type { OverrideResolverOption } from './plugin/override-resolve.mjs';
14
13
  export type { VirtualModulePluginOption } from './plugin/virtual-module.mjs';
15
14
  export { APPTYPE, coreName, FRAMEWORK, isDev, isLibrary, isMicro, mainDirectory, PACKAGENAME, PACKAGEVERSION } from './process-env.mjs';
package/lib/index.mjs CHANGED
@@ -1 +1 @@
1
- export{default as hasPkg}from"./commom/has-pkg.mjs";export{getIPv4,getPort}from"./commom/net.mjs";export{default as osTmpDir}from"./commom/os-tmp-dir.mjs";export{CUSTOMCONFIG,default as paths,routeDir,yarnArgv}from"./commom/paths.mjs";export{default as require}from"./commom/require.mjs";export{default as Rule}from"./commom/rule.mjs";export{yApiMock,yApiSchemaMock}from"./dev/mock.mjs";export{default as jsxDomExpressions}from"./options/jsx-dom-expressions.mjs";export{default as splitChunk}from"./options/split-chunk.mjs";export{APPTYPE,coreName,FRAMEWORK,isDev,isLibrary,isMicro,mainDirectory,PACKAGENAME,PACKAGEVERSION}from"./process-env.mjs";export{resolveProgram,toCamelCase}from"./utils/index.mjs";
1
+ export{default as hasPkg}from"./commom/has-pkg.mjs";export{getIPv4,getPort}from"./commom/net.mjs";export{CUSTOMCONFIG,default as paths,routeDir,yarnArgv}from"./commom/paths.mjs";export{default as require}from"./commom/require.mjs";export{default as Rule}from"./commom/rule.mjs";export{yApiMock,yApiSchemaMock}from"./dev/mock.mjs";export{default as jsxDomExpressions}from"./options/jsx-dom-expressions.mjs";export{default as splitChunk}from"./options/split-chunk.mjs";export{APPTYPE,coreName,FRAMEWORK,isDev,isLibrary,isMicro,mainDirectory,PACKAGENAME,PACKAGEVERSION}from"./process-env.mjs";export{resolveProgram,toCamelCase}from"./utils/index.mjs";
@@ -1,5 +1,4 @@
1
1
  import { CONFIG } from '../config.mjs';
2
- import htmlPluginOption from './html-plugin-option.mjs';
3
2
  declare const prefixCls: string;
4
3
  declare const modifyVars: Record<string, string | false | undefined>;
5
4
  export default modifyVars;
@@ -1 +1 @@
1
- import{CONFIG as i}from"../config.mjs";import o from"./html-plugin-option.mjs";let f=i.prefixCls||"n",n={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":o.favicon};Object.assign(n,i.modifyVars);export default n;
1
+ import{CONFIG as i}from"../config.mjs";let f=i.prefixCls||"n",n={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":i.htmlPluginOption?.favicon};Object.assign(n,i.modifyVars);export default n;
@@ -1,17 +1,16 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { basename, resolve } from 'node:path';
3
3
  import webpack, { type Compilation, type Compiler } from 'webpack';
4
- declare const sources: typeof webpack.sources;
5
- interface HtmlMeta {
6
- [key: string]: string | Record<string, string>;
4
+ export interface HtmlMeta {
5
+ [key: string]: string | undefined | HtmlMeta;
7
6
  }
8
- export interface HtmlWebpackOption {
7
+ export interface HtmlPluginOption {
9
8
  favicon?: string | false;
10
9
  title?: string;
11
10
  template?: string;
12
11
  filename?: string | ((entryName: string) => string);
13
12
  inject?: boolean | 'head' | 'body';
14
- templateContent?: (options: HtmlWebpackOption) => string;
13
+ templateContent?: (options: HtmlPluginOption) => string;
15
14
  tags?: {
16
15
  textContent?: string;
17
16
  tag?: string;
@@ -20,9 +19,17 @@ export interface HtmlWebpackOption {
20
19
  }[];
21
20
  meta?: HtmlMeta;
22
21
  }
23
- export declare class SimpleHtmlWebpackPlugin {
24
- private options: HtmlWebpackOption;
25
- constructor(options: HtmlWebpackOption = {});
22
+ export declare class HtmlPlugin {
23
+ private options: HtmlPluginOption;
24
+ private AddEntry: RegExp;
25
+ private faviconPath: string;
26
+ private name: string;
27
+ private cachedMetaTags: string | null;
28
+ private cachedCustomTags: {
29
+ head: string;
30
+ body: string;
31
+ } | null;
32
+ constructor(options: HtmlPluginOption = {});
26
33
  apply(compiler: Compiler);
27
34
  private generateDefaultTemplate(): string;
28
35
  private generateMetaTags(): string;
@@ -0,0 +1 @@
1
+ import{existsSync as t,readFileSync as e}from"node:fs";import{basename as s,resolve as i}from"node:path";import n from"webpack";export class HtmlPlugin{constructor(t={}){this.AddEntry=/main\.bundle\.js$/,this.faviconPath="",this.name="HtmlPlugin",this.cachedMetaTags=null,this.cachedCustomTags=null,this.options={title:"WebApp",filename:"index.html",inject:"body",...t}}apply(o){o.hooks.compilation.tap(this.name,a=>{a.hooks.processAssets.tap({name:this.name,stage:n.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},()=>{let h;if(this.options.favicon){let h=i(o.context,this.options.favicon);if(t(h)){let t=s(this.options.favicon);a.emitAsset(t,new n.sources.RawSource(e(h))),this.faviconPath=(a.outputOptions.publicPath||"")+t}else a.warnings.push(new n.WebpackError(`Favicon file ${h} does not exist`))}if(h=this.options.templateContent?this.options.templateContent(this.options):this.options.template?e(i(o.context,this.options.template),{encoding:"utf-8"}):this.generateDefaultTemplate(),this.options.inject){let t=this.getAssets(a);h=this.injectAssets(h,t,this.options.inject)}let r="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";a.emitAsset(r,new n.sources.RawSource(h))})})}generateDefaultTemplate(){let t=this.generateMetaTags(),e=this.generateCustomTags();return`<!DOCTYPE html><html><head><meta charset="utf-8">${t}<title>${this.options.title}</title><link rel="icon" type="image/x-icon" href="${this.faviconPath}">${e.head}</head><body><div id="root"></div>${e.body}</body></html>`}generateMetaTags(){if(null!==this.cachedMetaTags)return this.cachedMetaTags;if(!this.options.meta)return this.cachedMetaTags="","";let t=Object.entries(this.options.meta).map(([t,e])=>{if("string"==typeof e)return`<meta name="${t}" content="${e}">`;if(void 0===e)return"";let s=Object.entries(e).map(([t,e])=>`${t}="${e}"`).join(" ");return`<meta ${s}>`}).join("");return this.cachedMetaTags=t,t}generateCustomTags(){if(null!==this.cachedCustomTags)return this.cachedCustomTags;let t={head:"",body:""};if(!this.options.tags)return this.cachedCustomTags=t,t;let e=[],s=[];return this.options.tags.forEach(t=>{let{tag:i="script",textContent:n="",inject:o=this.options.inject,...a}=t,h=Object.entries(a).filter(([,t])=>null!==t&&!1!==t).map(([t,e])=>!0===e?t:`${t}="${e}"`).join(" "),r=`<${i} ${h}>${n}</${i}>`;"head"===o?e.push(r):s.push(r)}),t.head=e.join(""),t.body=s.join(""),this.cachedCustomTags=t,t}getAssets(t){let e={js:[],css:[]},s=t.outputOptions.publicPath||"";for(let i of t.entrypoints.values())i.getFiles().forEach(t=>{t.endsWith(".js")?e.js.push(s+t):t.endsWith(".css")&&e.css.push(s+t)});return e}injectAssets(t,e,s){let i=e.css.length?e.css.map(t=>`<link href="${t}" rel="stylesheet">`).join(""):"",n=e.js.length?e.js.map(t=>`<script ${this.AddEntry.test(t)?'entry="true" ':""}src="${t}"></script>`).join(""):"",o=this.generateCustomTags(),a=t.split("</head>");if(2===a.length){let[t,e]=a,h=e.split("</body>");return"head"===s?`${t}${i}${n}${o.head}</head>${h[0]}${o.body}</body>${h[1]||""}`:`${t}${o.head}</head>${h[0]}${i}${n}${o.body}</body>${h[1]||""}`}return t}}
@@ -0,0 +1,9 @@
1
+ import { type JsMinifyOptions, minify } from '@swc/core';
2
+ import webpack, { type Compiler } from 'webpack';
3
+ declare class SwcMinifyPlugin {
4
+ private name: string;
5
+ private options: JsMinifyOptions;
6
+ constructor(options: JsMinifyOptions);
7
+ apply(compiler: Compiler);
8
+ }
9
+ export default SwcMinifyPlugin;
@@ -0,0 +1 @@
1
+ import{minify as e}from"@swc/core";import o from"webpack";export default class{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,...e}}apply(s){s.hooks.compilation.tap(this.name,s=>{s.hooks.processAssets.tapAsync({name:this.name,stage:o.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,additionalAssets:!0},async(t,a)=>{let n=Object.keys(t).filter(e=>e.endsWith(".js")&&!e.endsWith(".min.js"));try{await Promise.all(n.map(async t=>{let a=s.getAsset(t);if(a){let n=a.source.source().toString().replace(/\r\n/g,"\n"),{code:i}=await e(n,this.options);s.updateAsset(t,new o.sources.RawSource(i))}})),a()}catch(e){a(e)}})})}}
@@ -1,22 +1,9 @@
1
1
  import webpack, { type WebpackPluginInstance } from 'webpack';
2
- import htmlPluginOption from './options/html-plugin-option.mjs';
3
- import { AddEntryAttributePlugin } from './plugin/add-entry-attribute.mjs';
4
2
  import { CopyPlugin } from './plugin/copy.mjs';
5
- import { SimpleHtmlWebpackPlugin } from './plugin/html-webpack-plugin.mjs';
3
+ import { HtmlMeta, HtmlPlugin } from './plugin/html-plugin.mjs';
6
4
  import moduleFederation from './plugin/module-federation.mjs';
7
5
  import { VirtualModuleWebpackPlugin } from './plugin/virtual-module.mjs';
8
6
  import { CONFIG } from './config.mjs';
9
- import { isMicro } from './process-env.mjs';
10
- declare const DefinePlugin: typeof webpack.DefinePlugin;
11
- declare const SourceMapDevToolPlugin: typeof webpack.SourceMapDevToolPlugin;
12
- declare const IgnorePlugin: typeof webpack.IgnorePlugin;
13
- declare const dirDeep: number;
14
- declare const page404: string;
15
- declare const fixBrowserRouter: {
16
- pathSegmentsToKeep?: number;
17
- path?: string;
18
- };
19
- declare const pathSegmentsToKeep: number;
20
- declare const path: string;
7
+ import { description, keywords } from './process-env.mjs';
21
8
  declare const plugins: WebpackPluginInstance[];
22
9
  export default plugins;
@@ -1 +1 @@
1
- import e from"webpack";import t from"./options/html-plugin-option.mjs";import{AddEntryAttributePlugin as o}from"./plugin/add-entry-attribute.mjs";import{CopyPlugin as l}from"./plugin/copy.mjs";import{SimpleHtmlWebpackPlugin as i}from"./plugin/html-webpack-plugin.mjs";import n from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as p}from"./plugin/virtual-module.mjs";import{CONFIG as r}from"./config.mjs";import{isMicro as s}from"./process-env.mjs";let m=e.DefinePlugin,a=e.SourceMapDevToolPlugin,c=e.IgnorePlugin,u=r.basename.split("/").filter(Boolean).length,g=`${Array(u).fill("..").join("/")+(u?"/":"")}404.html`,h=r.fixBrowserRouter||{},f=h.pathSegmentsToKeep??u,d=h.path??g,w=[...n,new p(r.virtualModule),r.htmlPluginOption&&new i(t),r.fixBrowserRouter&&new i({filename:d,inject:!1,templateContent:()=>`<html lang="en"><head><title>${t.title}</title><script>const pathKeep = ${f};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>`}),new l(r.copy),s&&new o({test:/main\.bundle\.js$/}),new m({"process.env":JSON.stringify(r.env)}),new c({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),r.sourceMap&&new a(r.sourceMap),...r.plugins].filter(e=>!!e);export default w;
1
+ import e from"webpack";import{CopyPlugin as t}from"./plugin/copy.mjs";import{HtmlPlugin as i}from"./plugin/html-plugin.mjs";import o from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as l}from"./plugin/virtual-module.mjs";import{CONFIG as n}from"./config.mjs";import{description as r,keywords as p}from"./process-env.mjs";let a=[...o,new l(n.virtualModule),new t(n.copy),new e.DefinePlugin({"process.env":JSON.stringify(n.env)}),new e.IgnorePlugin({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),...n.plugins].filter(Boolean);if(n.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:r,keywords:Array.isArray(p)?p.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};n.seo&&(e.relCanonical={rel:"canonical",href:`https://${n.seo.domain}${n.basename}`}),n.htmlPluginOption.meta&&Object.assign(e,n.htmlPluginOption.meta),a.push(new i({...n.htmlPluginOption,meta:e}))}if(n.fixBrowserRouter){let e=n.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,o=n.fixBrowserRouter.pathSegmentsToKeep??e;a.push(new i({filename:n.fixBrowserRouter.path??t,inject:!1,templateContent:()=>`<html lang="en"><head><title>${n.htmlPluginOption?.title}</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>`}))}n.sourceMap&&a.push(new e.SourceMapDevToolPlugin(n.sourceMap));export default a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.26.12-beta.3",
3
+ "version": "3.26.12-beta.4",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -36,7 +36,6 @@
36
36
  "mini-css-extract-plugin": "2.9.2",
37
37
  "style-loader": "4.0.0",
38
38
  "swc-loader": "0.2.6",
39
- "terser-webpack-plugin": "5.3.11",
40
39
  "typescript": "5.5.4",
41
40
  "webpack": "5.97.1",
42
41
  "webpack-dev-middleware": "7.4.2",
@@ -14,7 +14,7 @@ import type {
14
14
  } from 'webpack';
15
15
 
16
16
  import type {
17
- HtmlWebpackOption,
17
+ HtmlPluginOption,
18
18
  JsxDomExpressions,
19
19
  OptimizationSplitChunksOptions,
20
20
  OverrideResolverOption,
@@ -108,15 +108,7 @@ export declare type ConfigType = {
108
108
  **/
109
109
  entry?: Record<string, string> | string;
110
110
  /** 压缩配置 */
111
- minifier:
112
- | {
113
- /**
114
- * @default 'swc'
115
- */
116
- type?: MinifierType;
117
- options?: SwcMinifyOptions | TerserMinifyOptions;
118
- }
119
- | false;
111
+ minifier: SwcMinifyOptions | false;
120
112
  /** 环境变量, 可通过 process.env 获取 */
121
113
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
114
  env: Record<string, any>;
@@ -253,8 +245,8 @@ export declare type ConfigType = {
253
245
  cert: string;
254
246
  };
255
247
  };
256
- /** HtmlWebpackPlugin Option */
257
- htmlPluginOption: HtmlWebpackOption | false;
248
+ /** HtmlPlugin Option */
249
+ htmlPluginOption: HtmlPluginOption | false;
258
250
  /** 需要拷贝的文件列表
259
251
  * @example
260
252
  * ```ts
@@ -1,2 +0,0 @@
1
- declare function osTmpDir(): string;
2
- export default osTmpDir;
@@ -1 +0,0 @@
1
- export default function(){let e;let s="win32"===process.platform;return e=s?process.env.TEMP||process.env.TMP||`${process.env.SystemRoot||process.env.windir}\\temp`:process.env.TMPDIR||process.env.TMP||process.env.TEMP||"/tmp",(s?/[^:]\\$/:/.\/$/).test(e)&&(e=e.slice(0,-1)),e}
@@ -1,11 +0,0 @@
1
- import { merge } from 'webpack-merge';
2
- import { CONFIG } from '../config.mjs';
3
- import type { HtmlWebpackOption } from '../plugin/html-webpack-plugin.mjs';
4
- import { coreName, description, keywords, PACKAGENAME } from '../process-env.mjs';
5
- import { resolveProgram } from '../utils/index.mjs';
6
- declare const option: HtmlWebpackOption;
7
- declare const favicon: string | false;
8
- declare const relCanonical: string | false;
9
- declare const meta: HtmlWebpackOption['meta'];
10
- declare const htmlPluginOption: HtmlWebpackOption;
11
- export default htmlPluginOption;
@@ -1 +0,0 @@
1
- import{merge as e}from"webpack-merge";import{CONFIG as t}from"../config.mjs";import{coreName as i,description as o,keywords as a,PACKAGENAME as r}from"../process-env.mjs";import{resolveProgram as n}from"../utils/index.mjs";let p=t.htmlPluginOption||{},l=p.favicon??`node_modules/${i}/lib/options/favicon.ico`,m=t.seo&&`https://${t.seo.domain}${t.basename}`,s={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:o,keywords:Array.isArray(a)?a.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};m&&Object.assign(s,{relCanonical:{rel:"canonical",href:m}});let c=e({title:t.env?.PROJECTNAME||r.toLocaleUpperCase()||"Title",filename:"index.html",meta:s,tags:[]},p,{favicon:l?n(l):l},p.template?{template:n(p.template)}:{});export default c;
@@ -1,26 +0,0 @@
1
- import TerserPlugin from 'terser-webpack-plugin';
2
- import { merge } from 'webpack-merge';
3
- import type { MinifierType, SwcMinifyOptions, TerserMinifyOptions } from '../index.mjs';
4
- type MinifyObject = {
5
- terser: {
6
- minify: typeof TerserPlugin.terserMinify;
7
- terserOptions: TerserMinifyOptions;
8
- extractComments?: boolean;
9
- };
10
- swc: {
11
- minify: typeof TerserPlugin.swcMinify;
12
- terserOptions?: SwcMinifyOptions;
13
- };
14
- };
15
- declare const commonCompress: {
16
- readonly drop_console: boolean;
17
- readonly drop_debugger: boolean;
18
- readonly global_defs: {
19
- readonly '@alert': string;
20
- };
21
- readonly pure_funcs: readonly [string, string, string, string];
22
- };
23
- declare const commonMinifyConf: TerserMinifyOptions & SwcMinifyOptions;
24
- export declare const minify: MinifyObject;
25
- export declare const getMinifyOption: (type: string, options: {
26
- }) => any;
@@ -1 +0,0 @@
1
- import e from"terser-webpack-plugin";import{merge as o}from"webpack-merge";let r={drop_console:!0,drop_debugger:!0,global_defs:{"@alert":"console.log"},pure_funcs:["console.log","console.warn","console.error","console.info"]},s={ecma:2015,toplevel:!1,module:!1,ie8:!1,keep_classnames:void 0,keep_fnames:!1};export const minify={terser:{minify:e.terserMinify,terserOptions:{compress:r,...s,mangle:!0,format:{comments:!1},safari10:!1,parse:{}},extractComments:!1},swc:{minify:e.swcMinify,terserOptions:{format:{comments:!1},compress:{...r,...s,top_retain:[],keep_infinity:!0},mangle:!0}}};export const getMinifyOption=(e="swc",r={})=>{let s=minify[e];return Object.assign(s,{terserOptions:o(s.terserOptions,r)})};
@@ -1,10 +0,0 @@
1
- import HtmlWebpackPlugin from 'html-webpack-plugin';
2
- import type { Compiler } from 'webpack';
3
- declare const name: string;
4
- export declare class AddEntryAttributePlugin {
5
- private readonly test;
6
- constructor(opt: {
7
- test: RegExp;
8
- });
9
- apply(compiler: Compiler);
10
- }
@@ -1 +0,0 @@
1
- import t from"html-webpack-plugin";let s="AddEntryAttributePlugin";export class AddEntryAttributePlugin{constructor(t){this.test=t.test}apply(e){e.hooks.compilation.tap(s,e=>{t.getHooks(e).alterAssetTagGroups.tapAsync(s,(t,s)=>{for(let s=0,e=t.headTags.length;s<e;s++){let e=t.headTags[s];"script"===e.tagName&&e.attributes.src&&this.test.test(e.attributes.src)&&(e.attributes.entry=!0)}s(null,t)})})}}
@@ -1,23 +0,0 @@
1
- import t from"fs";import e from"path";import s from"webpack";let i=s.sources;export class SimpleHtmlWebpackPlugin{constructor(t={}){this.options={title:"Web App",filename:"index.html",inject:"body",...t}}apply(s){s.hooks.emit.tapAsync("SimpleHtmlWebpackPlugin",(o,n)=>{let a;if(this.options.templateContent)a=this.options.templateContent(this.options);else if(this.options.template){let i=e.resolve(s.context,this.options.template);a=t.readFileSync(i,"utf-8")}else a=this.generateDefaultTemplate();if(this.options.inject){let t=this.getAssets(o);a=this.injectAssets(a,t,this.options.inject)}let l="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";o.emitAsset(l,new i.RawSource(a)),n()})}generateDefaultTemplate(){let t=this.generateMetaTags(),e=this.generateCustomTags(),s=this.options.favicon?`<link rel="icon" type="image/x-icon" href="${this.options.favicon}">`:"";return`
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
- <meta charset="utf-8">
6
- ${t}
7
- <title>${this.options.title}</title>
8
- ${s}
9
- ${e.head}
10
- </head>
11
- <body>
12
- <div id="root"></div>
13
- ${e.body}
14
- </body>
15
- </html>`}generateMetaTags(){return this.options.meta?Object.entries(this.options.meta).map(([t,e])=>{if("string"==typeof e)return`<meta name="${t}" content="${e}">`;let s=Object.entries(e).map(([t,e])=>`${t}="${e}"`).join(" ");return`<meta ${s}>`}).join("\n"):""}generateCustomTags(){let t={head:"",body:""};return this.options.tags&&this.options.tags.forEach(e=>{let{tag:s="script",textContent:i="",inject:o="body",...n}=e,a=Object.entries(n).filter(([,t])=>null!==t&&!1!==t).map(([t,e])=>!0===e?t:`${t}="${e}"`).join(" "),l=`<${s} ${a}>${i}</${s}>`;"head"===o?t.head+=(t.head?"\n":"")+l:t.body+=(t.body?"\n":"")+l}),t}getAssets(t){let e={js:[],css:[]},s=t.outputOptions.publicPath||"";for(let i of t.entrypoints.values())i.getFiles().forEach(t=>{t.endsWith(".js")?e.js.push(s+t):t.endsWith(".css")&&e.css.push(s+t)});return e}injectAssets(t,e,s){let i=t,o=e.css.map(t=>`<link href="${t}" rel="stylesheet">`).join("\n"),n=e.js.map(t=>`<script src="${t}"></script>`).join("\n"),a=this.generateCustomTags();return"head"===s?(i=i.replace("</head>",`${o}
16
- ${n}
17
- ${a.head}
18
- </head>`),a.body&&(i=i.replace("</body>",`${a.body}
19
- </body>`))):(i=i.replace("</body>",`${o}
20
- ${n}
21
- ${a.body}
22
- </body>`),a.head&&(i=i.replace("</head>",`${a.head}
23
- </head>`))),i}}