@into-mini/sfc-split-plugin 0.6.4 → 0.6.6
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/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AddWxsPlugin } from "./plugin/add-wxs.mjs";
|
|
2
2
|
import { ExposeEntryNamePlugin } from "./plugin/expose-entry.mjs";
|
|
3
|
-
import { EntryRenamePlugin } from
|
|
3
|
+
// import { EntryRenamePlugin } from './plugin/entry-rename.mts';
|
|
4
4
|
import { MinaRuntimeWebpackPlugin } from "./plugin/mina-runtime.mjs";
|
|
5
5
|
export class SfcSplitPlugin {
|
|
6
6
|
options;
|
|
@@ -17,10 +17,10 @@ export class SfcSplitPlugin {
|
|
|
17
17
|
new AddWxsPlugin().apply(compiler);
|
|
18
18
|
new MinaRuntimeWebpackPlugin().apply(compiler);
|
|
19
19
|
new ExposeEntryNamePlugin().apply(compiler);
|
|
20
|
-
new EntryRenamePlugin({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}).apply(compiler);
|
|
20
|
+
// new EntryRenamePlugin({
|
|
21
|
+
// issuer: /\.vue$/,
|
|
22
|
+
// test: /\.wxml|json/,
|
|
23
|
+
// }).apply(compiler);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -12,10 +12,12 @@ function reach(path) {
|
|
|
12
12
|
return fileURLToPath(import.meta.resolve(path));
|
|
13
13
|
}
|
|
14
14
|
const componentRoot = 'as-components';
|
|
15
|
-
function handleImport({
|
|
15
|
+
function handleImport({ addSmartEntry, context, rootContext, maps, callback }) {
|
|
16
16
|
if (Object.keys(maps).length > 0) {
|
|
17
|
-
for (const [name,
|
|
18
|
-
if (
|
|
17
|
+
for (const [name, src] of Object.entries(maps)) {
|
|
18
|
+
if ((src.endsWith('.vue') || src.startsWith('vue:')) &&
|
|
19
|
+
!src.startsWith('plugin://')) {
|
|
20
|
+
const path = src.replace(/^vue:/, '');
|
|
19
21
|
try {
|
|
20
22
|
const absolutePath = slash(path.startsWith('.') ? resolve(context, path) : reach(path));
|
|
21
23
|
const relativePath = slash(relative(rootContext, absolutePath));
|
|
@@ -31,7 +33,7 @@ function handleImport({ toThis, addSmartEntry, context, rootContext, maps, callb
|
|
|
31
33
|
createShortHash(slash(relativePath)),
|
|
32
34
|
].join('/')
|
|
33
35
|
: relativePath.replace(/\.vue$/, '');
|
|
34
|
-
const placer =
|
|
36
|
+
const placer = `/${entryName}`;
|
|
35
37
|
callback({
|
|
36
38
|
name,
|
|
37
39
|
placer,
|
|
@@ -56,19 +58,14 @@ function handleImport({ toThis, addSmartEntry, context, rootContext, maps, callb
|
|
|
56
58
|
export default function loader(source) {
|
|
57
59
|
this.cacheable();
|
|
58
60
|
const callback = this.async();
|
|
59
|
-
const { entryName: thisEntryName } = this;
|
|
60
61
|
const config = JSON.parse(source.trim() || '{}');
|
|
61
62
|
const { rootContext, context } = this;
|
|
62
|
-
function toThis(entryName) {
|
|
63
|
-
return slash(relative(`/${thisEntryName}/..`, `/${entryName}`));
|
|
64
|
-
}
|
|
65
63
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
66
64
|
const addSmartEntry = (io) => {
|
|
67
65
|
this.addSmartEntry(io);
|
|
68
66
|
};
|
|
69
67
|
if (config?.usingComponents) {
|
|
70
68
|
handleImport.bind(this)({
|
|
71
|
-
toThis,
|
|
72
69
|
addSmartEntry,
|
|
73
70
|
componentRoot,
|
|
74
71
|
context,
|
|
@@ -85,7 +82,6 @@ export default function loader(source) {
|
|
|
85
82
|
}
|
|
86
83
|
if (config?.componentGenerics) {
|
|
87
84
|
handleImport.bind(this)({
|
|
88
|
-
toThis,
|
|
89
85
|
addSmartEntry,
|
|
90
86
|
context,
|
|
91
87
|
rootContext,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Compiler,
|
|
1
|
+
import type { Compiler, PathData, Chunk, WebpackPluginInstance } from 'webpack';
|
|
2
2
|
export declare class ExposeEntryNamePlugin implements WebpackPluginInstance {
|
|
3
3
|
getEntryNameFromChunk(chunk: Chunk): string | null | undefined;
|
|
4
|
-
getEntryNameFromEntries(compilation: Compilation, module: Module): string;
|
|
5
4
|
getEntryNameFromPathData(pathData: PathData): string;
|
|
6
5
|
apply(compiler: Compiler): void;
|
|
7
6
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import slash from 'slash';
|
|
2
1
|
const PLUGIN_NAME = 'ExposeEntryNamePlugin';
|
|
3
2
|
export class ExposeEntryNamePlugin {
|
|
4
3
|
getEntryNameFromChunk(chunk) {
|
|
@@ -12,29 +11,6 @@ export class ExposeEntryNamePlugin {
|
|
|
12
11
|
}
|
|
13
12
|
return '';
|
|
14
13
|
}
|
|
15
|
-
getEntryNameFromEntries(compilation, module) {
|
|
16
|
-
const { moduleGraph, entries } = compilation;
|
|
17
|
-
for (const [name, io] of entries) {
|
|
18
|
-
for (const dep of io.dependencies) {
|
|
19
|
-
const entryModule = moduleGraph.getModule(dep);
|
|
20
|
-
if (entryModule) {
|
|
21
|
-
if (
|
|
22
|
-
// @ts-expect-error ------------
|
|
23
|
-
entryModule.request && // @ts-expect-error ------------
|
|
24
|
-
slash(entryModule.request) === slash(module.request)) {
|
|
25
|
-
return name;
|
|
26
|
-
}
|
|
27
|
-
if (
|
|
28
|
-
// @ts-expect-error ------------
|
|
29
|
-
entryModule?.resource && // @ts-expect-error ------------
|
|
30
|
-
slash(entryModule?.resource) === slash(module.resource)) {
|
|
31
|
-
return name;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return '';
|
|
37
|
-
}
|
|
38
14
|
getEntryNameFromPathData(pathData) {
|
|
39
15
|
if (pathData?.chunk) {
|
|
40
16
|
const entryName = this.getEntryNameFromChunk(pathData.chunk);
|
|
@@ -54,7 +30,6 @@ export class ExposeEntryNamePlugin {
|
|
|
54
30
|
return '';
|
|
55
31
|
}
|
|
56
32
|
apply(compiler) {
|
|
57
|
-
const { NormalModule: { getCompilationHooks }, } = compiler.webpack;
|
|
58
33
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
59
34
|
compilation.hooks.assetPath.tap(PLUGIN_NAME, (path, pathData) => {
|
|
60
35
|
if (path.includes('[entry]')) {
|
|
@@ -65,15 +40,6 @@ export class ExposeEntryNamePlugin {
|
|
|
65
40
|
}
|
|
66
41
|
return path;
|
|
67
42
|
});
|
|
68
|
-
getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext, module) => {
|
|
69
|
-
Object.defineProperty(loaderContext, 'entryName', {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: false,
|
|
72
|
-
get: () => {
|
|
73
|
-
return this.getEntryNameFromEntries(compilation, module);
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
43
|
});
|
|
78
44
|
}
|
|
79
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@into-mini/sfc-split-plugin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"loader",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"sort-keys": "^6.0.0",
|
|
33
33
|
"yaml": "^2.8.2",
|
|
34
34
|
"@into-mini/clsx": "^0.1.1",
|
|
35
|
-
"@into-mini/sfc-transformer": "^0.6.
|
|
35
|
+
"@into-mini/sfc-transformer": "^0.6.9"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"webpack": "^5.104.1"
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Compiler, Compilation, PathData, Module, WebpackPluginInstance } from 'webpack';
|
|
2
|
-
export declare class ExposeEntryNamePlugin implements WebpackPluginInstance {
|
|
3
|
-
getEntryNameFromEntries(compilation: Compilation, module: Module): string;
|
|
4
|
-
getEntryNameFromPathData(compilation: Compilation, pathData: PathData): string;
|
|
5
|
-
apply(compiler: Compiler): void;
|
|
6
|
-
}
|
|
@@ -1,63 +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
|
-
return name;
|
|
15
|
-
}
|
|
16
|
-
if (
|
|
17
|
-
// @ts-expect-error ------------
|
|
18
|
-
entryModule?.resource && // @ts-expect-error ------------
|
|
19
|
-
slash(entryModule?.resource) === slash(module.resource)) {
|
|
20
|
-
return name;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return '';
|
|
26
|
-
}
|
|
27
|
-
getEntryNameFromPathData(compilation, pathData) {
|
|
28
|
-
const mod = pathData.module;
|
|
29
|
-
const graph = pathData.chunkGraph;
|
|
30
|
-
if (mod && graph) {
|
|
31
|
-
const [entryModule] = graph
|
|
32
|
-
.getModuleChunks(mod)
|
|
33
|
-
.map((chunk) => [...graph.getChunkEntryModulesIterable(chunk)][0]);
|
|
34
|
-
if (entryModule) {
|
|
35
|
-
return this.getEntryNameFromEntries(compilation, entryModule);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return '';
|
|
39
|
-
}
|
|
40
|
-
apply(compiler) {
|
|
41
|
-
const { NormalModule: { getCompilationHooks }, } = compiler.webpack;
|
|
42
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
43
|
-
compilation.hooks.assetPath.tap(PLUGIN_NAME, (path, pathData) => {
|
|
44
|
-
if (path.includes('[entry]')) {
|
|
45
|
-
const entryName = this.getEntryNameFromPathData(compilation, pathData);
|
|
46
|
-
return entryName
|
|
47
|
-
? path.replaceAll('[entry]', entryName)
|
|
48
|
-
: path.replaceAll('[entry]', '[hash:8]');
|
|
49
|
-
}
|
|
50
|
-
return path;
|
|
51
|
-
});
|
|
52
|
-
getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext, module) => {
|
|
53
|
-
Object.defineProperty(loaderContext, 'entryName', {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
configurable: false,
|
|
56
|
-
get: () => {
|
|
57
|
-
return this.getEntryNameFromEntries(compilation, module);
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|