@qmuse/component-tagger-vite-plugin 0.0.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/LEGAL.md +7 -0
- package/README.md +43 -0
- package/dist/cjs/index.d.ts +37 -0
- package/dist/cjs/index.js +173 -0
- package/dist/esm/index.d.ts +37 -0
- package/dist/esm/index.js +140 -0
- package/package.json +43 -0
package/LEGAL.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Legal Disclaimer
|
|
2
|
+
|
|
3
|
+
Within this source code, the comments in Chinese shall be the original, governing version. Any comment in other languages are for reference only. In the event of any conflict between the Chinese language version comments and other language comments, the Chinese language version shall prevail.
|
|
4
|
+
|
|
5
|
+
法律免责声明
|
|
6
|
+
|
|
7
|
+
关于代码注释部分,中文注释为官方版本,其它语言注释仅做参考。中文注释可能与其它语言注释存在不一致,当中文注释与其它语言注释存在不一致时,请以中文注释为准。
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @qmuse/component-tagger-vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite 版本的 QMuse component tagger 插件,用于在开发模式下为 React JSX/TSX 代码注入组件和元素源码标记。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @qmuse/component-tagger-vite-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from 'vite';
|
|
15
|
+
import react from '@vitejs/plugin-react';
|
|
16
|
+
import componentTaggerVitePlugin from '@qmuse/component-tagger-vite-plugin';
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
plugins: [componentTaggerVitePlugin(), react()],
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
默认只在 Vite dev server 下生效。如果需要在 build 时也注入标记:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
componentTaggerVitePlugin({
|
|
27
|
+
onlyDev: false,
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 选项
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
componentTaggerVitePlugin({
|
|
35
|
+
onlyDev: true,
|
|
36
|
+
include: /src\/.*\.[jt]sx?$/,
|
|
37
|
+
exclude: /node_modules/,
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `onlyDev`: 默认 `true`,只在 `vite serve` 或 development mode 注入。
|
|
42
|
+
- `include`: 可选,额外限制需要处理的文件。
|
|
43
|
+
- `exclude`: 可选,排除不需要处理的文件。
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface LoaderOptions {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
sourceDir?: string;
|
|
4
|
+
tagComponents?: boolean;
|
|
5
|
+
tagElements?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type FilterPattern = RegExp | string | ((id: string) => boolean);
|
|
8
|
+
interface ComponentTaggerViteOptions {
|
|
9
|
+
onlyDev?: boolean;
|
|
10
|
+
include?: FilterPattern | FilterPattern[];
|
|
11
|
+
exclude?: FilterPattern | FilterPattern[];
|
|
12
|
+
loaderOptions?: LoaderOptions;
|
|
13
|
+
}
|
|
14
|
+
interface Alias {
|
|
15
|
+
find: string | RegExp;
|
|
16
|
+
replacement: string;
|
|
17
|
+
}
|
|
18
|
+
interface ResolvedViteConfig {
|
|
19
|
+
root: string;
|
|
20
|
+
command?: string;
|
|
21
|
+
mode?: string;
|
|
22
|
+
resolve?: {
|
|
23
|
+
alias?: Alias[] | Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface VitePlugin {
|
|
27
|
+
name: string;
|
|
28
|
+
enforce: 'pre';
|
|
29
|
+
configResolved(config: ResolvedViteConfig): void;
|
|
30
|
+
transform(source: string, id: string): {
|
|
31
|
+
code: string;
|
|
32
|
+
map: null;
|
|
33
|
+
} | null;
|
|
34
|
+
}
|
|
35
|
+
declare function componentTaggerVitePlugin(options?: ComponentTaggerViteOptions): VitePlugin;
|
|
36
|
+
export { componentTaggerVitePlugin };
|
|
37
|
+
export default componentTaggerVitePlugin;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
componentTaggerVitePlugin: () => componentTaggerVitePlugin,
|
|
33
|
+
default: () => src_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_component_tagger_webpack_loader = __toESM(require("@qmuse/component-tagger-webpack-loader"));
|
|
39
|
+
var DEFAULT_EXT_RE = /\.(js|ts|jsx|tsx)$/;
|
|
40
|
+
function cleanUrl(id) {
|
|
41
|
+
return id.replace(/[?#].*$/, "");
|
|
42
|
+
}
|
|
43
|
+
function normalizePath(filePath) {
|
|
44
|
+
return filePath.replace(/\\/g, "/");
|
|
45
|
+
}
|
|
46
|
+
function toArray(value) {
|
|
47
|
+
if (!value)
|
|
48
|
+
return [];
|
|
49
|
+
return Array.isArray(value) ? value : [value];
|
|
50
|
+
}
|
|
51
|
+
function matchesPattern(pattern, id) {
|
|
52
|
+
if (typeof pattern === "function")
|
|
53
|
+
return pattern(id);
|
|
54
|
+
if (typeof pattern === "string")
|
|
55
|
+
return id.includes(pattern);
|
|
56
|
+
return pattern.test(id);
|
|
57
|
+
}
|
|
58
|
+
function normalizeAliases(alias) {
|
|
59
|
+
if (!alias)
|
|
60
|
+
return [];
|
|
61
|
+
if (Array.isArray(alias))
|
|
62
|
+
return alias;
|
|
63
|
+
return Object.keys(alias).map((find) => ({
|
|
64
|
+
find,
|
|
65
|
+
replacement: alias[find]
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
function toProjectRelative(projectRoot, filePath) {
|
|
69
|
+
const normalizedRoot = normalizePath(projectRoot);
|
|
70
|
+
const normalizedPath = normalizePath(filePath);
|
|
71
|
+
if (normalizedPath === normalizedRoot)
|
|
72
|
+
return "";
|
|
73
|
+
if (normalizedPath.startsWith(`${normalizedRoot}/`)) {
|
|
74
|
+
return normalizedPath.slice(normalizedRoot.length + 1);
|
|
75
|
+
}
|
|
76
|
+
return normalizedPath.replace(/^\/+/, "");
|
|
77
|
+
}
|
|
78
|
+
function resolveAlias(request, aliases, projectRoot) {
|
|
79
|
+
for (const alias of aliases) {
|
|
80
|
+
if (typeof alias.find === "string") {
|
|
81
|
+
const { find, replacement } = alias;
|
|
82
|
+
if (request !== find && !request.startsWith(`${find}/`))
|
|
83
|
+
continue;
|
|
84
|
+
const suffix = request.slice(find.length).replace(/^\/+/, "");
|
|
85
|
+
const resolved2 = import_path.default.isAbsolute(replacement) ? import_path.default.join(replacement, suffix) : import_path.default.resolve(projectRoot, replacement, suffix);
|
|
86
|
+
return toProjectRelative(projectRoot, resolved2);
|
|
87
|
+
}
|
|
88
|
+
if (!alias.find.test(request))
|
|
89
|
+
continue;
|
|
90
|
+
const replaced = request.replace(alias.find, alias.replacement);
|
|
91
|
+
const resolved = import_path.default.isAbsolute(replaced) ? replaced : import_path.default.resolve(projectRoot, replaced);
|
|
92
|
+
return toProjectRelative(projectRoot, resolved);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function createWebpackUtils(projectRoot, aliases) {
|
|
97
|
+
return {
|
|
98
|
+
absolutify(context, request) {
|
|
99
|
+
const aliasResolved = resolveAlias(request, aliases, projectRoot);
|
|
100
|
+
if (aliasResolved)
|
|
101
|
+
return aliasResolved;
|
|
102
|
+
if (request.startsWith(".")) {
|
|
103
|
+
return toProjectRelative(projectRoot, import_path.default.resolve(projectRoot, context, request));
|
|
104
|
+
}
|
|
105
|
+
if (import_path.default.isAbsolute(request)) {
|
|
106
|
+
return toProjectRelative(projectRoot, request);
|
|
107
|
+
}
|
|
108
|
+
return request;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function createLoaderFs() {
|
|
113
|
+
return {
|
|
114
|
+
fileSystem: import_fs.default,
|
|
115
|
+
existsSync: import_fs.default.existsSync.bind(import_fs.default),
|
|
116
|
+
readFileSync: import_fs.default.readFileSync.bind(import_fs.default)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function shouldTransform(filePath, options) {
|
|
120
|
+
if (filePath.includes("node_modules"))
|
|
121
|
+
return false;
|
|
122
|
+
if (!DEFAULT_EXT_RE.test(filePath))
|
|
123
|
+
return false;
|
|
124
|
+
const include = toArray(options.include);
|
|
125
|
+
if (include.length && !include.some((pattern) => matchesPattern(pattern, filePath))) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return !toArray(options.exclude).some((pattern) => matchesPattern(pattern, filePath));
|
|
129
|
+
}
|
|
130
|
+
function componentTaggerVitePlugin(options = {}) {
|
|
131
|
+
let projectRoot = process.cwd();
|
|
132
|
+
let aliases = [];
|
|
133
|
+
let isDev = process.env.NODE_ENV === "development";
|
|
134
|
+
return {
|
|
135
|
+
name: "qmuse-component-tagger-vite-plugin",
|
|
136
|
+
enforce: "pre",
|
|
137
|
+
configResolved(config) {
|
|
138
|
+
var _a;
|
|
139
|
+
projectRoot = config.root || process.cwd();
|
|
140
|
+
aliases = normalizeAliases((_a = config.resolve) == null ? void 0 : _a.alias);
|
|
141
|
+
isDev = config.command === "serve" || config.mode === "development" || process.env.NODE_ENV === "development";
|
|
142
|
+
},
|
|
143
|
+
transform(source, id) {
|
|
144
|
+
if (options.onlyDev !== false && !isDev)
|
|
145
|
+
return null;
|
|
146
|
+
if (id.includes("\0"))
|
|
147
|
+
return null;
|
|
148
|
+
const filePath = cleanUrl(id);
|
|
149
|
+
if (!shouldTransform(filePath, options))
|
|
150
|
+
return null;
|
|
151
|
+
const resourcePath = import_path.default.isAbsolute(filePath) ? filePath : import_path.default.resolve(projectRoot, filePath);
|
|
152
|
+
const loaderContext = {
|
|
153
|
+
getOptions: () => options.loaderOptions || {},
|
|
154
|
+
resourcePath,
|
|
155
|
+
rootContext: projectRoot,
|
|
156
|
+
fs: createLoaderFs(),
|
|
157
|
+
utils: createWebpackUtils(projectRoot, aliases)
|
|
158
|
+
};
|
|
159
|
+
const code = import_component_tagger_webpack_loader.default.call(loaderContext, source);
|
|
160
|
+
if (!code || code === source)
|
|
161
|
+
return null;
|
|
162
|
+
return {
|
|
163
|
+
code,
|
|
164
|
+
map: null
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
var src_default = componentTaggerVitePlugin;
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
componentTaggerVitePlugin
|
|
173
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface LoaderOptions {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
sourceDir?: string;
|
|
4
|
+
tagComponents?: boolean;
|
|
5
|
+
tagElements?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type FilterPattern = RegExp | string | ((id: string) => boolean);
|
|
8
|
+
interface ComponentTaggerViteOptions {
|
|
9
|
+
onlyDev?: boolean;
|
|
10
|
+
include?: FilterPattern | FilterPattern[];
|
|
11
|
+
exclude?: FilterPattern | FilterPattern[];
|
|
12
|
+
loaderOptions?: LoaderOptions;
|
|
13
|
+
}
|
|
14
|
+
interface Alias {
|
|
15
|
+
find: string | RegExp;
|
|
16
|
+
replacement: string;
|
|
17
|
+
}
|
|
18
|
+
interface ResolvedViteConfig {
|
|
19
|
+
root: string;
|
|
20
|
+
command?: string;
|
|
21
|
+
mode?: string;
|
|
22
|
+
resolve?: {
|
|
23
|
+
alias?: Alias[] | Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface VitePlugin {
|
|
27
|
+
name: string;
|
|
28
|
+
enforce: 'pre';
|
|
29
|
+
configResolved(config: ResolvedViteConfig): void;
|
|
30
|
+
transform(source: string, id: string): {
|
|
31
|
+
code: string;
|
|
32
|
+
map: null;
|
|
33
|
+
} | null;
|
|
34
|
+
}
|
|
35
|
+
declare function componentTaggerVitePlugin(options?: ComponentTaggerViteOptions): VitePlugin;
|
|
36
|
+
export { componentTaggerVitePlugin };
|
|
37
|
+
export default componentTaggerVitePlugin;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import componentTaggerLoader from '@qmuse/component-tagger-webpack-loader';
|
|
5
|
+
var DEFAULT_EXT_RE = /\.(js|ts|jsx|tsx)$/;
|
|
6
|
+
function cleanUrl(id) {
|
|
7
|
+
return id.replace(/[?#].*$/, '');
|
|
8
|
+
}
|
|
9
|
+
function normalizePath(filePath) {
|
|
10
|
+
return filePath.replace(/\\/g, '/');
|
|
11
|
+
}
|
|
12
|
+
function toArray(value) {
|
|
13
|
+
if (!value) return [];
|
|
14
|
+
return Array.isArray(value) ? value : [value];
|
|
15
|
+
}
|
|
16
|
+
function matchesPattern(pattern, id) {
|
|
17
|
+
if (typeof pattern === 'function') return pattern(id);
|
|
18
|
+
if (typeof pattern === 'string') return id.includes(pattern);
|
|
19
|
+
return pattern.test(id);
|
|
20
|
+
}
|
|
21
|
+
function normalizeAliases(alias) {
|
|
22
|
+
if (!alias) return [];
|
|
23
|
+
if (Array.isArray(alias)) return alias;
|
|
24
|
+
return Object.keys(alias).map(function (find) {
|
|
25
|
+
return {
|
|
26
|
+
find: find,
|
|
27
|
+
replacement: alias[find]
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function toProjectRelative(projectRoot, filePath) {
|
|
32
|
+
var normalizedRoot = normalizePath(projectRoot);
|
|
33
|
+
var normalizedPath = normalizePath(filePath);
|
|
34
|
+
if (normalizedPath === normalizedRoot) return '';
|
|
35
|
+
if (normalizedPath.startsWith("".concat(normalizedRoot, "/"))) {
|
|
36
|
+
return normalizedPath.slice(normalizedRoot.length + 1);
|
|
37
|
+
}
|
|
38
|
+
return normalizedPath.replace(/^\/+/, '');
|
|
39
|
+
}
|
|
40
|
+
function resolveAlias(request, aliases, projectRoot) {
|
|
41
|
+
var _iterator = _createForOfIteratorHelper(aliases),
|
|
42
|
+
_step;
|
|
43
|
+
try {
|
|
44
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
45
|
+
var alias = _step.value;
|
|
46
|
+
if (typeof alias.find === 'string') {
|
|
47
|
+
var find = alias.find,
|
|
48
|
+
replacement = alias.replacement;
|
|
49
|
+
if (request !== find && !request.startsWith("".concat(find, "/"))) continue;
|
|
50
|
+
var suffix = request.slice(find.length).replace(/^\/+/, '');
|
|
51
|
+
var _resolved = path.isAbsolute(replacement) ? path.join(replacement, suffix) : path.resolve(projectRoot, replacement, suffix);
|
|
52
|
+
return toProjectRelative(projectRoot, _resolved);
|
|
53
|
+
}
|
|
54
|
+
if (!alias.find.test(request)) continue;
|
|
55
|
+
var replaced = request.replace(alias.find, alias.replacement);
|
|
56
|
+
var resolved = path.isAbsolute(replaced) ? replaced : path.resolve(projectRoot, replaced);
|
|
57
|
+
return toProjectRelative(projectRoot, resolved);
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
_iterator.e(err);
|
|
61
|
+
} finally {
|
|
62
|
+
_iterator.f();
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function createWebpackUtils(projectRoot, aliases) {
|
|
67
|
+
return {
|
|
68
|
+
absolutify: function absolutify(context, request) {
|
|
69
|
+
var aliasResolved = resolveAlias(request, aliases, projectRoot);
|
|
70
|
+
if (aliasResolved) return aliasResolved;
|
|
71
|
+
if (request.startsWith('.')) {
|
|
72
|
+
return toProjectRelative(projectRoot, path.resolve(projectRoot, context, request));
|
|
73
|
+
}
|
|
74
|
+
if (path.isAbsolute(request)) {
|
|
75
|
+
return toProjectRelative(projectRoot, request);
|
|
76
|
+
}
|
|
77
|
+
return request;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function createLoaderFs() {
|
|
82
|
+
return {
|
|
83
|
+
fileSystem: fs,
|
|
84
|
+
existsSync: fs.existsSync.bind(fs),
|
|
85
|
+
readFileSync: fs.readFileSync.bind(fs)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function shouldTransform(filePath, options) {
|
|
89
|
+
if (filePath.includes('node_modules')) return false;
|
|
90
|
+
if (!DEFAULT_EXT_RE.test(filePath)) return false;
|
|
91
|
+
var include = toArray(options.include);
|
|
92
|
+
if (include.length && !include.some(function (pattern) {
|
|
93
|
+
return matchesPattern(pattern, filePath);
|
|
94
|
+
})) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return !toArray(options.exclude).some(function (pattern) {
|
|
98
|
+
return matchesPattern(pattern, filePath);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function componentTaggerVitePlugin() {
|
|
102
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
103
|
+
var projectRoot = process.cwd();
|
|
104
|
+
var aliases = [];
|
|
105
|
+
var isDev = process.env.NODE_ENV === 'development';
|
|
106
|
+
return {
|
|
107
|
+
name: 'qmuse-component-tagger-vite-plugin',
|
|
108
|
+
enforce: 'pre',
|
|
109
|
+
configResolved: function configResolved(config) {
|
|
110
|
+
var _config$resolve;
|
|
111
|
+
projectRoot = config.root || process.cwd();
|
|
112
|
+
aliases = normalizeAliases((_config$resolve = config.resolve) === null || _config$resolve === void 0 ? void 0 : _config$resolve.alias);
|
|
113
|
+
isDev = config.command === 'serve' || config.mode === 'development' || process.env.NODE_ENV === 'development';
|
|
114
|
+
},
|
|
115
|
+
transform: function transform(source, id) {
|
|
116
|
+
if (options.onlyDev !== false && !isDev) return null;
|
|
117
|
+
if (id.includes('\0')) return null;
|
|
118
|
+
var filePath = cleanUrl(id);
|
|
119
|
+
if (!shouldTransform(filePath, options)) return null;
|
|
120
|
+
var resourcePath = path.isAbsolute(filePath) ? filePath : path.resolve(projectRoot, filePath);
|
|
121
|
+
var loaderContext = {
|
|
122
|
+
getOptions: function getOptions() {
|
|
123
|
+
return options.loaderOptions || {};
|
|
124
|
+
},
|
|
125
|
+
resourcePath: resourcePath,
|
|
126
|
+
rootContext: projectRoot,
|
|
127
|
+
fs: createLoaderFs(),
|
|
128
|
+
utils: createWebpackUtils(projectRoot, aliases)
|
|
129
|
+
};
|
|
130
|
+
var code = componentTaggerLoader.call(loaderContext, source);
|
|
131
|
+
if (!code || code === source) return null;
|
|
132
|
+
return {
|
|
133
|
+
code: code,
|
|
134
|
+
map: null
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export { componentTaggerVitePlugin };
|
|
140
|
+
export default componentTaggerVitePlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qmuse/component-tagger-vite-plugin",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "component tagger vite plugin",
|
|
5
|
+
"author": "dyxuan",
|
|
6
|
+
"main": "dist/cjs/index.js",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"typings": "dist/esm/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"LEGAL.md",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "father build",
|
|
16
|
+
"build:watch": "father build --watch",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@babel/runtime": "^7.18.0",
|
|
21
|
+
"@qmuse/component-tagger-webpack-loader": "^0.0.2"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@babel/plugin-transform-modules-commonjs": "^7.28.6",
|
|
25
|
+
"@types/node": "^20.11.30",
|
|
26
|
+
"father": "^4.6.18",
|
|
27
|
+
"prettier": "^3.4.2"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"vite": ">=4.0.0"
|
|
31
|
+
},
|
|
32
|
+
"engines": {},
|
|
33
|
+
"ci": {
|
|
34
|
+
"type": "aci"
|
|
35
|
+
},
|
|
36
|
+
"libType": "UTIL",
|
|
37
|
+
"tnpm": {
|
|
38
|
+
"mode": "npm"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"registry": "https://registry.npmjs.org"
|
|
42
|
+
}
|
|
43
|
+
}
|