@moneko/core 3.0.0-beta.37 → 3.0.0-beta.39
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/common.js +2 -194
- package/lib/coverage.js +1 -30
- package/lib/done.js +1 -12
- package/lib/envFlags.js +1 -48
- package/lib/esm.js +1 -7
- package/lib/has-pkg.js +1 -14
- package/lib/html-add-entry-attr.js +1 -22
- package/lib/html-plugin-option.js +1 -41
- package/lib/index.js +1 -4
- package/lib/minify.js +1 -46
- package/lib/modifyVars.js +1 -11
- package/lib/module-federation.js +1 -46
- package/lib/module.config.js +1 -184
- package/lib/process-env.js +1 -63
- package/lib/resolver-sync.js +1 -21
- package/lib/routes.js +1 -184
- package/lib/seo.js +1 -57
- package/lib/swcrc.js +1 -111
- package/lib/tsloader.config.js +1 -25
- package/lib/utils.js +1 -64
- package/lib/webpack.common.js +1 -219
- package/lib/webpack.dev.js +3 -97
- package/lib/webpack.prod.js +1 -64
- package/lib/yarn-argv.js +1 -9
- package/package.json +2 -2
- package/typings/global.d.ts +2 -0
package/lib/utils.js
CHANGED
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { networkInterfaces } from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { transformFileSync } from '@swc/core';
|
|
5
|
-
import { cacheDir } from './process-env.js';
|
|
6
|
-
import resolverSync from './resolver-sync.js';
|
|
7
|
-
const swcOption = {
|
|
8
|
-
inputSourceMap: false,
|
|
9
|
-
sourceMaps: false,
|
|
10
|
-
module: {
|
|
11
|
-
type: 'es6'
|
|
12
|
-
},
|
|
13
|
-
jsc: {
|
|
14
|
-
parser: {
|
|
15
|
-
syntax: 'typescript'
|
|
16
|
-
},
|
|
17
|
-
loose: false
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export function tfc(filepath) {
|
|
21
|
-
return transformFileSync(filepath, swcOption).code || '{}';
|
|
22
|
-
}
|
|
23
|
-
export function readConf(src, name) {
|
|
24
|
-
const cacheFile = path.join(cacheDir, `${name}.mjs`);
|
|
25
|
-
writeFileSync(cacheFile, tfc(src), 'utf-8');
|
|
26
|
-
return import(cacheFile);
|
|
27
|
-
}
|
|
28
|
-
export function toUpperCaseString(string) {
|
|
29
|
-
return string?.replace(/\b\w/g, (th)=>th.toUpperCase()).replace(/\./g, ' ');
|
|
30
|
-
}
|
|
31
|
-
export function getIPAdress() {
|
|
32
|
-
const interfaces = networkInterfaces();
|
|
33
|
-
for(const devName in interfaces){
|
|
34
|
-
if (Object.prototype.hasOwnProperty.call(interfaces, devName)) {
|
|
35
|
-
const iface = interfaces[devName];
|
|
36
|
-
for(let i = 0; i < iface.length; i++){
|
|
37
|
-
const alias = iface[i];
|
|
38
|
-
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith('169.254') && !alias.internal) {
|
|
39
|
-
return alias.address;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export function resolveProgramPath(src) {
|
|
46
|
-
return path.resolve(process.cwd(), './' + src);
|
|
47
|
-
}
|
|
48
|
-
export const resolveNodeModulesPath = (src)=>{
|
|
49
|
-
return resolveProgramPath(`node_modules/${src}`);
|
|
50
|
-
};
|
|
51
|
-
export const resolve = (url)=>resolverSync.resolveSync({}, process.cwd(), url) || url;
|
|
52
|
-
const funcTag = '[object Function]';
|
|
53
|
-
const asyncTag = '[object AsyncFunction]';
|
|
54
|
-
const genTag = '[object GeneratorFunction]';
|
|
55
|
-
const proxyTag = '[object Proxy]';
|
|
56
|
-
export function isObject(target) {
|
|
57
|
-
const type = typeof target;
|
|
58
|
-
return target !== null && (type == 'object' || type == 'function');
|
|
59
|
-
}
|
|
60
|
-
export function isFunction(target) {
|
|
61
|
-
if (!isObject(target)) return false;
|
|
62
|
-
const tagType = Object.prototype.toString.call(target);
|
|
63
|
-
return tagType == funcTag || tagType == asyncTag || tagType == genTag || tagType == proxyTag;
|
|
64
|
-
}
|
|
1
|
+
import{writeFileSync as e}from"fs";import{networkInterfaces as t}from"os";import r from"path";import{transformFileSync as o}from"@swc/core";import{cacheDir as n}from"./process-env.js";import s from"./resolver-sync.js";let c={inputSourceMap:!1,sourceMaps:!1,module:{type:"es6"},jsc:{parser:{syntax:"typescript"},loose:!1}};export function tfc(e){return o(e,c).code||"{}"}export function readConf(t,o){let s=r.join(n,`${o}.mjs`);return e(s,tfc(t),"utf-8"),import(s)}export function toUpperCaseString(e){return e?.replace(/\b\w/g,e=>e.toUpperCase()).replace(/\./g," ")}export function getIPAdress(){let e=t();for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)){let r=e[t];for(let e=0;e<r.length;e++){let t=r[e];if("IPv4"===t.family&&"127.0.0.1"!==t.address&&!t.address.startsWith("169.254")&&!t.internal)return t.address}}}export function resolveProgramPath(e){return r.resolve(process.cwd(),"./"+e)}export const resolveNodeModulesPath=e=>resolveProgramPath(`node_modules/${e}`);export const resolve=e=>s.resolveSync({},process.cwd(),e)||e;export function isObject(e){let t=typeof e;return null!==e&&("object"==t||"function"==t)}export function isFunction(e){if(!isObject(e))return!1;let t=Object.prototype.toString.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t||"[object GeneratorFunction]"==t||"[object Proxy]"==t}
|
package/lib/webpack.common.js
CHANGED
|
@@ -1,219 +1 @@
|
|
|
1
|
-
import fs from 'fs
|
|
2
|
-
import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin';
|
|
3
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
4
|
-
import webpack from 'webpack';
|
|
5
|
-
import WebpackBar from 'webpackbar';
|
|
6
|
-
import { CONFIG, ENTRYPATH, PUBLICPATH } from './common.js';
|
|
7
|
-
import DoneWebpackPlugin from './done.js';
|
|
8
|
-
import envFlags from './envFlags.js';
|
|
9
|
-
import AddEntryAttributeWebpackPlugin from './html-add-entry-attr.js';
|
|
10
|
-
import htmlPluginOption from './html-plugin-option.js';
|
|
11
|
-
import { moduleFederation } from './module-federation.js';
|
|
12
|
-
import moduleConfig from './module.config.js';
|
|
13
|
-
import { APPTYPE, DEV, hasEslintConfig, hasStylelintConfig, PACKAGENAME, PROGRAMPATH, FRAMEWORK } from './process-env.js';
|
|
14
|
-
import { frameworkCacheDir } from './routes.js';
|
|
15
|
-
import { seo } from './seo.js';
|
|
16
|
-
import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
|
|
17
|
-
const eslintrc = [
|
|
18
|
-
'.eslintrc.js',
|
|
19
|
-
'.eslintrc.json',
|
|
20
|
-
'.eslintrc.yaml',
|
|
21
|
-
'.eslintrc.json'
|
|
22
|
-
];
|
|
23
|
-
const stylelintrc = [
|
|
24
|
-
'.stylelintrc',
|
|
25
|
-
'.stylelintrc.json',
|
|
26
|
-
'.stylelintrc.yaml',
|
|
27
|
-
'.stylelintrc.yml',
|
|
28
|
-
'.stylelintrc.js',
|
|
29
|
-
'stylelint.config.js',
|
|
30
|
-
'stylelint.config.cjs'
|
|
31
|
-
];
|
|
32
|
-
const rootFiles = fs.readdirSync(PROGRAMPATH);
|
|
33
|
-
let hasEslint = false, hasStylelint = false;
|
|
34
|
-
for(let i = 0, len = rootFiles.length; i < len; i++){
|
|
35
|
-
if (stylelintrc.includes(rootFiles[i])) {
|
|
36
|
-
hasStylelint = true;
|
|
37
|
-
}
|
|
38
|
-
if (eslintrc.includes(rootFiles[i])) {
|
|
39
|
-
hasEslint = true;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (!hasEslint) {
|
|
43
|
-
hasEslint = hasEslintConfig;
|
|
44
|
-
}
|
|
45
|
-
if (!hasStylelint) {
|
|
46
|
-
hasStylelint = hasStylelintConfig;
|
|
47
|
-
}
|
|
48
|
-
const StylelintPlugin = hasStylelint ? (await import('stylelint-webpack-plugin')).default : null;
|
|
49
|
-
const ESLintPlugin = hasEslint ? (await import('eslint-webpack-plugin')).default : null;
|
|
50
|
-
const alias = {
|
|
51
|
-
'@': resolveProgramPath('src'),
|
|
52
|
-
'@framework-cache-dir': frameworkCacheDir
|
|
53
|
-
};
|
|
54
|
-
Object.assign(alias, CONFIG.alias);
|
|
55
|
-
if (APPTYPE === 'library') {
|
|
56
|
-
Object.assign(alias, {
|
|
57
|
-
'@': resolveProgramPath('site'),
|
|
58
|
-
'@pkg': resolveProgramPath('components'),
|
|
59
|
-
[PACKAGENAME]: resolveProgramPath('components')
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
const assetHtmlOption = CONFIG.assetHtml.map((item)=>{
|
|
63
|
-
return {
|
|
64
|
-
publicPath: '',
|
|
65
|
-
...item
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
export const outputConfig = {
|
|
69
|
-
path: resolveProgramPath(APPTYPE === 'library' ? 'docs' : 'dist'),
|
|
70
|
-
filename: 'js/[name].bundle.js',
|
|
71
|
-
chunkFilename: 'js/[name].chunk.js',
|
|
72
|
-
assetModuleFilename: `assets/[name].[hash][ext]`,
|
|
73
|
-
library: PACKAGENAME,
|
|
74
|
-
libraryTarget: 'window',
|
|
75
|
-
globalObject: 'window',
|
|
76
|
-
chunkLoadingGlobal: `webpackJsonp_${PACKAGENAME}`,
|
|
77
|
-
pathinfo: false,
|
|
78
|
-
clean: true,
|
|
79
|
-
publicPath: PUBLICPATH
|
|
80
|
-
};
|
|
81
|
-
let mainEntry = resolveNodeModulesPath(`@moneko/${FRAMEWORK}/lib/packages/${ENTRYPATH[APPTYPE]}/index.js`);
|
|
82
|
-
if (APPTYPE === 'single-component') {
|
|
83
|
-
Object.assign(alias, {
|
|
84
|
-
[PACKAGENAME]: resolveProgramPath('umd')
|
|
85
|
-
});
|
|
86
|
-
mainEntry = resolveProgramPath(DEV ? 'example/index.ts' : 'src/index.ts');
|
|
87
|
-
outputConfig.path = resolveProgramPath(DEV ? 'dist' : 'umd');
|
|
88
|
-
outputConfig.filename = 'index.js';
|
|
89
|
-
outputConfig.library = PACKAGENAME;
|
|
90
|
-
outputConfig.libraryTarget = 'umd';
|
|
91
|
-
outputConfig.libraryExport = 'default';
|
|
92
|
-
}
|
|
93
|
-
let entryMap = {
|
|
94
|
-
main: mainEntry
|
|
95
|
-
};
|
|
96
|
-
if (CONFIG.entry) {
|
|
97
|
-
if (typeof CONFIG.entry === 'string') {
|
|
98
|
-
entryMap = CONFIG.entry;
|
|
99
|
-
} else if (Object.keys(CONFIG.entry)) {
|
|
100
|
-
Object.assign(entryMap, CONFIG.entry);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (CONFIG.output) {
|
|
104
|
-
if (typeof CONFIG.output === 'string') {
|
|
105
|
-
outputConfig.path = CONFIG.output;
|
|
106
|
-
} else if (Object.keys(CONFIG.output)) {
|
|
107
|
-
Object.assign(outputConfig, CONFIG.output);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const dirDeep = CONFIG.routeBaseName.split('/').filter(Boolean).length;
|
|
111
|
-
const page404 = Array(dirDeep).fill('..').join('/') + (dirDeep ? '/' : '') + '404.html';
|
|
112
|
-
const { pathSegmentsToKeep =dirDeep , path =page404 } = CONFIG.fixBrowserRouter || {};
|
|
113
|
-
const config = {
|
|
114
|
-
entry: entryMap,
|
|
115
|
-
stats: 'errors-only',
|
|
116
|
-
infrastructureLogging: {
|
|
117
|
-
level: 'none'
|
|
118
|
-
},
|
|
119
|
-
target: 'web',
|
|
120
|
-
plugins: [
|
|
121
|
-
new webpack.AutomaticPrefetchPlugin(),
|
|
122
|
-
...moduleFederation,
|
|
123
|
-
ESLintPlugin && new ESLintPlugin({
|
|
124
|
-
fix: true,
|
|
125
|
-
threads: true,
|
|
126
|
-
extensions: [
|
|
127
|
-
'js',
|
|
128
|
-
'md',
|
|
129
|
-
'mdx',
|
|
130
|
-
'cjs',
|
|
131
|
-
'ejs',
|
|
132
|
-
'mjs',
|
|
133
|
-
'jsx',
|
|
134
|
-
'ts',
|
|
135
|
-
'tsx',
|
|
136
|
-
'json',
|
|
137
|
-
'html',
|
|
138
|
-
'coffee',
|
|
139
|
-
'vue'
|
|
140
|
-
]
|
|
141
|
-
}),
|
|
142
|
-
StylelintPlugin && new StylelintPlugin({
|
|
143
|
-
fix: true,
|
|
144
|
-
threads: true,
|
|
145
|
-
extensions: [
|
|
146
|
-
'css',
|
|
147
|
-
'scss',
|
|
148
|
-
'sass',
|
|
149
|
-
'less',
|
|
150
|
-
'ts',
|
|
151
|
-
'tsx',
|
|
152
|
-
'js',
|
|
153
|
-
'jsx'
|
|
154
|
-
],
|
|
155
|
-
exclude: [
|
|
156
|
-
'node_modules/',
|
|
157
|
-
'es/',
|
|
158
|
-
'lib/',
|
|
159
|
-
'docs/',
|
|
160
|
-
'coverage/',
|
|
161
|
-
'dist/'
|
|
162
|
-
]
|
|
163
|
-
}),
|
|
164
|
-
new HtmlWebpackPlugin(htmlPluginOption),
|
|
165
|
-
CONFIG.fixBrowserRouter && new HtmlWebpackPlugin({
|
|
166
|
-
filename: path,
|
|
167
|
-
inject: false,
|
|
168
|
-
templateContent: ()=>`<html html><head><title>${htmlPluginOption.title}</title><script>var pathSegmentsToKeep = ${pathSegmentsToKeep || dirDeep};var l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`
|
|
169
|
-
}),
|
|
170
|
-
new AddAssetHtmlPlugin(assetHtmlOption),
|
|
171
|
-
APPTYPE === 'single-spa' && new AddEntryAttributeWebpackPlugin((src)=>{
|
|
172
|
-
return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
|
|
173
|
-
}),
|
|
174
|
-
new webpack.DefinePlugin(envFlags),
|
|
175
|
-
new webpack.WatchIgnorePlugin({
|
|
176
|
-
paths: [
|
|
177
|
-
/\.d\.ts$/
|
|
178
|
-
]
|
|
179
|
-
}),
|
|
180
|
-
CONFIG.sourceMap && new webpack.SourceMapDevToolPlugin(CONFIG.sourceMap),
|
|
181
|
-
new WebpackBar({
|
|
182
|
-
name: '编译中',
|
|
183
|
-
color: '#6f42c1'
|
|
184
|
-
}),
|
|
185
|
-
new DoneWebpackPlugin({
|
|
186
|
-
done: ()=>{
|
|
187
|
-
if (!DEV && CONFIG.seo) {
|
|
188
|
-
seo();
|
|
189
|
-
}
|
|
190
|
-
CONFIG.done?.();
|
|
191
|
-
}
|
|
192
|
-
}),
|
|
193
|
-
...CONFIG.plugins
|
|
194
|
-
].filter(Boolean),
|
|
195
|
-
experiments: {
|
|
196
|
-
topLevelAwait: true,
|
|
197
|
-
syncWebAssembly: true,
|
|
198
|
-
asyncWebAssembly: true
|
|
199
|
-
},
|
|
200
|
-
resolve: {
|
|
201
|
-
extensions: [
|
|
202
|
-
'.tsx',
|
|
203
|
-
'.ts',
|
|
204
|
-
'.js',
|
|
205
|
-
'.jsx'
|
|
206
|
-
],
|
|
207
|
-
alias: alias,
|
|
208
|
-
fallback: {
|
|
209
|
-
path: false,
|
|
210
|
-
fs: false,
|
|
211
|
-
crypto: false,
|
|
212
|
-
assert: false
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
module: moduleConfig,
|
|
216
|
-
externals: CONFIG.externals,
|
|
217
|
-
output: outputConfig
|
|
218
|
-
};
|
|
219
|
-
export default config;
|
|
1
|
+
import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import n from"webpack";import o from"webpackbar";import{CONFIG as l,ENTRYPATH as i,PUBLICPATH as r}from"./common.js";import a from"./done.js";import p from"./envFlags.js";import m from"./html-add-entry-attr.js";import c from"./html-plugin-option.js";import{moduleFederation as u}from"./module-federation.js";import f from"./module.config.js";import{APPTYPE as d,DEV as g,hasEslintConfig as j,hasStylelintConfig as h,PACKAGENAME as b,PROGRAMPATH as y,FRAMEWORK as w}from"./process-env.js";import{frameworkCacheDir as x}from"./routes.js";import{seo as k}from"./seo.js";import{resolveNodeModulesPath as v,resolveProgramPath as C}from"./utils.js";let O=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],P=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],$=e.readdirSync(y),T=!1,A=!1;for(let e=0,t=$.length;e<t;e++)P.includes($[e])&&(A=!0),O.includes($[e])&&(T=!0);T||(T=j),A||(A=h);let B=A?(await import("stylelint-webpack-plugin")).default:null,S=T?(await import("eslint-webpack-plugin")).default:null,M={"@":C("src"),"@framework-cache-dir":x};Object.assign(M,l.alias),"library"===d&&Object.assign(M,{"@":C("site"),"@pkg":C("components"),[b]:C("components")});let F=l.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:C("library"===d?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:"js/[name].chunk.js",assetModuleFilename:"assets/[name].[hash][ext]",library:b,libraryTarget:"window",globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${b}`,pathinfo:!1,clean:!0,publicPath:r};let K=v(`@moneko/${w}/lib/packages/${i[d]}/index.js`);"single-component"===d&&(Object.assign(M,{[b]:C("umd")}),K=C(g?"example/index.ts":"src/index.ts"),outputConfig.path=C(g?"dist":"umd"),outputConfig.filename="index.js",outputConfig.library=b,outputConfig.libraryTarget="umd",outputConfig.libraryExport="default");let L={main:K};l.entry&&("string"==typeof l.entry?L=l.entry:Object.keys(l.entry)&&Object.assign(L,l.entry)),l.output&&("string"==typeof l.output?outputConfig.path=l.output:Object.keys(l.output)&&Object.assign(outputConfig,l.output));let W=l.routeBaseName.split("/").filter(Boolean).length,D=Array(W).fill("..").join("/")+(W?"/":"")+"404.html",{pathSegmentsToKeep:R=W,path:_=D}=l.fixBrowserRouter||{},E={entry:L,stats:"errors-only",infrastructureLogging:{level:"none"},target:"web",plugins:[new n.AutomaticPrefetchPlugin,...u,S&&new S({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"]}),B&&new B({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","docs/","coverage/","dist/"]}),new s(c),l.fixBrowserRouter&&new s({filename:_,inject:!1,templateContent:()=>`<html html><head><title>${c.title}</title><script>var pathSegmentsToKeep = ${R||W};var l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}),new t(F),"single-spa"===d&&new m(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new n.DefinePlugin(p),new n.WatchIgnorePlugin({paths:[/\.d\.ts$/]}),l.sourceMap&&new n.SourceMapDevToolPlugin(l.sourceMap),l.bar&&new o(l.bar),new a({done:()=>{!g&&l.seo&&k(),l.done?.()}}),...l.plugins].filter(Boolean),experiments:{topLevelAwait:!0,syncWebAssembly:!0,asyncWebAssembly:!0},resolve:{extensions:[".tsx",".ts",".js",".jsx"],alias:M,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:f,externals:l.externals,output:outputConfig};export default E;
|
package/lib/webpack.dev.js
CHANGED
|
@@ -1,98 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { getPort } from 'portfinder';
|
|
4
|
-
import webpack from 'webpack';
|
|
5
|
-
import { merge } from 'webpack-merge';
|
|
6
|
-
import { CONFIG } from './common.js';
|
|
7
|
-
import { hasPkg } from './has-pkg.js';
|
|
8
|
-
import { FRAMEWORK } from './process-env.js';
|
|
9
|
-
import { getIPAdress, isFunction, resolveProgramPath } from './utils.js';
|
|
10
|
-
import common from './webpack.common.js';
|
|
11
|
-
const hasMockMiddlewares = hasPkg('@moneko/mock');
|
|
12
|
-
const mockMiddlewares = hasMockMiddlewares && await import('@moneko/mock');
|
|
13
|
-
const ReactRefresh = FRAMEWORK === 'react' && (await import('@pmmmwh/react-refresh-webpack-plugin')).default;
|
|
14
|
-
let cacheConfig = false;
|
|
15
|
-
if (CONFIG.cacheDirectory) {
|
|
16
|
-
cacheConfig = {
|
|
17
|
-
type: 'filesystem',
|
|
18
|
-
allowCollectingMemory: true,
|
|
19
|
-
cacheDirectory: CONFIG.cacheDirectory
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const devtool = CONFIG.devtool === false || CONFIG.devtool ? CONFIG.devtool : 'eval-cheap-module-source-map';
|
|
23
|
-
const webpackConfig = new Promise((resolve)=>{
|
|
24
|
-
getPort({
|
|
25
|
-
port: CONFIG.devServer.port,
|
|
26
|
-
stopPort: 9999
|
|
27
|
-
}, (_err, port)=>{
|
|
28
|
-
const notes = [];
|
|
29
|
-
if (CONFIG.devServer.port !== port) {
|
|
30
|
-
notes.push(`Port ${chalk.yellow(CONFIG.devServer.port)} is in use, trying ${chalk.green(port)} instead`);
|
|
31
|
-
}
|
|
32
|
-
CONFIG.devServer.port = port;
|
|
33
|
-
const initRouteBase = CONFIG.routeBaseName === '/';
|
|
34
|
-
const protocol = CONFIG.devServer.https ? 'https:' : 'http:';
|
|
35
|
-
const routeBase = initRouteBase ? '' : CONFIG.routeBaseName;
|
|
36
|
-
const conf = merge(common, {
|
|
37
|
-
devtool: devtool,
|
|
38
|
-
mode: 'development',
|
|
39
|
-
cache: cacheConfig,
|
|
40
|
-
devServer: {
|
|
41
|
-
headers: {
|
|
42
|
-
'Access-Control-Allow-Origin': '*'
|
|
43
|
-
},
|
|
44
|
-
compress: CONFIG.devServer.compress,
|
|
45
|
-
host: '0.0.0.0',
|
|
46
|
-
port: port,
|
|
47
|
-
historyApiFallback: initRouteBase || {
|
|
48
|
-
index: routeBase,
|
|
49
|
-
disableDotRule: true
|
|
50
|
-
},
|
|
51
|
-
https: CONFIG.devServer.https,
|
|
52
|
-
proxy: CONFIG.proxy,
|
|
53
|
-
allowedHosts: CONFIG.devServer.allowedHosts,
|
|
54
|
-
client: {
|
|
55
|
-
progress: false,
|
|
56
|
-
logging: 'info',
|
|
57
|
-
overlay: false
|
|
58
|
-
},
|
|
59
|
-
static: {
|
|
60
|
-
watch: {
|
|
61
|
-
ignored: (f)=>{
|
|
62
|
-
return f.endsWith('.d.ts') || /\/node_modules\//.test(f);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
setupMiddlewares: (middlewares, devServer)=>{
|
|
67
|
-
if (!devServer) {
|
|
68
|
-
throw new Error('webpack-dev-server is not defined');
|
|
69
|
-
}
|
|
70
|
-
if (devServer.app && isFunction(mockMiddlewares)) {
|
|
71
|
-
mockMiddlewares(devServer.app, resolveProgramPath('mock/'));
|
|
72
|
-
}
|
|
73
|
-
return middlewares;
|
|
74
|
-
},
|
|
75
|
-
open: false,
|
|
76
|
-
hot: true
|
|
77
|
-
},
|
|
78
|
-
plugins: [
|
|
79
|
-
new webpack.HotModuleReplacementPlugin(),
|
|
80
|
-
ReactRefresh && new ReactRefresh(),
|
|
81
|
-
new FriendlyErrorsWebpackPlugin({
|
|
82
|
-
compilationSuccessInfo: {
|
|
83
|
-
messages: [
|
|
84
|
-
`You application is running here:
|
|
1
|
+
import e from"@soda/friendly-errors-webpack-plugin";import o from"chalk";import{getPort as r}from"portfinder";import t from"webpack";import{merge as s}from"webpack-merge";import{CONFIG as p}from"./common.js";import{hasPkg as i}from"./has-pkg.js";import{FRAMEWORK as l}from"./process-env.js";import{getIPAdress as a,isFunction as m,resolveProgramPath as n}from"./utils.js";import c from"./webpack.common.js";let d=i("@moneko/mock"),v=d&&await import("@moneko/mock"),h="react"===l&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,w=!1;p.cacheDirectory&&(w={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:p.cacheDirectory});let f=!1===p.devtool||p.devtool?p.devtool:"eval-cheap-module-source-map",u=new Promise(i=>{r({port:p.devServer.port,stopPort:9999},(r,l)=>{let d=[];p.devServer.port!==l&&d.push(`Port ${o.yellow(p.devServer.port)} is in use, trying ${o.green(l)} instead`),p.devServer.port=l;let u="/"===p.routeBaseName,g=p.devServer.https?"https:":"http:",k=u?"":p.routeBaseName,y=s(c,{devtool:f,mode:"development",cache:w,devServer:{headers:{"Access-Control-Allow-Origin":"*"},compress:p.devServer.compress,host:"0.0.0.0",port:l,historyApiFallback:u||{index:k,disableDotRule:!0},https:p.devServer.https,proxy:p.proxy,allowedHosts:p.devServer.allowedHosts,client:{progress:!1,logging:"info",overlay:!1},static:{watch:{ignored:e=>e.endsWith(".d.ts")||/\/node_modules\//.test(e)}},setupMiddlewares:(e,o)=>{if(!o)throw Error("webpack-dev-server is not defined");return o.app&&m(v)&&v(o.app,n("mock/")),e},open:!1,hot:!0},plugins:[new t.HotModuleReplacementPlugin,h&&new h,new e({compilationSuccessInfo:{messages:[`You application is running here:
|
|
85
2
|
|
|
86
|
-
local: ${
|
|
87
|
-
network: ${
|
|
88
|
-
],
|
|
89
|
-
notes: notes
|
|
90
|
-
},
|
|
91
|
-
clearConsole: true
|
|
92
|
-
})
|
|
93
|
-
].filter(Boolean)
|
|
94
|
-
});
|
|
95
|
-
resolve(conf);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
export default webpackConfig;
|
|
3
|
+
local: ${o.cyan(`${g}//${p.devServer.host}:${l}${k}`)}
|
|
4
|
+
network: ${o.cyan(`${g}//${a()}:${l}${k}`)}`],notes:d},clearConsole:!0})].filter(Boolean)});i(y)})});export default u;
|
package/lib/webpack.prod.js
CHANGED
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
3
|
-
import TerserPlugin from 'terser-webpack-plugin';
|
|
4
|
-
import webpack from 'webpack';
|
|
5
|
-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
|
6
|
-
import { merge } from 'webpack-merge';
|
|
7
|
-
import { CONFIG } from './common.js';
|
|
8
|
-
import { getMinifyOption } from './minify.js';
|
|
9
|
-
import common from './webpack.common.js';
|
|
10
|
-
const { cssnanoMinify , swcMinify } = CssMinimizerPlugin;
|
|
11
|
-
const defaultJsMiniify = CONFIG.compiler === 'swc' ? 'swc' : 'terser';
|
|
12
|
-
const defaultCssMiniify = CONFIG.compiler === 'swc' ? 'swc' : 'cssnano';
|
|
13
|
-
const cssMinify = {
|
|
14
|
-
swc: swcMinify,
|
|
15
|
-
cssnano: cssnanoMinify
|
|
16
|
-
};
|
|
17
|
-
const minimizer = [];
|
|
18
|
-
if (CONFIG.minifier) {
|
|
19
|
-
if (CONFIG.minifier.js) {
|
|
20
|
-
minimizer.push(new TerserPlugin(getMinifyOption(CONFIG.minifier.js?.type || defaultJsMiniify, CONFIG.minifier.js?.options)));
|
|
21
|
-
}
|
|
22
|
-
if (CONFIG.minifier.css) {
|
|
23
|
-
minimizer.push(new CssMinimizerPlugin({
|
|
24
|
-
minify: cssMinify[CONFIG.minifier.css?.type || defaultCssMiniify],
|
|
25
|
-
minimizerOptions: CONFIG.minifier.css?.options
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const optimization = {
|
|
30
|
-
splitChunks: CONFIG.splitChunk,
|
|
31
|
-
runtimeChunk: CONFIG.runtimeChunk,
|
|
32
|
-
chunkIds: 'named',
|
|
33
|
-
moduleIds: 'named',
|
|
34
|
-
removeAvailableModules: true,
|
|
35
|
-
removeEmptyChunks: true,
|
|
36
|
-
mergeDuplicateChunks: true,
|
|
37
|
-
minimize: true,
|
|
38
|
-
minimizer: minimizer
|
|
39
|
-
};
|
|
40
|
-
let cacheConfig = false;
|
|
41
|
-
if (CONFIG.cacheDirectory) {
|
|
42
|
-
cacheConfig = {
|
|
43
|
-
type: 'filesystem',
|
|
44
|
-
allowCollectingMemory: true,
|
|
45
|
-
cacheDirectory: CONFIG.cacheDirectory
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
export default merge(common, {
|
|
49
|
-
devtool: CONFIG.devtool === false || CONFIG.devtool ? CONFIG.devtool : 'cheap-module-source-map',
|
|
50
|
-
mode: 'production',
|
|
51
|
-
cache: cacheConfig,
|
|
52
|
-
optimization: optimization,
|
|
53
|
-
plugins: [
|
|
54
|
-
new MiniCssExtractPlugin({
|
|
55
|
-
filename: 'style/[name].bundle.css',
|
|
56
|
-
chunkFilename: 'style/[name].chunk.css',
|
|
57
|
-
experimentalUseImportModule: true
|
|
58
|
-
}),
|
|
59
|
-
CONFIG.bundleAnalyzer && new BundleAnalyzerPlugin(CONFIG.bundleAnalyzer),
|
|
60
|
-
CONFIG.splitChunk && new webpack.optimize.MinChunkSizePlugin({
|
|
61
|
-
minChunkSize: 10000
|
|
62
|
-
})
|
|
63
|
-
].filter(Boolean)
|
|
64
|
-
});
|
|
1
|
+
import e from"css-minimizer-webpack-plugin";import i from"mini-css-extract-plugin";import m from"terser-webpack-plugin";import n from"webpack";import{BundleAnalyzerPlugin as o}from"webpack-bundle-analyzer";import{merge as r}from"webpack-merge";import{CONFIG as s}from"./common.js";import{getMinifyOption as t}from"./minify.js";import{CUSTOMCONFIG as c}from"./process-env.js";import p from"./webpack.common.js";let{cssnanoMinify:l,swcMinify:a}=e,u="swc"===s.compiler?"swc":"terser",f="swc"===s.compiler?"swc":"cssnano",d=[];s.minifier&&(s.minifier.js&&d.push(new m(t(s.minifier.js?.type||u,s.minifier.js?.options))),s.minifier.css&&d.push(new e({minify:{swc:a,cssnano:l}[s.minifier.css?.type||f],minimizerOptions:s.minifier.css?.options})));let h={splitChunks:s.splitChunk,runtimeChunk:s.runtimeChunk,chunkIds:"named",moduleIds:"named",removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,minimize:!0,minimizer:d},k=!1;s.cacheDirectory&&(k={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:`${s.cacheDirectory}-${c}`});export default r(p,{devtool:!1===s.devtool||s.devtool?s.devtool:"cheap-module-source-map",mode:"production",cache:k,optimization:h,plugins:[new i({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.css",experimentalUseImportModule:!0}),s.bundleAnalyzer&&new o(s.bundleAnalyzer),s.splitChunk&&new n.optimize.MinChunkSizePlugin({minChunkSize:1e4})].filter(Boolean)});
|
package/lib/yarn-argv.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const yarnArgv = {};
|
|
3
|
-
original?.forEach((o)=>{
|
|
4
|
-
const m = o.split('=');
|
|
5
|
-
Object.assign(yarnArgv, {
|
|
6
|
-
[m[0]]: m[1] || true
|
|
7
|
-
});
|
|
8
|
-
});
|
|
9
|
-
export default yarnArgv;
|
|
1
|
+
let e=JSON.parse(process.env.npm_config_argv||"{}")?.original,a={};e?.forEach(e=>{let r=e.split("=");Object.assign(a,{[r[0]]:r[1]||!0})});export default a;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.39",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "swc src -d lib -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=true -C jsc.minify.mangle=
|
|
8
|
+
"build": "swc src -d lib -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=true -C jsc.minify.mangle=true -C jsc.minify.compress=true -C minify=true -D",
|
|
9
9
|
"prebuild": "rm -rf ./lib && tsc"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [],
|
package/typings/global.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
ProxyConfigMap,
|
|
15
15
|
WebpackConfiguration,
|
|
16
16
|
} from 'webpack-dev-server';
|
|
17
|
+
import type { State } from 'webpackbar';
|
|
17
18
|
|
|
18
19
|
export type MinifierType = 'swc' | 'terser';
|
|
19
20
|
export declare type AppType =
|
|
@@ -272,6 +273,7 @@ export declare type ConfigType<T extends 'tsc' | 'swc' = 'swc'> = {
|
|
|
272
273
|
generate?: 'ssr' | 'dom';
|
|
273
274
|
hydratable?: boolean;
|
|
274
275
|
};
|
|
276
|
+
bar?: Partial<State>;
|
|
275
277
|
};
|
|
276
278
|
export declare interface ModuleFederationOption {
|
|
277
279
|
/** 模块名称,唯一性,不能重名 */
|