@into-mini/sfc-split-plugin 0.1.0 → 0.1.2
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/package.json +1 -1
- package/plugin/copy-config.mjs +0 -5
- package/plugin/entry-rename.mjs +109 -0
- package/plugin.mjs +5 -0
- package/plugin/expose-entry-bk.mjs +0 -73
package/package.json
CHANGED
package/plugin/copy-config.mjs
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const pluginName = 'EntryRenamePlugin';
|
|
5
|
+
|
|
6
|
+
export class EntryRenamePlugin {
|
|
7
|
+
options;
|
|
8
|
+
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getIssuerPath(issuerModule) {
|
|
14
|
+
return (
|
|
15
|
+
issuerModule?.nameForCondition?.() ??
|
|
16
|
+
issuerModule?.resource ??
|
|
17
|
+
issuerModule?.identifier?.()
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
matchIssuer(issuerPath) {
|
|
22
|
+
const { issuer } = this.options;
|
|
23
|
+
|
|
24
|
+
if (!issuer) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!issuerPath) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (issuer instanceof RegExp) {
|
|
33
|
+
return issuer.test(issuerPath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof issuer === 'function') {
|
|
37
|
+
return issuer(issuerPath);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return issuerPath.includes(issuer);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
matchTest(filename) {
|
|
44
|
+
const { test } = this.options;
|
|
45
|
+
|
|
46
|
+
if (!test) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (test instanceof RegExp) {
|
|
51
|
+
return test.test(filename);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof test === 'function') {
|
|
55
|
+
return test(filename);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return filename.includes(test);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
apply(compiler) {
|
|
62
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
63
|
+
const { Compilation } = compiler.webpack;
|
|
64
|
+
compilation.hooks.processAssets.tap(
|
|
65
|
+
{ name: pluginName, stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS },
|
|
66
|
+
() => {
|
|
67
|
+
for (const module of compilation.modules) {
|
|
68
|
+
const filename = module.buildInfo?.filename;
|
|
69
|
+
|
|
70
|
+
if (!filename) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!this.matchTest(filename)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const issuerModule = compilation.moduleGraph.getIssuer(module);
|
|
79
|
+
const issuerPath = this.getIssuerPath(issuerModule);
|
|
80
|
+
|
|
81
|
+
if (!this.matchIssuer(issuerPath)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const chunks = compilation.chunkGraph.getModuleChunks(module);
|
|
86
|
+
const entryChunk = [...chunks].find((chunk) => chunk.name);
|
|
87
|
+
|
|
88
|
+
if (!entryChunk?.name) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const ext = path.extname(filename);
|
|
93
|
+
const newName = `${entryChunk.name}${ext}`;
|
|
94
|
+
|
|
95
|
+
if (newName === filename) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (compilation.getAsset(newName)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
compilation.renameAsset(filename, newName);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
package/plugin.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { AddWxsPlugin } from './plugin/add-wxs.mjs';
|
|
|
8
8
|
import { CopyConfigPlugin } from './plugin/copy-config.mjs';
|
|
9
9
|
import { EmitFakePlugin } from './plugin/emit-fake.mjs';
|
|
10
10
|
import { ExposeEntryNamePlugin } from './plugin/expose-entry.mjs';
|
|
11
|
+
// import { EntryRenamePlugin } from './plugin/entry-rename.mjs';
|
|
11
12
|
import { FindEntryPlugin } from './plugin/find-entry.mjs';
|
|
12
13
|
import { SfcSplitPlugin } from './plugin/sfc-split.mjs';
|
|
13
14
|
import { MinaRuntimeWebpackPlugin } from './plugin/mina-runtime.mjs';
|
|
@@ -42,6 +43,7 @@ export class AllInOnePlugin {
|
|
|
42
43
|
loader: reach('@into-mini/wxml-loader'),
|
|
43
44
|
generator: {
|
|
44
45
|
filename: '[entry][ext]',
|
|
46
|
+
// filename: '[contenthash:8][ext]',
|
|
45
47
|
},
|
|
46
48
|
},
|
|
47
49
|
{
|
|
@@ -85,6 +87,9 @@ export class AllInOnePlugin {
|
|
|
85
87
|
new AddWxsPlugin().apply(compiler);
|
|
86
88
|
new SfcSplitPlugin({ tagMatcher, preserveTap }).apply(compiler);
|
|
87
89
|
new ExposeEntryNamePlugin().apply(compiler);
|
|
90
|
+
// new EntryRenamePlugin({ issuer: /\.vue$/, test: /\.wxml/ }).apply(
|
|
91
|
+
// compiler,
|
|
92
|
+
// );
|
|
88
93
|
new FindEntryPlugin({ type }).apply(compiler);
|
|
89
94
|
new CopyConfigPlugin({ type }).apply(compiler);
|
|
90
95
|
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import slash from 'slash';
|
|
2
|
-
const PLUGIN_NAME = 'ExposeEntryNamePlugin';
|
|
3
|
-
export class ExposeEntryNamePlugin {
|
|
4
|
-
getEntryNameFromEntries(compilation, module) {
|
|
5
|
-
const { moduleGraph, entries } = compilation;
|
|
6
|
-
for (const [name, io] of entries) {
|
|
7
|
-
for (const dep of io.dependencies) {
|
|
8
|
-
const entryModule = moduleGraph.getModule(dep);
|
|
9
|
-
if (entryModule) {
|
|
10
|
-
if (
|
|
11
|
-
// @ts-expect-error ------------
|
|
12
|
-
entryModule.request && // @ts-expect-error ------------
|
|
13
|
-
slash(entryModule.request) === slash(module.request)
|
|
14
|
-
) {
|
|
15
|
-
return name;
|
|
16
|
-
}
|
|
17
|
-
if (
|
|
18
|
-
// @ts-expect-error ------------
|
|
19
|
-
entryModule?.resource && // @ts-expect-error ------------
|
|
20
|
-
slash(entryModule?.resource) === slash(module.resource)
|
|
21
|
-
) {
|
|
22
|
-
return name;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return '';
|
|
28
|
-
}
|
|
29
|
-
getEntryNameFromPathData(compilation, pathData) {
|
|
30
|
-
const mod = pathData.module;
|
|
31
|
-
const graph = pathData.chunkGraph;
|
|
32
|
-
if (mod && graph) {
|
|
33
|
-
const [entryModule] = graph
|
|
34
|
-
.getModuleChunks(mod)
|
|
35
|
-
.map((chunk) => [...graph.getChunkEntryModulesIterable(chunk)][0]);
|
|
36
|
-
if (entryModule) {
|
|
37
|
-
return this.getEntryNameFromEntries(compilation, entryModule);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
apply(compiler) {
|
|
43
|
-
const {
|
|
44
|
-
NormalModule: { getCompilationHooks },
|
|
45
|
-
} = compiler.webpack;
|
|
46
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
47
|
-
compilation.hooks.assetPath.tap(PLUGIN_NAME, (path, pathData) => {
|
|
48
|
-
if (path.includes('[entry]')) {
|
|
49
|
-
const entryName = this.getEntryNameFromPathData(
|
|
50
|
-
compilation,
|
|
51
|
-
pathData,
|
|
52
|
-
);
|
|
53
|
-
return entryName
|
|
54
|
-
? path.replaceAll('[entry]', entryName)
|
|
55
|
-
: path.replaceAll('[entry]', '[hash:8]');
|
|
56
|
-
}
|
|
57
|
-
return path;
|
|
58
|
-
});
|
|
59
|
-
getCompilationHooks(compilation).loader.tap(
|
|
60
|
-
PLUGIN_NAME,
|
|
61
|
-
(loaderContext, module) => {
|
|
62
|
-
Object.defineProperty(loaderContext, 'entryName', {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: false,
|
|
65
|
-
get: () => {
|
|
66
|
-
return this.getEntryNameFromEntries(compilation, module);
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|