@moneko/core 3.2.1-beta.2 → 3.2.1-beta.3

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,4 +1,4 @@
1
- /**
1
+ export default /**
2
2
  * 向 html-webpack-plugin 导出的 HTML 模板 script 添加属性
3
3
  * ```javascript
4
4
  * // 假设输出 main chunk 为 main.[hash].chunk.js。
@@ -7,34 +7,12 @@
7
7
  * return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
8
8
  * })),
9
9
  * ```
10
- */ class AddEntryAttributeWebpackPlugin {
11
- entryMatchCallback;
12
- // eslint-disable-next-line no-unused-vars
13
- constructor(matchCallback){
14
- this.entryMatchCallback = matchCallback;
15
- }
16
- apply(compiler) {
17
- compiler.hooks.compilation.tap('AddEntryAttributeWebpackPlugin', (compilation)=>{
18
- // 通过最终的 webpack 配置的 plugins 属性,根据插件的 constructor.name 拿到 html-webpack-plugin 实例
19
- const HtmlWebpackPluginInstance = compiler.options.plugins.map(({ constructor })=>constructor).find((constructor)=>constructor && constructor.name === 'HtmlWebpackPlugin');
20
- // .find(
21
- // (plugin) => plugin instanceof HtmlWebpackPlugin,
22
- // ) as typeof HtmlWebpackPlugin;
23
- if (HtmlWebpackPluginInstance) {
24
- // 获取 html-webpack-plugin 所有的 hooks
25
- const hooks = HtmlWebpackPluginInstance.getHooks(compilation);
26
- // 在插入标签之前做些什么
27
- hooks.alterAssetTagGroups.tap('AddEntryAttributeWebpackPlugin', (data)=>{
28
- // 拿到所有的标签,如果是 script 标签,并且满足我们的匹配函数,则将其 attributes['entry'] 设为 true
29
- data.headTags.forEach((tag)=>{
30
- if (tag.tagName === 'script' && this.entryMatchCallback(tag.attributes.src)) {
31
- tag.attributes.entry = true;
32
- }
33
- });
34
- return data;
35
- });
36
- }
37
- });
38
- }
39
- }
40
- export default AddEntryAttributeWebpackPlugin;
10
+ */class{// eslint-disable-next-line no-unused-vars
11
+ constructor(t){this.entryMatchCallback=t}apply(t){t.hooks.compilation.tap("AddEntryAttributeWebpackPlugin",a=>{// 通过最终的 webpack 配置的 plugins 属性,根据插件的 constructor.name 拿到 html-webpack-plugin 实例
12
+ let e=t.options.plugins.map(({constructor:t})=>t).find(t=>t&&"HtmlWebpackPlugin"===t.name);// .find(
13
+ // (plugin) => plugin instanceof HtmlWebpackPlugin,
14
+ // ) as typeof HtmlWebpackPlugin;
15
+ if(e){// 获取 html-webpack-plugin 所有的 hooks
16
+ let t=e.getHooks(a);// 在插入标签之前做些什么
17
+ t.alterAssetTagGroups.tap("AddEntryAttributeWebpackPlugin",t=>(// 拿到所有的标签,如果是 script 标签,并且满足我们的匹配函数,则将其 attributes['entry'] 设为 true
18
+ t.headTags.forEach(t=>{"script"===t.tagName&&this.entryMatchCallback(t.attributes.src)&&(t.attributes.entry=!0)}),t))}})}}
@@ -1,45 +1 @@
1
- import { merge } from 'webpack-merge';
2
- import app from './app.js';
3
- import { CONFIG } from './config.js';
4
- import paths from './paths.js';
5
- import { PACKAGENAME, coreName } from './process-env.js';
6
- const { template, favicon, ...option } = Object.assign({
7
- template: `node_modules/${coreName}/template/index.html`,
8
- favicon: `node_modules/${coreName}/template/favicon.ico`
9
- }, CONFIG.htmlPluginOption || {});
10
- const htmlPluginOption = merge({
11
- title: CONFIG.env?.PROJECTNAME || PACKAGENAME.toLocaleUpperCase() || 'Title',
12
- filename: 'index.html',
13
- hash: false,
14
- minify: {
15
- collapseWhitespace: true,
16
- removeComments: true,
17
- removeRedundantAttributes: false,
18
- removeScriptTypeAttributes: false,
19
- removeStyleLinkTypeAttributes: false,
20
- removeAttributeQuotes: true,
21
- useShortDoctype: true
22
- },
23
- meta: {
24
- charset: 'UTF-8',
25
- 'X-UA-Compatible': {
26
- 'http-equiv': 'X-UA-Compatible',
27
- content: 'IE=edge,Chrome=1'
28
- },
29
- HandheldFriendly: 'true',
30
- MobileOptimized: '320',
31
- 'screen-orientation': 'portrait',
32
- 'x5-orientation': 'portrait',
33
- browsermode: 'application',
34
- 'x5-page-mode': 'app',
35
- 'msapplication-tap-highlight': 'no',
36
- viewport: 'width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no',
37
- 'apple-mobile-web-app-capable': 'yes',
38
- renderer: 'webkit',
39
- description: app.description || ''
40
- },
41
- tags: [],
42
- template: `${paths.programPath}/${template}`,
43
- favicon: `${paths.programPath}/${favicon}`
44
- }, option);
45
- export default htmlPluginOption;
1
+ import{merge as e}from"webpack-merge";import t from"./app.js";import{CONFIG as i}from"./config.js";import o from"./paths.js";import{PACKAGENAME as a,coreName as r}from"./process-env.js";let{template:p,favicon:m,...n}=Object.assign({template:`node_modules/${r}/template/index.html`,favicon:`node_modules/${r}/template/favicon.ico`},i.htmlPluginOption||{}),l=e({title:i.env?.PROJECTNAME||a.toLocaleUpperCase()||"Title",filename:"index.html",hash:!1,minify:{collapseWhitespace:!0,removeComments:!0,removeRedundantAttributes:!1,removeScriptTypeAttributes:!1,removeStyleLinkTypeAttributes:!1,removeAttributeQuotes:!0,useShortDoctype:!0},meta:{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",viewport:"width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no","apple-mobile-web-app-capable":"yes",renderer:"webkit",description:t.description||""},tags:[],template:`${o.programPath}/${p}`,favicon:`${o.programPath}/${m}`},n);export default l;
package/lib/index.js CHANGED
@@ -1,4 +1 @@
1
- export { default as paths } from './paths.js';
2
- export { CUSTOMCONFIG, FRAMEWORKNAME, PACKAGENAME, PACKAGEVERSION, coreName, isDev, isLibrary, isMicro } from './process-env.js';
3
- export { realResolve, resolveNodeModulesPath, resolveProgramPath } from './utils.js';
4
- export { getNetworkAdress, getIPv4, getPort } from './net.js';
1
+ export{default as paths}from"./paths.js";export{CUSTOMCONFIG,FRAMEWORKNAME,PACKAGENAME,PACKAGEVERSION,coreName,isDev,isLibrary,isMicro}from"./process-env.js";export{realResolve,resolveNodeModulesPath,resolveProgramPath}from"./utils.js";export{getNetworkAdress,getIPv4,getPort}from"./net.js";
package/lib/locales.js CHANGED
@@ -1,93 +1,3 @@
1
- import { stat } from 'fs';
2
- import { basename, join } from 'path';
3
- import { watch } from 'chokidar';
4
- import { CONFIG } from './config.js';
5
- import esm from './esm.js';
6
- import { FRAMEWORK, isLibrary } from './process-env.js';
7
- import ReactiveObject from './reactive-object.js';
8
- import { empty, resolveProgramPath, tfc } from './utils.js';
9
- const prefixStr = {
10
- react: 'import sso from "shared-store-object";',
11
- solid: 'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'
12
- };
13
- const suffixStr = {
14
- react: 'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',
15
- solid: 'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'
16
- }[FRAMEWORK];
17
- function getStr(lang, data) {
18
- return `${prefixStr[FRAMEWORK]}
19
- export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(lang)};const _res = ${JSON.stringify(data)};const resources = deepFreeze(_res);${suffixStr}`;
20
- }
21
- export const localesModuleName = '@app/locales';
22
- export const locales = new ReactiveObject({
23
- [localesModuleName]: getStr([], {})
24
- });
25
- const caches = {};
26
- // 要执行的函数
27
- async function handleFileChange(filePath, type) {
28
- const filename = basename(filePath).replace(/\.[^.]+$/, '');
29
- if (type === 'deleted') {
30
- delete caches[filename];
31
- } else {
32
- const option = await import(esm`${tfc(filePath)}`);
33
- Object.assign(caches, {
34
- [filename]: option.default
35
- });
36
- }
37
- const langs = [];
38
- const resources = {};
39
- for(const key in caches){
40
- if (Object.prototype.hasOwnProperty.call(caches, key)) {
41
- const item = caches[key];
42
- const { language = filename, title = language, icon, translation = {} } = item;
43
- langs.push({
44
- language,
45
- title,
46
- icon
47
- });
48
- resources[language] = {
49
- language,
50
- title,
51
- icon,
52
- translation
53
- };
54
- }
55
- }
56
- locales.setData(localesModuleName, getStr(langs, resources));
57
- }
58
- function watchDirectory(paths, ignored) {
59
- const files = [];
60
- const watcher = watch(paths, {
61
- ignored: ignored,
62
- persistent: true,
63
- ignoreInitial: false
64
- });
65
- watcher.on('add', (path)=>{
66
- files.push(path);
67
- handleFileChange(path, 'added').finally(empty);
68
- });
69
- watcher.on('change', (path)=>{
70
- handleFileChange(path, 'change').finally(empty);
71
- });
72
- watcher.on('unlink', (path)=>{
73
- files.splice(files.indexOf(path), 1);
74
- handleFileChange(path, 'deleted').finally(empty);
75
- });
76
- watcher.on('ready', ()=>{
77
- files.forEach((f)=>{
78
- handleFileChange(f, 'change').finally(empty);
79
- });
80
- });
81
- process.on('SIGINT', function() {
82
- watcher.close();
83
- });
84
- }
85
- stat(join(CONFIG.alias['@'], './locales'), (err, stats)=>{
86
- if (!err && stats.isDirectory()) {
87
- watchDirectory(resolveProgramPath(isLibrary ? 'site/locales' : 'src/locales'), [
88
- /^\..*/,
89
- /!\.ts$/,
90
- /\.d\.ts$/
91
- ]);
92
- }
93
- });
1
+ import{stat as e}from"fs";import{basename as t,join as o}from"path";import{watch as a}from"chokidar";import{CONFIG as l}from"./config.js";import r from"./esm.js";import{FRAMEWORK as n,isLibrary as s}from"./process-env.js";import c from"./reactive-object.js";import{empty as i,resolveProgramPath as g,tfc as f}from"./utils.js";let p={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},u={react:'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',solid:'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'}[n];function d(e,t){return`${p[n]}
2
+ export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(e)};const _res = ${JSON.stringify(t)};const resources = deepFreeze(_res);${u}`}export const localesModuleName="@app/locales";export const locales=new c({[localesModuleName]:d([],{})});let m={};// 要执行的函数
3
+ async function z(e,o){let a=t(e).replace(/\.[^.]+$/,"");if("deleted"===o)delete m[a];else{let t=await import(r`${f(e)}`);Object.assign(m,{[a]:t.default})}let l=[],n={};for(let e in m)if(Object.prototype.hasOwnProperty.call(m,e)){let t=m[e],{language:o=a,title:r=o,icon:s,translation:c={}}=t;l.push({language:o,title:r,icon:s}),n[o]={language:o,title:r,icon:s,translation:c}}locales.setData(localesModuleName,d(l,n))}e(o(l.alias["@"],"./locales"),(e,t)=>{!e&&t.isDirectory()&&function(e,t){let o=[],l=a(e,{ignored:t,persistent:!0,ignoreInitial:!1});l.on("add",e=>{o.push(e),z(e,"added").finally(i)}),l.on("change",e=>{z(e,"change").finally(i)}),l.on("unlink",e=>{o.splice(o.indexOf(e),1),z(e,"deleted").finally(i)}),l.on("ready",()=>{o.forEach(e=>{z(e,"change").finally(i)})}),process.on("SIGINT",function(){l.close()})}(g(s?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/])});
@@ -1 +1 @@
1
- export default 'function merge(e,r){if(!e.length)return void 0;const n=[];e.forEach(e=>{const t=n.findIndex(n=>n[r]==e[r]);if(t>-1){const i=[...n[t].children||[],...e.children||[]];n[t]=Object.assign(e,n[t],n[t].meta&&{meta:{...n[t].meta,...e.meta}});if(i.length){n[t].children=merge(i,r)}}else{n.push(Object.assign(e,Array.isArray(e.children)&&{children:merge(e.children,r)}))}});return n}export default merge;';
1
+ export default"function merge(e,r){if(!e.length)return void 0;const n=[];e.forEach(e=>{const t=n.findIndex(n=>n[r]==e[r]);if(t>-1){const i=[...n[t].children||[],...e.children||[]];n[t]=Object.assign(e,n[t],n[t].meta&&{meta:{...n[t].meta,...e.meta}});if(i.length){n[t].children=merge(i,r)}}else{n.push(Object.assign(e,Array.isArray(e.children)&&{children:merge(e.children,r)}))}});return n}export default merge;";
package/lib/minify.js CHANGED
@@ -1,47 +1,2 @@
1
- import TerserPlugin from 'terser-webpack-plugin';
2
- import { merge } from 'webpack-merge';
3
- import { swcMinifyOption } from './swcrc.js';
4
- export const minify = {
5
- terser: {
6
- minify: TerserPlugin.terserMinify,
7
- terserOptions: {
8
- ecma: 2015,
9
- parse: {},
10
- compress: {
11
- global_defs: {
12
- '@alert': 'console.log'
13
- },
14
- drop_console: true,
15
- drop_debugger: true,
16
- pure_funcs: [
17
- 'console.log',
18
- 'console.warn',
19
- 'console.error',
20
- 'console.info'
21
- ]
22
- },
23
- toplevel: false,
24
- mangle: true,
25
- module: false,
26
- format: {
27
- comments: false
28
- },
29
- // nameCache: null,
30
- ie8: false,
31
- keep_classnames: void 0,
32
- keep_fnames: false,
33
- safari10: false
34
- },
35
- extractComments: false
36
- },
37
- swc: {
38
- minify: TerserPlugin.swcMinify,
39
- terserOptions: swcMinifyOption
40
- }
41
- };
42
- export const getMinifyOption = (type, options = {})=>{
43
- const min = minify[type];
44
- return Object.assign(min, {
45
- terserOptions: merge(min.terserOptions, options)
46
- });
47
- };
1
+ import e from"terser-webpack-plugin";import{merge as o}from"webpack-merge";import{swcMinifyOption as r}from"./swcrc.js";export const minify={terser:{minify:e.terserMinify,terserOptions:{ecma:2015,parse:{},compress:{global_defs:{"@alert":"console.log"},drop_console:!0,drop_debugger:!0,pure_funcs:["console.log","console.warn","console.error","console.info"]},toplevel:!1,mangle:!0,module:!1,format:{comments:!1},// nameCache: null,
2
+ ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1},extractComments:!1},swc:{minify:e.swcMinify,terserOptions:r}};export const getMinifyOption=(e,r={})=>{let s=minify[e];return Object.assign(s,{terserOptions:o(s.terserOptions,r)})};
@@ -1,11 +1 @@
1
- import { CONFIG } from './config.js';
2
- import htmlPluginOption from './html-plugin-option.js';
3
- const prefixCls = CONFIG.prefixCls || 'n';
4
- const modifyVars = {
5
- '@prefix-cls': prefixCls,
6
- '@ant-prefix': prefixCls,
7
- '@iconfont-css-prefix': `${prefixCls}-icon`,
8
- '@favicon': JSON.stringify(htmlPluginOption.favicon)
9
- };
10
- Object.assign(modifyVars, CONFIG.modifyVars);
11
- export default modifyVars;
1
+ import{CONFIG as i}from"./config.js";import o from"./html-plugin-option.js";let f=i.prefixCls||"n",n={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":JSON.stringify(o.favicon)};Object.assign(n,i.modifyVars);export default n;
@@ -1,46 +1 @@
1
- import ExternalTemplateRemotesPlugin from 'external-remotes-plugin';
2
- import webpack from 'webpack';
3
- import ModuleFederationPlugin from 'webpack/lib/container/ModuleFederationPlugin.js';
4
- import { CONFIG } from './config.js';
5
- import { realResolve } from './utils.js';
6
- const NormalModuleReplacementPlugin = webpack.NormalModuleReplacementPlugin;
7
- const aliasLibrary = {};
8
- const exposesMap = {};
9
- const remoteMap = {};
10
- export const moduleFederation = CONFIG.moduleFederation?.map((opt)=>{
11
- if (Array.isArray(opt.remotes)) {
12
- for(let r = 0, rlen = opt.remotes.length; r < rlen; r++){
13
- const m = opt.remotes[r];
14
- const aliasName = m.alias || m.name;
15
- const filename = m.filename || 'remote_entry.js';
16
- remoteMap[aliasName] = `${m.name}@${m.host}/${filename}`;
17
- if (Array.isArray(m.library)) {
18
- for(let i = 0, len = m.library.length; i < len; i++){
19
- aliasLibrary[m.library[i]] = `${aliasName}/${m.library[i]}`;
20
- }
21
- }
22
- }
23
- }
24
- if (Array.isArray(opt.exposes)) {
25
- for(let i = 0, len = opt.exposes.length; i < len; i++){
26
- const m = opt.exposes[i];
27
- if (typeof m === 'string') {
28
- exposesMap[`./${m}`] = realResolve(m);
29
- } else if (Object.prototype.toString.call(m) === '[object Object]') {
30
- exposesMap[`./${m.name}`] = realResolve(m.path);
31
- }
32
- }
33
- }
34
- return new ModuleFederationPlugin({
35
- filename: 'remote_entry.js',
36
- ...opt,
37
- remotes: remoteMap,
38
- exposes: exposesMap
39
- });
40
- });
41
- if (moduleFederation.length) {
42
- moduleFederation.push(new ExternalTemplateRemotesPlugin());
43
- moduleFederation.push(new NormalModuleReplacementPlugin(/(.*)/, (resource)=>{
44
- if (aliasLibrary[resource.request]) resource.request = aliasLibrary[resource.request];
45
- }));
46
- }
1
+ import e from"external-remotes-plugin";import r from"webpack";import t from"webpack/lib/container/ModuleFederationPlugin.js";import{CONFIG as o}from"./config.js";import{realResolve as l}from"./utils.js";let i=r.NormalModuleReplacementPlugin,a={},n={},s={};export const moduleFederation=o.moduleFederation?.map(e=>{if(Array.isArray(e.remotes))for(let r=0,t=e.remotes.length;r<t;r++){let t=e.remotes[r],o=t.alias||t.name,l=t.filename||"remote_entry.js";if(s[o]=`${t.name}@${t.host}/${l}`,Array.isArray(t.library))for(let e=0,r=t.library.length;e<r;e++)a[t.library[e]]=`${o}/${t.library[e]}`}if(Array.isArray(e.exposes))for(let r=0,t=e.exposes.length;r<t;r++){let t=e.exposes[r];"string"==typeof t?n[`./${t}`]=l(t):"[object Object]"===Object.prototype.toString.call(t)&&(n[`./${t.name}`]=l(t.path))}return new t({filename:"remote_entry.js",...e,remotes:s,exposes:n})});moduleFederation.length&&(moduleFederation.push(new e),moduleFederation.push(new i(/(.*)/,e=>{a[e.request]&&(e.request=a[e.request])})));
@@ -1,273 +1,3 @@
1
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
2
- import svgToMiniDataURI from 'mini-svg-data-uri';
3
- import { CONFIG, PUBLICPATH, isTsc } from './config.js';
4
- import { hasPkg } from './has-pkg.js';
5
- import modifyVars from './modify-vars.js';
6
- import paths from './paths.js';
7
- import { FRAMEWORK, isDev, isLibrary, isMicro } from './process-env.js';
8
- import swcOption from './swcrc.js';
9
- import tsLoaderConfig from './tsloader.config.js';
10
- import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
11
- const cssUnicode = {
12
- loader: `${paths.corePath}/loader/css-unicode.cjs`
13
- };
14
- const cssAssetsPublicPath = isMicro ? PUBLICPATH : '../';
15
- let styleLoader = {
16
- loader: MiniCssExtractPlugin.loader,
17
- options: {
18
- publicPath: cssAssetsPublicPath !== '/' ? cssAssetsPublicPath : '../'
19
- }
20
- };
21
- const postcssLoader = hasPkg('@moneko/postcss') && {
22
- loader: 'postcss-loader',
23
- options: {
24
- postcssOptions: (await import('@moneko/postcss')).default
25
- }
26
- };
27
- if (isDev) {
28
- styleLoader = 'style-loader';
29
- }
30
- const customCssModules = [
31
- ...CONFIG.cssModules,
32
- `@moneko/${FRAMEWORK}`,
33
- 'neko-ui'
34
- ].map(resolveNodeModulesPath);
35
- const styleResources = [
36
- ...[
37
- 'src/styles/variables.less',
38
- 'src/styles/mixins.less',
39
- 'site/styles/variables.less',
40
- 'site/styles/mixins.less'
41
- ].map(resolveProgramPath)
42
- ];
43
- const entryResolveProgramPath = [
44
- 'components',
45
- 'example',
46
- 'mock',
47
- 'site',
48
- 'src',
49
- 'server'
50
- ].map(resolveProgramPath);
51
- const cssLoader = {
52
- loader: 'css-loader',
53
- options: {
54
- modules: {
55
- // 根据文件名觉得是否启用cssModules | 排除 node_modules 和 *global.css 和 *global.less
56
- auto: (resourcePath)=>{
57
- for(let i = 0, len = customCssModules.length; i < len; i++){
58
- if (resourcePath && resourcePath?.includes(customCssModules[i])) {
59
- return /(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(resourcePath);
60
- }
61
- }
62
- return /(^(?!.*node_modules))(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(resourcePath);
63
- },
64
- // localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
65
- localIdentName: '[path][name]__[local]',
66
- exportLocalsConvention: 'dashesOnly'
67
- },
68
- importLoaders: 2
69
- }
70
- };
71
- const lessLoaderRule = [
72
- styleLoader,
73
- isDev && {
74
- loader: '@teamsupercell/typings-for-css-modules-loader',
75
- options: {
76
- verifyOnly: !isDev
77
- }
78
- },
79
- cssLoader,
80
- postcssLoader,
81
- cssUnicode,
82
- {
83
- loader: 'less-loader',
84
- options: {
85
- sourceMap: !!CONFIG.sourceMap,
86
- lessOptions: {
87
- modifyVars: modifyVars,
88
- javascriptEnabled: true
89
- }
90
- }
91
- },
92
- {
93
- loader: 'style-resources-loader',
94
- options: {
95
- patterns: styleResources
96
- }
97
- }
98
- ].filter(Boolean);
99
- const jsLoader = {
100
- loader: isTsc ? 'ts-loader' : 'swc-loader',
101
- options: isTsc ? tsLoaderConfig : swcOption(isDev)
102
- };
103
- function include(type) {
104
- return entryResolveProgramPath.concat(CONFIG.rulesInclude?.[type]?.map(resolveNodeModulesPath) || []);
105
- }
106
- const includeMedia = include('media');
107
- const moduleOptions = {
108
- rules: [
109
- isLibrary && {
110
- test: /\.mdx?$/i,
111
- include: [
112
- resolveProgramPath('components')
113
- ],
114
- exclude: [
115
- /(.+)\/examples\/(.+).mdx?$/i
116
- ],
117
- enforce: 'pre',
118
- use: [
119
- {
120
- loader: `${paths.corePath}/loader/frontmatter.cjs`
121
- }
122
- ]
123
- },
124
- {
125
- oneOf: [
126
- {
127
- resourceQuery: /raw/i,
128
- type: 'asset/source'
129
- },
130
- {
131
- resourceQuery: /url/i,
132
- type: 'asset/resource',
133
- generator: {
134
- filename: (pathData)=>{
135
- const filename = pathData.filename;
136
- if (filename && filename.endsWith('wasm?url')) {
137
- return 'wasm/[name][ext]';
138
- }
139
- return 'assets/[name][ext]';
140
- }
141
- }
142
- },
143
- {
144
- test: /\.wasm$/i,
145
- type: 'webassembly/async',
146
- include: include('wasm')
147
- },
148
- {
149
- test: /\.txt$/i,
150
- type: 'asset/source'
151
- },
152
- {
153
- test: /\.ico$/i,
154
- type: 'asset/inline',
155
- include: includeMedia
156
- },
157
- {
158
- test: /\.svg$/i,
159
- type: 'asset/inline',
160
- generator: {
161
- dataUrl (content) {
162
- return svgToMiniDataURI(content.toString());
163
- }
164
- },
165
- include: includeMedia
166
- },
167
- {
168
- test: /\.(gif|png|jpe?g|mp4)$/i,
169
- type: 'asset',
170
- dependency: {
171
- not: [
172
- 'url'
173
- ]
174
- },
175
- generator: {
176
- filename: 'assets/images/[name][ext]'
177
- },
178
- include: includeMedia
179
- },
180
- {
181
- test: /\.(eot|ttf|otf|woff|woff2)$/i,
182
- type: 'asset',
183
- dependency: {
184
- not: [
185
- 'url'
186
- ]
187
- },
188
- generator: {
189
- filename: 'assets/fonts/[name][ext]'
190
- },
191
- include: include('font')
192
- },
193
- {
194
- test: /\.(sa|sc)ss$/i,
195
- use: [
196
- styleLoader,
197
- isDev && {
198
- loader: '@teamsupercell/typings-for-css-modules-loader',
199
- options: {
200
- verifyOnly: !isDev,
201
- sass: true
202
- }
203
- },
204
- cssLoader,
205
- postcssLoader,
206
- cssUnicode,
207
- {
208
- loader: 'sass-loader',
209
- options: {
210
- implementation: (await import('sass')).default,
211
- sassOptions: {}
212
- }
213
- }
214
- ].filter(Boolean),
215
- include: include('css')
216
- },
217
- {
218
- test: /\.less$/i,
219
- use: lessLoaderRule,
220
- include: include('css')
221
- },
222
- {
223
- test: /\.css$/i,
224
- use: [
225
- styleLoader,
226
- 'css-loader',
227
- postcssLoader,
228
- cssUnicode
229
- ].filter(Boolean),
230
- include: include('css')
231
- },
232
- {
233
- test: /\.(cj|mj|t|j)s(|x)$/i,
234
- use: [
235
- ...CONFIG.prefixJsLoader,
236
- jsLoader
237
- ].filter(Boolean),
238
- include: include('js')
239
- },
240
- {
241
- test: /\.mdx?$/i,
242
- use: [
243
- ...CONFIG.prefixJsLoader,
244
- jsLoader,
245
- {
246
- loader: '@mdx-js/loader',
247
- options: CONFIG.mdx
248
- }
249
- ].filter(Boolean),
250
- include: entryResolveProgramPath,
251
- exclude: [
252
- /(.+)\/examples\/(.+).mdx?$/i
253
- ]
254
- },
255
- {
256
- test: /\.mdx?$/i,
257
- type: 'asset/source',
258
- include: [
259
- /(.+)\/examples\/(.+).mdx?$/i
260
- ]
261
- },
262
- {
263
- type: 'asset/source',
264
- include: [
265
- /(.+)\/examples\/(.+).*?$/i
266
- ]
267
- }
268
- ]
269
- },
270
- ...CONFIG.moduleRules
271
- ].filter((e)=>typeof e === 'object')
272
- };
273
- export default moduleOptions;
1
+ import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import{CONFIG as t,PUBLICPATH as o,isTsc as r}from"./config.js";import{hasPkg as a}from"./has-pkg.js";import l from"./modify-vars.js";import i from"./paths.js";import{FRAMEWORK as n,isDev as c,isLibrary as m,isMicro as d}from"./process-env.js";import p from"./swcrc.js";import u from"./tsloader.config.js";import{resolveNodeModulesPath as f,resolveProgramPath as y}from"./utils.js";let x={loader:`${i.corePath}/loader/css-unicode.cjs`},$=d?o:"../",g={loader:e.loader,options:{publicPath:"/"!==$?$:"../"}},j=a("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:(await import("@moneko/postcss")).default}};c&&(g="style-loader");let w=[...t.cssModules,`@moneko/${n}`,"neko-ui"].map(f),v=[...["src/styles/variables.less","src/styles/mixins.less","site/styles/variables.less","site/styles/mixins.less"].map(y)],b=["components","example","mock","site","src","server"].map(y),h={loader:"css-loader",options:{modules:{// 根据文件名觉得是否启用cssModules | 排除 node_modules 和 *global.css 和 *global.less
2
+ auto:e=>{for(let s=0,t=w.length;s<t;s++)if(e&&e?.includes(w[s]))return/(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(e);return/(^(?!.*node_modules))(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(e)},// localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
3
+ localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},k=c&&{loader:"@teamsupercell/typings-for-css-modules-loader",options:{verifyOnly:!c}},O=[g,k,h,j,x,{loader:"less-loader",options:{sourceMap:!!t.sourceMap,lessOptions:{modifyVars:l,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:v}}].filter(Boolean),B={loader:r?"ts-loader":"swc-loader",options:r?u:p(c)};function L(e){return b.concat(t.rulesInclude?.[e]?.map(f)||[])}let M=L("media"),P={rules:[m&&{test:/\.mdx?$/i,include:[y("components")],exclude:[/(.+)\/examples\/(.+).mdx?$/i],enforce:"pre",use:[{loader:`${i.corePath}/loader/frontmatter.cjs`}]},{oneOf:[{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:/\.wasm$/i,type:"webassembly/async",include:L("wasm")},{test:/\.txt$/i,type:"asset/source"},{test:/\.ico$/i,type:"asset/inline",include:M},{test:/\.svg$/i,type:"asset/inline",generator:{dataUrl:e=>s(e.toString())},include:M},{test:/\.(gif|png|jpe?g|mp4)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext]"},include:M},{test:/\.(eot|ttf|otf|woff|woff2)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/fonts/[name][ext]"},include:L("font")},{test:/\.(sa|sc)ss$/i,use:[g,k,h,j,x,{loader:"sass-loader",options:{implementation:await import("sass"),sassOptions:{}}}].filter(Boolean),include:L("css")},{test:/\.less$/i,use:O,include:L("css")},{test:/\.css$/i,use:[g,"css-loader",j,x].filter(Boolean),include:L("css")},{test:/\.(cj|mj|t|j)s(|x)$/i,use:[...t.prefixJsLoader,B].filter(Boolean),include:L("js")},{test:/\.mdx?$/i,use:[...t.prefixJsLoader,B,{loader:"@mdx-js/loader",options:t.mdx}].filter(Boolean),include:b,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/i,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...t.moduleRules].filter(e=>"object"==typeof e)};export default P;
package/lib/net.js CHANGED
@@ -1,33 +1 @@
1
- import { createConnection } from 'net';
2
- import { networkInterfaces } from 'os';
3
- import devServer from 'webpack-dev-server';
4
- const { internalIPSync } = devServer;
5
- export function getNetworkAdress() {
6
- const interfaces = networkInterfaces();
7
- for(const devName in interfaces){
8
- if (Object.prototype.hasOwnProperty.call(interfaces, devName)) {
9
- const iface = interfaces[devName];
10
- for(let i = 0; i < iface.length; i++){
11
- const alias = iface[i];
12
- if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith('169.254') && !alias.internal) {
13
- return alias.address;
14
- }
15
- }
16
- }
17
- }
18
- }
19
- export function getIPv4() {
20
- return internalIPSync('v4');
21
- }
22
- export function getPort(start, end, host = '0.0.0.0') {
23
- return new Promise((resolve)=>{
24
- const tester = createConnection(start, host);
25
- tester.on('connect', ()=>{
26
- tester.destroy();
27
- resolve(getPort(start + 1, end, host));
28
- });
29
- tester.on('error', ()=>{
30
- resolve(start);
31
- });
32
- });
33
- }
1
+ import{createConnection as t}from"net";import{networkInterfaces as e}from"os";import r from"webpack-dev-server";let{internalIPSync:o}=r;export function getNetworkAdress(){let t=e();for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e)){let r=t[e];for(let t=0;t<r.length;t++){let e=r[t];if("IPv4"===e.family&&"127.0.0.1"!==e.address&&!e.address.startsWith("169.254")&&!e.internal)return e.address}}}export function getIPv4(){return o("v4")}export function getPort(e,r,o="0.0.0.0"){return new Promise(n=>{let s=t(e,o);s.on("connect",()=>{s.destroy(),n(getPort(e+1,r,o))}),s.on("error",()=>{n(e)})})}