@moneko/core 3.13.1 → 3.15.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/config.mjs +1 -1
- package/lib/module.config.mjs +1 -1
- package/lib/plugin/copy.d.mts +26 -0
- package/lib/plugin/copy.mjs +1 -0
- package/lib/plugins.config.mjs +1 -1
- package/package.json +1 -2
- package/typings/global.d.ts +7 -18
package/lib/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileExists as e}from"@moneko/mdx";import{merge as o}from"webpack-merge";import t from"./options/jsx-dom-expressions.mjs";import s from"./options/split-chunk.mjs";import
|
|
1
|
+
import{fileExists as e}from"@moneko/mdx";import{merge as o}from"webpack-merge";import t from"./options/jsx-dom-expressions.mjs";import s from"./options/split-chunk.mjs";import i,{CUSTOMCONFIG as a}from"./paths.mjs";import{APPTYPE as r,FRAMEWORK as l,NODE_ENV as n,PACKAGENAME as m,isDev as p,isLibrary as c,isMobile as u,jsxImportSource as d,mainDirectory as h}from"./process-env.mjs";import{isFunction as f,resolveProgram as g}from"./utils/index.mjs";import x from"./utils/log.mjs";import P from"./utils/read-conf.mjs";import v from"./utils/setup-env.mjs";let C=["@moneko","neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],j={devtool:p?"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:v(n,r,l),basename:"/",publicPath:"/",rem:{designSize:u?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":g(h)},moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},cacheDirectory:i.webpackCachePath,devServer:{host:"localhost",port:3e3},htmlPluginOption:{},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:s,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:C,js:C,media:C,font:C,wasm:[]},mdx:{jsx:!1,development:p,jsxImportSource:d,providerImportSource:`@moneko/${l}/mdx`},jsxDomExpressions:t,bar:{name:"Client",color:"#6f42c1"},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${i.httpCachePath}/http.lock`,cacheLocation:`${i.httpCachePath}/data`,upgrade:!0},virtualModule:{},cssExtract:{}};c&&(j.alias=Object.assign(j.alias,{"@pkg":i.componentsPath,[m]:i.componentsPath}));let k=j,w={},b={};if(e(i.configPath)){let e=(await P(i.configPath,"index")).default;w=f(e)?e(process):e}if(a&&e(i.customConfigPath)){let e=(await P(i.customConfigPath,a)).default;b=f(e)?e(process):e}(!1===(k=o(k,w,b)).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||"/";global.NEKOCLICONFIG={CONFIG,CUSTOMCONFIG:a,log:x};
|
package/lib/module.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e;import{CONFIG as s}from"./config.mjs";import o from"./options/modify-vars.mjs";import t from"./options/swcrc.mjs";import r,{CUSTOMCONFIG as
|
|
1
|
+
let e;import{CONFIG as s}from"./config.mjs";import o from"./options/modify-vars.mjs";import t from"./options/swcrc.mjs";import r,{CUSTOMCONFIG as n}from"./paths.mjs";import{getLightningCssTargets as a}from"./polyfills/targets.mjs";import{FRAMEWORK as i,isDev as l,isLibrary as m}from"./process-env.mjs";import d from"./rule.mjs";import c from"./utils/has-pkg.mjs";import{node_modules as p,resolveProgram as u}from"./utils/index.mjs";import f from"./utils/svg-to-data-uri.mjs";import{comment as y,getCommentPath as g}from"./vm/docs.mjs";import j from"./vm/generate-doc.mjs";import v from"./options/css-extract.mjs";import{saveFile as x}from"@moneko/mdx";import h from"./utils/reactive-object.mjs";let _={loader:`${r.corePath}/loader/lightningcss.cjs`,options:{sourceMap:!!s.sourceMap,analyzeDependencies:!1,targets:a(),drafts:{nesting:!0,customMedia:!0},errorRecovery:!1,unusedSymbols:[],rem:!!s.rem}},w={loader:"less-loader",options:{sourceMap:!!s.sourceMap,lessOptions:{modifyVars:o,javascriptEnabled:!0}}},M=[...s.cssModules,`@moneko/${i}`,"neko-ui"].map(p),k=["components","example","mock","site","src","server"].map(u);function $(e){return[...k,...s.rulesInclude?.[e]?.map(p)||[]]}n&&k.push(u(n)),s.overrideResolve&&s.overrideResolve.override&&k.push(s.overrideResolve.override);let O=$("css"),b=$("js"),P=$("media"),R=$("wasm"),D=$("font");c("sass")&&(e={loader:"sass-loader",options:{implementation:await import("sass"),sassOptions:{}}});let L=m&&l&&{test:d.tsdoc,include:s.alias["@pkg"],exclude:[d.node_modules,d.__tests__],enforce:"pre",loader:`${r.corePath}/loader/ts-doc.cjs`,options:{comment:y,generateDoc:j,getCommentPath:g}},B=[{resourceQuery:/raw/i,type:"asset/source"},{resourceQuery:/url/i,type:"asset/resource",generator:{filename:e=>{let s=e.filename;return s&&s.endsWith("wasm?url")?"wasm/[name][ext]":"assets/[name][ext]"}}},{test:d.wasm,type:"webassembly/async",include:R},{test:d.txt,type:"asset/source"},{test:d.ico,type:"asset/inline",include:P},{test:d.svg,type:"asset/inline",generator:{dataUrl:e=>f(e.toString())},include:P},{test:d.image,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext]"},include:P},{test:d.video,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/video/[name][ext]"},include:P},{test:d.font,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/fonts/[name][ext]"},include:D}],S=s.prefixJsLoader.filter(Boolean)||[],I=new h({});s.cssModuleDefinition&&I.on("change",x);export default(o=>{let n={loader:"swc-loader",options:t(o)},a={loader:"css-loader",options:{modules:{auto:e=>{if(e){for(let s=0,o=M.length;s<o;s++)if(e.includes(M[s]))return d.css_module.test(e)}return d.node_modules_css_module.test(e)},localIdentName:"[path][name]_[local]",exportLocalsConvention:"dashesOnly",exportOnlyLocals:o,getJSON:e=>{s.cssModuleDefinition&&I.setData(`${e.resourcePath}.d.ts`,e.exports.map(({name:e,value:s})=>`export const ${e}: '${s}';`).join("\n")+"\n")}},importLoaders:2}};return{noParse:d.no_parse,rules:[L,{oneOf:[...B,{test:d.js,use:[...S,n],include:b},{test:d.css,use:[v,"css-loader",_],include:O},e&&{test:d.scss,use:[v,a,_,e],include:O},{test:d.less,use:[v,a,_,w],include:O},{test:d.markdown,use:[...S,{loader:`${r.corePath}/loader/mdx.cjs`,options:s.mdx}],exclude:[d.node_modules]}].filter(Boolean)},...s.moduleRules].filter(Boolean)}});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
/** 需要拷贝的文件列表
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* export default {
|
|
6
|
+
* copy: {
|
|
7
|
+
* // 将 public 下的 a.json 和 s.txt 添加到资源
|
|
8
|
+
* files: ['public/a.json', 'public/s.txt'],
|
|
9
|
+
* // 将 static 文件夹添加到资源
|
|
10
|
+
* dirs: ['static']
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface CopyPluginOption {
|
|
16
|
+
/** 需要拷贝的文件列表 */
|
|
17
|
+
files?: string[];
|
|
18
|
+
/** 需要拷贝的文件夹 */
|
|
19
|
+
dirs?: string[];
|
|
20
|
+
}
|
|
21
|
+
export declare class CopyPlugin {
|
|
22
|
+
private option;
|
|
23
|
+
constructor(option: CopyPluginOption);
|
|
24
|
+
private writeFile;
|
|
25
|
+
apply(compiler: Compiler): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{loadFile as t,scanFolder as i}from"@moneko/mdx";import{basename as o,resolve as p}from"path";import e from"../utils/log.mjs";export class CopyPlugin{constructor(t){this.option=t}async writeFile(i,l){let r=l.compiler.outputFileSystem;if(r){let s=o(i),a=await t(p(i));r.writeFile(p(l.outputOptions.path,s),a,t=>{t&&e(`Error copying file ${s} to output directory: ${t}`)})}}apply(t){t.hooks.emit.tapPromise({name:"CopyPlugin",stage:t.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT},async t=>{if(this.option&&t.compiler.outputFileSystem){let o=[...this.option.files||[],...this.option.dirs?.flatMap(t=>i(t))||[]];await Promise.all(o.map(i=>this.writeFile(i,t)))}})}}
|
package/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"
|
|
1
|
+
import e from"html-webpack-plugin";import t from"webpack";import{CONFIG as o}from"./config.mjs";import l from"./options/html-plugin-option.mjs";import{AddEntryAttributePlugin as i}from"./plugin/add-entry-attribute.mjs";import r from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as n}from"./plugin/virtual-module.mjs";import{isMicro as p}from"./process-env.mjs";import{CopyPlugin as m}from"./plugin/copy.mjs";let{DefinePlugin:s,SourceMapDevToolPlugin:a,IgnorePlugin:c}=t,u=o.basename.split("/").filter(Boolean).length,f=`${Array(u).fill("..").join("/")+(u?"/":"")}404.html`,{pathSegmentsToKeep:h=u,path:d=f}=o.fixBrowserRouter||{},g=[...r,new n(o.virtualModule),o.htmlPluginOption&&new e(l),o.fixBrowserRouter&&new e({filename:d,inject:!1,templateContent:()=>`<html lang="en"><head><title>${l.title}</title><script>const pathKeep = ${h||u};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 m(o.copy),p&&new i({test:/main\.bundle\.js$/}),new s({"process.env":JSON.stringify(o.env)}),new c({resourceRegExp:/\/__tests__\//}),o.sourceMap&&new a(o.sourceMap),...o.plugins].filter(e=>!!e);export default g;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"@moneko/transform-imports": "0.5.1",
|
|
16
16
|
"@swc/core": "1.5.0",
|
|
17
17
|
"@typescript/vfs": "1.5.0",
|
|
18
|
-
"add-asset-html-webpack-plugin": "6.0.0",
|
|
19
18
|
"browserslist": "4.23.0",
|
|
20
19
|
"chalk": "5.3.0",
|
|
21
20
|
"chokidar": "3.6.0",
|
package/typings/global.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import type {
|
|
|
10
10
|
import type { DonePluginOption } from '../lib/plugin/done';
|
|
11
11
|
import type { MdxOptions } from '@moneko/mdx';
|
|
12
12
|
import type { Config as SwcConfig, JsMinifyOptions as SwcMinifyOptions } from '@swc/core';
|
|
13
|
-
import type { Options as AssetHtmlOptions } from 'add-asset-html-webpack-plugin';
|
|
14
13
|
import type { Options as HtmlWebpackPluginOptions } from 'html-webpack-plugin';
|
|
15
14
|
import type { MinifyOptions as TerserMinifyOptions } from 'terser';
|
|
16
15
|
import type {
|
|
@@ -21,6 +20,7 @@ import type {
|
|
|
21
20
|
WebpackPluginInstance,
|
|
22
21
|
} from 'webpack';
|
|
23
22
|
import type { PluginOptions as MiniCssExtractPluginOptions } from 'mini-css-extract-plugin';
|
|
23
|
+
import type { CopyPluginOption } from '../lib/plugin/copy.mjs';
|
|
24
24
|
|
|
25
25
|
export type { TerserMinifyOptions, SwcMinifyOptions, MiniCssExtractPluginOptions };
|
|
26
26
|
export type MinifierType = 'swc' | 'terser';
|
|
@@ -73,7 +73,6 @@ export type HtmlWebpackOption = HtmlWebpackPluginOptions & {
|
|
|
73
73
|
[key: string]: string | null | boolean | number;
|
|
74
74
|
}[];
|
|
75
75
|
};
|
|
76
|
-
export type CssMinify = 'swc' | 'cssnano' | 'lightningcss';
|
|
77
76
|
export type DevtoolOption =
|
|
78
77
|
| 'eval'
|
|
79
78
|
| 'eval-cheap-source-map'
|
|
@@ -206,6 +205,10 @@ export declare type ConfigType = {
|
|
|
206
205
|
prefixJsLoader: RuleSetRule['use'][];
|
|
207
206
|
/** node_modules中, 需要开启 cssModules 的模块 */
|
|
208
207
|
cssModules: string[];
|
|
208
|
+
/** 为 cssModule 生成准确的声明文件
|
|
209
|
+
* @default true
|
|
210
|
+
*/
|
|
211
|
+
cssModuleDefinition: boolean;
|
|
209
212
|
/** 按需引入 */
|
|
210
213
|
importOnDemand?: SwcImportOnDemandTransform;
|
|
211
214
|
/** 开发服务器代理 */
|
|
@@ -220,22 +223,8 @@ export declare type ConfigType = {
|
|
|
220
223
|
};
|
|
221
224
|
/** HtmlWebpackPlugin Option */
|
|
222
225
|
htmlPluginOption: HtmlWebpackOption | false;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
* const conf = {
|
|
226
|
-
* assetHtml: [
|
|
227
|
-
* {
|
|
228
|
-
* glob: './public/*.entry.css',
|
|
229
|
-
* typeOfAsset: 'css',
|
|
230
|
-
* },
|
|
231
|
-
* {
|
|
232
|
-
* glob: './public/*.entry.js',
|
|
233
|
-
* typeOfAsset: 'js',
|
|
234
|
-
* },
|
|
235
|
-
* ]
|
|
236
|
-
* }
|
|
237
|
-
* */
|
|
238
|
-
assetHtml: AssetHtmlOptions[];
|
|
226
|
+
|
|
227
|
+
copy: CopyPluginOption;
|
|
239
228
|
/** 路由模式
|
|
240
229
|
* @description
|
|
241
230
|
* 当在不支持 browserRouter 的环境(GitHub pages)使用 browserRouter,
|