@into-mini/sfc-split-plugin 0.5.7 → 0.5.9
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.d.mts +1 -1
- package/dist/index.mjs +17 -17
- package/dist/loader/{fake-vue-loader.d.mts → entry-loader.d.mts} +1 -1
- package/dist/loader/{fake-vue-loader.mjs → entry-loader.mjs} +4 -21
- package/package.json +3 -3
- package/dist/plugin/sfc-split.d.mts +0 -18
- package/dist/plugin/sfc-split.mjs +0 -74
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Options } from './plugin/sfc-split.mts';
|
|
2
1
|
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import type { Options } from '@into-mini/sfc-transformer/src/transformer.mts';
|
|
3
3
|
export declare const COMPONENT_ROOT = "as-components";
|
|
4
4
|
export declare class SfcSplitPlugin implements WebpackPluginInstance {
|
|
5
5
|
#private;
|
package/dist/index.mjs
CHANGED
|
@@ -19,19 +19,10 @@ export class SfcSplitPlugin {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
#applyLoader(compiler) {
|
|
22
|
-
compiler.options.module.rules.push(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// {
|
|
27
|
-
// loader: reach('./loader/fake-vue-loader.mts'),
|
|
28
|
-
// options: {
|
|
29
|
-
// componentRoot: COMPONENT_ROOT,
|
|
30
|
-
// },
|
|
31
|
-
// },
|
|
32
|
-
// ],
|
|
33
|
-
// },
|
|
34
|
-
{
|
|
22
|
+
compiler.options.module.rules.push({
|
|
23
|
+
test: /\.vue$/,
|
|
24
|
+
use: [],
|
|
25
|
+
}, {
|
|
35
26
|
test: /\.vue$/,
|
|
36
27
|
issuer: /\.vue$/,
|
|
37
28
|
resourceQuery: /type=script/,
|
|
@@ -43,7 +34,7 @@ export class SfcSplitPlugin {
|
|
|
43
34
|
resourceQuery: /type=template/,
|
|
44
35
|
type: 'asset/resource',
|
|
45
36
|
generator: {
|
|
46
|
-
filename: '[
|
|
37
|
+
filename: '[entry].wxml',
|
|
47
38
|
},
|
|
48
39
|
use: [
|
|
49
40
|
{
|
|
@@ -68,9 +59,19 @@ export class SfcSplitPlugin {
|
|
|
68
59
|
resourceQuery: [/type=config&lang=json/],
|
|
69
60
|
type: 'asset/resource',
|
|
70
61
|
generator: {
|
|
71
|
-
filename: '[
|
|
62
|
+
filename: '[entry].json',
|
|
72
63
|
},
|
|
73
|
-
|
|
64
|
+
use: [
|
|
65
|
+
{
|
|
66
|
+
loader: reach('@into-mini/sfc-split-plugin/dist/loader/entry-loader.mjs'),
|
|
67
|
+
options: {
|
|
68
|
+
componentRoot: COMPONENT_ROOT,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
loader: theLoader,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
74
75
|
}, {
|
|
75
76
|
test: /\.vue$/,
|
|
76
77
|
resourceQuery: { not: /type=/ },
|
|
@@ -89,7 +90,6 @@ export class SfcSplitPlugin {
|
|
|
89
90
|
if (type) {
|
|
90
91
|
new AddWxsPlugin().apply(compiler);
|
|
91
92
|
new MinaRuntimeWebpackPlugin().apply(compiler);
|
|
92
|
-
// new SfcSplitPluginBase({ tagMatcher, preserveTap }).apply(compiler);
|
|
93
93
|
new ExposeEntryNamePlugin().apply(compiler);
|
|
94
94
|
new EntryRenamePlugin({
|
|
95
95
|
issuer: /\.vue$/,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { LoaderContext } from 'webpack';
|
|
2
|
-
export default function loader(this: LoaderContext<Record<string, any>>, source: string
|
|
2
|
+
export default function loader(this: LoaderContext<Record<string, any>>, source: string): void;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import {
|
|
4
|
+
import { relative, resolve } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { toJSONString } from '@into-mini/sfc-transformer/src/utils.mts';
|
|
7
6
|
import slash from 'slash';
|
|
8
7
|
function createShortHash(input) {
|
|
9
8
|
return createHash('sha256').update(input).digest('hex').slice(0, 8);
|
|
@@ -52,22 +51,13 @@ function handleImport({ toThis, addSmartEntry, componentRoot, context, rootConte
|
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
export default function loader(source
|
|
54
|
+
export default function loader(source) {
|
|
56
55
|
this.cacheable();
|
|
57
56
|
const callback = this.async();
|
|
58
57
|
const { componentRoot } = this.getOptions();
|
|
59
58
|
const { entryName: thisEntryName } = this;
|
|
60
|
-
const
|
|
61
|
-
const { paths, config, script } = this.processSfcFile({
|
|
62
|
-
source,
|
|
63
|
-
resourcePath,
|
|
64
|
-
});
|
|
59
|
+
const config = JSON.parse(source);
|
|
65
60
|
const { rootContext, context } = this;
|
|
66
|
-
for (const path of paths) {
|
|
67
|
-
const filePath = join(rootContext, path);
|
|
68
|
-
this.addDependency(filePath);
|
|
69
|
-
this.addMissingDependency(filePath);
|
|
70
|
-
}
|
|
71
61
|
function toThis(entryName) {
|
|
72
62
|
return slash(relative(`/${thisEntryName}/..`, `/${entryName}`));
|
|
73
63
|
}
|
|
@@ -107,12 +97,5 @@ export default function loader(source, map, meta) {
|
|
|
107
97
|
},
|
|
108
98
|
});
|
|
109
99
|
}
|
|
110
|
-
|
|
111
|
-
...paths
|
|
112
|
-
.map((path) => relative(`${resourcePath}/..`, path))
|
|
113
|
-
.map((path) => `import "./${path}";`),
|
|
114
|
-
script,
|
|
115
|
-
].join('\n');
|
|
116
|
-
this.emitFile(`${thisEntryName}.json`, toJSONString(config));
|
|
117
|
-
callback(null, file, map, meta);
|
|
100
|
+
callback(null, JSON.stringify(config));
|
|
118
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@into-mini/sfc-split-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"loader",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"webpack-virtual-modules": "^0.6.2",
|
|
34
34
|
"yaml": "^2.8.2",
|
|
35
35
|
"@into-mini/clsx": "^0.1.0",
|
|
36
|
-
"@into-mini/sfc-split-loader": "^0.2.6",
|
|
37
36
|
"@into-mini/sfc-transformer": "^0.6.1",
|
|
38
|
-
"@into-mini/wxml-loader": "^0.0.0"
|
|
37
|
+
"@into-mini/wxml-loader": "^0.0.0",
|
|
38
|
+
"@into-mini/sfc-split-loader": "^0.2.6"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"webpack": "^5.104.0"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
|
2
|
-
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
3
|
-
export type Options = {
|
|
4
|
-
type?: boolean;
|
|
5
|
-
tagMatcher?: (tag: string) => {
|
|
6
|
-
tag: string;
|
|
7
|
-
path: string;
|
|
8
|
-
};
|
|
9
|
-
preserveTap?: (tag: string) => boolean;
|
|
10
|
-
};
|
|
11
|
-
export declare class SfcSplitPluginBase extends VirtualModulesPlugin implements WebpackPluginInstance {
|
|
12
|
-
#private;
|
|
13
|
-
PLUGIN_NAME: string;
|
|
14
|
-
tagMatcher: Options['tagMatcher'];
|
|
15
|
-
preserveTap: Options['preserveTap'];
|
|
16
|
-
constructor({ tagMatcher, preserveTap }: Options);
|
|
17
|
-
apply(compiler: Compiler): void;
|
|
18
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { parse } from '@into-mini/sfc-transformer/src/index.mjs';
|
|
5
|
-
import slash from 'slash';
|
|
6
|
-
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
|
7
|
-
export class SfcSplitPluginBase extends VirtualModulesPlugin {
|
|
8
|
-
PLUGIN_NAME = 'SfcSplitPluginBase';
|
|
9
|
-
tagMatcher;
|
|
10
|
-
preserveTap;
|
|
11
|
-
constructor({ tagMatcher, preserveTap }) {
|
|
12
|
-
super();
|
|
13
|
-
this.tagMatcher = tagMatcher;
|
|
14
|
-
this.preserveTap = preserveTap;
|
|
15
|
-
}
|
|
16
|
-
apply(compiler) {
|
|
17
|
-
this.#expose(compiler);
|
|
18
|
-
super.apply(compiler);
|
|
19
|
-
}
|
|
20
|
-
#expose(compiler) {
|
|
21
|
-
const { PLUGIN_NAME } = this;
|
|
22
|
-
const { NormalModule: { getCompilationHooks }, } = compiler.webpack;
|
|
23
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
24
|
-
getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext) => {
|
|
25
|
-
Object.defineProperty(loaderContext, 'processSfcFile', {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: false,
|
|
28
|
-
value: (options) => {
|
|
29
|
-
return this.#processSfcFile(options);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
#inject(resourcePath, ext, content) {
|
|
36
|
-
const src = path.resolve(resourcePath.replace(/\.vue$/, ext));
|
|
37
|
-
super.writeModule(src, content);
|
|
38
|
-
return src;
|
|
39
|
-
}
|
|
40
|
-
#injectStyle(resourcePath, id, style) {
|
|
41
|
-
return this.#inject(resourcePath, `-${id}.${style.lang ?? 'css'}`, style.content);
|
|
42
|
-
}
|
|
43
|
-
#injectStyles(resourcePath, styles) {
|
|
44
|
-
const io = [];
|
|
45
|
-
const css = styles?.length > 0 ? styles : [];
|
|
46
|
-
css.forEach((style, idx) => {
|
|
47
|
-
if (style?.content) {
|
|
48
|
-
const src = this.#injectStyle(resourcePath, idx, style);
|
|
49
|
-
io.push(src);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return io;
|
|
53
|
-
}
|
|
54
|
-
#injectTemplate(resourcePath, tpl) {
|
|
55
|
-
return this.#inject(resourcePath, '.wxml', tpl);
|
|
56
|
-
}
|
|
57
|
-
#processSfcFile({ source, resourcePath }) {
|
|
58
|
-
const { tagMatcher, preserveTap } = this;
|
|
59
|
-
const { tpl, styles, code, config } = parse(source, {
|
|
60
|
-
tagMatcher,
|
|
61
|
-
preserveTap,
|
|
62
|
-
});
|
|
63
|
-
const paths = [];
|
|
64
|
-
const wxml = this.#injectTemplate(resourcePath, tpl);
|
|
65
|
-
paths.push(wxml);
|
|
66
|
-
const css = this.#injectStyles(resourcePath, styles);
|
|
67
|
-
paths.push(...css);
|
|
68
|
-
return {
|
|
69
|
-
config,
|
|
70
|
-
paths: paths.map((src) => slash(src)),
|
|
71
|
-
script: code,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|