@moneko/core 3.1.5-beta.0 → 3.1.5-beta.1
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 +177 -1
- package/lib/html-add-entry-attr.js +7 -6
- package/package.json +4 -4
package/lib/common.js
CHANGED
|
@@ -1 +1,177 @@
|
|
|
1
|
-
import e from
|
|
1
|
+
import e from 'fs';
|
|
2
|
+
import t from 'add-asset-html-webpack-plugin';
|
|
3
|
+
import s from 'html-webpack-plugin';
|
|
4
|
+
import o from 'webpack';
|
|
5
|
+
import n from 'webpackbar';
|
|
6
|
+
import './cleanup.js';
|
|
7
|
+
import { CONFIG as l, PUBLICPATH as r } from './config.js';
|
|
8
|
+
import i from './done.js';
|
|
9
|
+
import a from './html-add-entry-attr.js';
|
|
10
|
+
import p from './html-plugin-option.js';
|
|
11
|
+
import { moduleFederation as c } from './module-federation.js';
|
|
12
|
+
import m from './module.config.js';
|
|
13
|
+
import u from './paths.js';
|
|
14
|
+
import {
|
|
15
|
+
CUSTOMCONFIG as f,
|
|
16
|
+
PACKAGENAME as d,
|
|
17
|
+
PACKAGEVERSION as h,
|
|
18
|
+
hasEslintConfig as j,
|
|
19
|
+
hasStylelintConfig as y,
|
|
20
|
+
isDev as g,
|
|
21
|
+
isLibrary as b,
|
|
22
|
+
isMicro as w,
|
|
23
|
+
} from './process-env.js';
|
|
24
|
+
import { seo as x } from './seo.js';
|
|
25
|
+
import { resolveNodeModulesPath as k, resolveProgramPath as v } from './utils.js';
|
|
26
|
+
import C from './virtual-module-plugin.js';
|
|
27
|
+
import $ from './virtual-modules.js';
|
|
28
|
+
let {
|
|
29
|
+
AutomaticPrefetchPlugin: O,
|
|
30
|
+
DefinePlugin: P,
|
|
31
|
+
SourceMapDevToolPlugin: M,
|
|
32
|
+
WatchIgnorePlugin: S,
|
|
33
|
+
} = o,
|
|
34
|
+
B = ['.eslintrc.js', '.eslintrc.json', '.eslintrc.yaml', '.eslintrc.json'],
|
|
35
|
+
D = [
|
|
36
|
+
'.stylelintrc',
|
|
37
|
+
'.stylelintrc.json',
|
|
38
|
+
'.stylelintrc.yaml',
|
|
39
|
+
'.stylelintrc.yml',
|
|
40
|
+
'.stylelintrc.js',
|
|
41
|
+
'stylelint.config.js',
|
|
42
|
+
'stylelint.config.cjs',
|
|
43
|
+
],
|
|
44
|
+
T = e.readdirSync(u.programPath),
|
|
45
|
+
A = !1,
|
|
46
|
+
H = !1;
|
|
47
|
+
for (let e = 0, t = T.length; e < t; e++)
|
|
48
|
+
D.includes(T[e]) && (H = !0), B.includes(T[e]) && (A = !0);
|
|
49
|
+
A || (A = j), H || (H = y);
|
|
50
|
+
let K = H ? (await import('stylelint-webpack-plugin')).default : null,
|
|
51
|
+
L = A ? (await import('eslint-webpack-plugin')).default : null,
|
|
52
|
+
F = l.assetHtml.map((e) => ({ publicPath: '', ...e }));
|
|
53
|
+
export const outputConfig = {
|
|
54
|
+
path: v(b ? 'docs' : 'dist'),
|
|
55
|
+
filename: 'js/[name].bundle.js',
|
|
56
|
+
chunkFilename: `js/[${g ? 'name' : 'chunkhash'}].js`,
|
|
57
|
+
assetModuleFilename: 'assets/[hash][ext][query]',
|
|
58
|
+
library: { name: d, type: 'window' },
|
|
59
|
+
globalObject: 'window',
|
|
60
|
+
chunkLoadingGlobal: `webpackJsonp_${d}`,
|
|
61
|
+
pathinfo: g,
|
|
62
|
+
clean: !0,
|
|
63
|
+
publicPath: r,
|
|
64
|
+
asyncChunks: !0,
|
|
65
|
+
charset: !0,
|
|
66
|
+
};
|
|
67
|
+
let J = { main: k('@app/entry') };
|
|
68
|
+
l.entry &&
|
|
69
|
+
('string' == typeof l.entry ? (J = l.entry) : Object.keys(l.entry) && Object.assign(J, l.entry)),
|
|
70
|
+
l.output &&
|
|
71
|
+
('string' == typeof l.output
|
|
72
|
+
? (outputConfig.path = l.output)
|
|
73
|
+
: Object.keys(l.output) && Object.assign(outputConfig, l.output));
|
|
74
|
+
let R = l.basename.split('/').filter(Boolean).length,
|
|
75
|
+
U = `${Array(R).fill('..').join('/') + (R ? '/' : '')}404.html`,
|
|
76
|
+
{ pathSegmentsToKeep: _ = R, path: q = U } = l.fixBrowserRouter || {},
|
|
77
|
+
z = !1;
|
|
78
|
+
l.cacheDirectory &&
|
|
79
|
+
(z = {
|
|
80
|
+
type: 'filesystem',
|
|
81
|
+
store: 'pack',
|
|
82
|
+
allowCollectingMemory: !0,
|
|
83
|
+
cacheDirectory: l.cacheDirectory,
|
|
84
|
+
memoryCacheUnaffected: !0,
|
|
85
|
+
name: `${f || 'default'}-${g ? 'development' : 'production'}`,
|
|
86
|
+
version: h,
|
|
87
|
+
});
|
|
88
|
+
export const clientConfig = {
|
|
89
|
+
entry: J,
|
|
90
|
+
stats: 'errors-only',
|
|
91
|
+
cache: z,
|
|
92
|
+
infrastructureLogging: { level: 'none' },
|
|
93
|
+
target: 'web',
|
|
94
|
+
externalsPresets: l.externalsPresets,
|
|
95
|
+
plugins: [
|
|
96
|
+
new O(),
|
|
97
|
+
...c,
|
|
98
|
+
L &&
|
|
99
|
+
new L({
|
|
100
|
+
fix: !0,
|
|
101
|
+
threads: !0,
|
|
102
|
+
extensions: [
|
|
103
|
+
'js',
|
|
104
|
+
'md',
|
|
105
|
+
'mdx',
|
|
106
|
+
'cjs',
|
|
107
|
+
'ejs',
|
|
108
|
+
'mjs',
|
|
109
|
+
'jsx',
|
|
110
|
+
'ts',
|
|
111
|
+
'tsx',
|
|
112
|
+
'json',
|
|
113
|
+
'html',
|
|
114
|
+
'coffee',
|
|
115
|
+
'vue',
|
|
116
|
+
],
|
|
117
|
+
}),
|
|
118
|
+
K &&
|
|
119
|
+
new K({
|
|
120
|
+
fix: !0,
|
|
121
|
+
threads: !0,
|
|
122
|
+
extensions: ['css', 'scss', 'sass', 'less', 'ts', 'tsx', 'js', 'jsx'],
|
|
123
|
+
exclude: ['node_modules/', 'es/', 'lib/', 'docs/', 'coverage/', 'dist/'],
|
|
124
|
+
}),
|
|
125
|
+
l.htmlPluginOption && new s(p),
|
|
126
|
+
l.fixBrowserRouter &&
|
|
127
|
+
new s({
|
|
128
|
+
filename: q,
|
|
129
|
+
inject: !1,
|
|
130
|
+
templateContent: () =>
|
|
131
|
+
`<html html><head><title>${p.title}</title><script>var pathSegmentsToKeep = ${
|
|
132
|
+
_ || R
|
|
133
|
+
};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>`,
|
|
134
|
+
}),
|
|
135
|
+
new t(F),
|
|
136
|
+
w && new a((e) => !!(e.match(/main\.(.*)\.bundle.js$/) || e.match('main.bundle.js'))),
|
|
137
|
+
new P({ 'process.env': JSON.stringify(l.env) }),
|
|
138
|
+
new S({ paths: [/\.d\.ts$/] }),
|
|
139
|
+
l.sourceMap && new M(l.sourceMap),
|
|
140
|
+
l.bar && new n(l.bar),
|
|
141
|
+
new i({
|
|
142
|
+
done: () => {
|
|
143
|
+
!g && l.seo && x(),
|
|
144
|
+
l.done?.(),
|
|
145
|
+
g ||
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
process.exit(0);
|
|
148
|
+
}, 2e3);
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
new C($),
|
|
152
|
+
...l.plugins,
|
|
153
|
+
].filter(Boolean),
|
|
154
|
+
experiments: {
|
|
155
|
+
asset: true,
|
|
156
|
+
importAsync: true,
|
|
157
|
+
importAwait: true,
|
|
158
|
+
topLevelAwait: !0,
|
|
159
|
+
asyncWebAssembly: !0,
|
|
160
|
+
cacheUnaffected: !0,
|
|
161
|
+
layers: !0,
|
|
162
|
+
lazyCompilation: g && { imports: !1, entries: !1 },
|
|
163
|
+
buildHttp: l.buildHttp,
|
|
164
|
+
backCompat: !0,
|
|
165
|
+
futureDefaults: !0,
|
|
166
|
+
css: !1,
|
|
167
|
+
outputModule: !1,
|
|
168
|
+
},
|
|
169
|
+
resolve: {
|
|
170
|
+
extensions: ['.tsx', '.ts', '.js', '.jsx', '.wasm'],
|
|
171
|
+
alias: l.alias,
|
|
172
|
+
fallback: { path: !1, fs: !1, crypto: !1, assert: !1 },
|
|
173
|
+
},
|
|
174
|
+
module: m,
|
|
175
|
+
externals: l.externals,
|
|
176
|
+
output: outputConfig,
|
|
177
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default /**
|
|
1
|
+
import t from"html-webpack-plugin";export default /**
|
|
2
2
|
* 向 html-webpack-plugin 导出的 HTML 模板 script 添加属性
|
|
3
3
|
* ```javascript
|
|
4
4
|
* // 假设输出 main chunk 为 main.[hash].chunk.js。
|
|
@@ -8,11 +8,12 @@ export default /**
|
|
|
8
8
|
* })),
|
|
9
9
|
* ```
|
|
10
10
|
*/class{// eslint-disable-next-line no-unused-vars
|
|
11
|
-
constructor(t){this.entryMatchCallback=t}apply(
|
|
12
|
-
let
|
|
13
|
-
//
|
|
11
|
+
constructor(t){this.entryMatchCallback=t}apply(a){a.hooks.compilation.tap("AddEntryAttributeWebpackPlugin",e=>{// 通过最终的 webpack 配置的 plugins 属性,根据插件的 constructor.name 拿到 html-webpack-plugin 实例
|
|
12
|
+
let r=a.options.plugins// .map(({ constructor }) => constructor)
|
|
13
|
+
// .find(
|
|
14
|
+
// (constructor) => constructor && constructor.name === 'HtmlWebpackPlugin',
|
|
14
15
|
// ) as typeof HtmlWebpackPlugin;
|
|
15
|
-
if(
|
|
16
|
-
let t=
|
|
16
|
+
.find(a=>a instanceof t);if(r){// 获取 html-webpack-plugin 所有的 hooks
|
|
17
|
+
let t=r.getHooks(e);// 在插入标签之前做些什么
|
|
17
18
|
t.alterAssetTagGroups.tap("AddEntryAttributeWebpackPlugin",t=>(// 拿到所有的标签,如果是 script 标签,并且满足我们的匹配函数,则将其 attributes['entry'] 设为 true
|
|
18
19
|
t.headTags.forEach(t=>{"script"===t.tagName&&this.entryMatchCallback(t.attributes.src)&&(t.attributes.entry=!0)}),t))}})}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.1.5-beta.
|
|
3
|
+
"version": "3.1.5-beta.1",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"author": "moneko",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@mdx-js/loader": "
|
|
15
|
+
"@mdx-js/loader": "3.0.0",
|
|
16
16
|
"@soda/friendly-errors-webpack-plugin": "1.8.1",
|
|
17
|
-
"@swc/core": "1.3.
|
|
17
|
+
"@swc/core": "1.3.95",
|
|
18
18
|
"@swc/css": "0.0.28",
|
|
19
19
|
"@swc/helpers": "0.5.3",
|
|
20
20
|
"@teamsupercell/typings-for-css-modules-loader": "2.5.2",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"ts-import-plugin": "3.0.0",
|
|
38
38
|
"ts-loader": "9.5.0",
|
|
39
39
|
"typescript": "5.2.2",
|
|
40
|
-
"webpack": "5.
|
|
40
|
+
"webpack": "5.89.0",
|
|
41
41
|
"webpack-bundle-analyzer": "4.9.1",
|
|
42
42
|
"webpack-cli": "5.1.4",
|
|
43
43
|
"webpack-dev-server": "4.15.1",
|