unplugin-raw 0.4.5 → 0.5.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/dist/esbuild.d.ts +4 -11
- package/dist/esbuild.js +1 -1
- package/dist/index-CbkvuMB_.d.ts +24 -0
- package/dist/index.d.ts +2 -23
- package/dist/index.js +1 -1
- package/dist/rolldown.d.ts +4 -11
- package/dist/rolldown.js +1 -1
- package/dist/rollup.d.ts +4 -11
- package/dist/rollup.js +1 -1
- package/dist/rspack.d.ts +4 -11
- package/dist/rspack.js +1 -1
- package/dist/{src-i5caNZ-U.js → src-DE-h8IJW.js} +32 -17
- package/dist/vite.d.ts +4 -11
- package/dist/vite.js +1 -1
- package/dist/webpack.d.ts +4 -11
- package/dist/webpack.js +1 -1
- package/package.json +16 -16
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import unplugin from
|
|
2
|
-
import 'unplugin';
|
|
3
|
-
import 'esbuild';
|
|
4
|
-
import 'unplugin-utils';
|
|
1
|
+
import { unplugin } from "./index-CbkvuMB_.js";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
* This entry file is for esbuild plugin. Requires esbuild >= 0.15
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
3
|
+
//#region src/esbuild.d.ts
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Esbuild plugin
|
|
@@ -23,5 +16,5 @@ import 'unplugin-utils';
|
|
|
23
16
|
* ```
|
|
24
17
|
*/
|
|
25
18
|
declare const esbuild: typeof unplugin.esbuild;
|
|
26
|
-
|
|
27
|
-
export { esbuild as
|
|
19
|
+
//#endregion
|
|
20
|
+
export { esbuild as default, esbuild as "module.exports" };
|
package/dist/esbuild.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { UnpluginInstance } from "unplugin";
|
|
2
|
+
import { FilterPattern } from "unplugin-utils";
|
|
3
|
+
import { Loader, TransformOptions } from "esbuild";
|
|
4
|
+
|
|
5
|
+
//#region src/core/options.d.ts
|
|
6
|
+
interface Options {
|
|
7
|
+
/** @default 'pre' */
|
|
8
|
+
enforce?: "pre" | "post" | undefined;
|
|
9
|
+
/** Transform */
|
|
10
|
+
transform?: {
|
|
11
|
+
/** @default [/\.[cm]?[jt]sx?$/] */
|
|
12
|
+
include?: FilterPattern;
|
|
13
|
+
/** @default [/node_modules/] */
|
|
14
|
+
exclude?: FilterPattern;
|
|
15
|
+
/** @default {} */
|
|
16
|
+
options?: TransformOptions;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/index.d.ts
|
|
21
|
+
declare const unplugin: UnpluginInstance<Options | undefined, false>;
|
|
22
|
+
declare function guessLoader(id: string): Loader;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { guessLoader, unplugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { FilterPattern } from 'unplugin-utils';
|
|
4
|
-
|
|
5
|
-
interface Options {
|
|
6
|
-
/** @default 'pre' */
|
|
7
|
-
enforce?: "pre" | "post" | undefined;
|
|
8
|
-
/** Transform */
|
|
9
|
-
transform?: {
|
|
10
|
-
/** @default [/\.[cm]?[jt]sx?$/] */
|
|
11
|
-
include?: FilterPattern
|
|
12
|
-
/** @default [/node_modules/] */
|
|
13
|
-
exclude?: FilterPattern
|
|
14
|
-
/** @default {} */
|
|
15
|
-
options?: TransformOptions
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare const unplugin: UnpluginInstance<Options | undefined, false>;
|
|
20
|
-
|
|
21
|
-
declare function guessLoader(id: string): Loader;
|
|
22
|
-
|
|
23
|
-
export { unplugin as default, guessLoader };
|
|
1
|
+
import { guessLoader, unplugin } from "./index-CbkvuMB_.js";
|
|
2
|
+
export { unplugin as default, guessLoader };
|
package/dist/index.js
CHANGED
package/dist/rolldown.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import unplugin from
|
|
2
|
-
import 'unplugin';
|
|
3
|
-
import 'esbuild';
|
|
4
|
-
import 'unplugin-utils';
|
|
1
|
+
import { unplugin } from "./index-CbkvuMB_.js";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
* This entry file is for Rolldown plugin.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
3
|
+
//#region src/rolldown.d.ts
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Rolldown plugin
|
|
@@ -23,5 +16,5 @@ import 'unplugin-utils';
|
|
|
23
16
|
* ```
|
|
24
17
|
*/
|
|
25
18
|
declare const rolldown: typeof unplugin.rolldown;
|
|
26
|
-
|
|
27
|
-
export { rolldown as
|
|
19
|
+
//#endregion
|
|
20
|
+
export { rolldown as default, rolldown as "module.exports" };
|
package/dist/rolldown.js
CHANGED
package/dist/rollup.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import unplugin from
|
|
2
|
-
import 'unplugin';
|
|
3
|
-
import 'esbuild';
|
|
4
|
-
import 'unplugin-utils';
|
|
1
|
+
import { unplugin } from "./index-CbkvuMB_.js";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
* This entry file is for Rollup plugin.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
3
|
+
//#region src/rollup.d.ts
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Rollup plugin
|
|
@@ -23,5 +16,5 @@ import 'unplugin-utils';
|
|
|
23
16
|
* ```
|
|
24
17
|
*/
|
|
25
18
|
declare const rollup: typeof unplugin.rollup;
|
|
26
|
-
|
|
27
|
-
export { rollup as
|
|
19
|
+
//#endregion
|
|
20
|
+
export { rollup as default, rollup as "module.exports" };
|
package/dist/rollup.js
CHANGED
package/dist/rspack.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import unplugin from
|
|
2
|
-
import 'unplugin';
|
|
3
|
-
import 'esbuild';
|
|
4
|
-
import 'unplugin-utils';
|
|
1
|
+
import { unplugin } from "./index-CbkvuMB_.js";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
* This entry file is for rspack plugin.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
3
|
+
//#region src/rspack.d.ts
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Rspack plugin
|
|
@@ -21,5 +14,5 @@ import 'unplugin-utils';
|
|
|
21
14
|
* ```
|
|
22
15
|
*/
|
|
23
16
|
declare const rspack: typeof unplugin.rspack;
|
|
24
|
-
|
|
25
|
-
export { rspack as
|
|
17
|
+
//#endregion
|
|
18
|
+
export { rspack as default, rspack as "module.exports" };
|
package/dist/rspack.js
CHANGED
|
@@ -25,9 +25,14 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
25
25
|
return {
|
|
26
26
|
name: "unplugin-raw",
|
|
27
27
|
enforce: options.enforce,
|
|
28
|
-
resolveId:
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
resolveId: [
|
|
29
|
+
"rollup",
|
|
30
|
+
"rolldown",
|
|
31
|
+
"vite"
|
|
32
|
+
].includes(meta.framework) ? async function(id, importer, opt) {
|
|
33
|
+
const attributeType = opt?.attributes?.type;
|
|
34
|
+
if (attributeType === "text") id += `${id.includes("?") ? "&" : "?"}raw`;
|
|
35
|
+
else if (attributeType === "bytes") id += `${id.includes("?") ? "&" : "?"}bytes`;
|
|
31
36
|
if (!rawRE.test(id)) return;
|
|
32
37
|
const file = cleanUrl(id);
|
|
33
38
|
const resolved = await this.resolve(file, importer);
|
|
@@ -38,23 +43,22 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
38
43
|
filter: { id: { include: rawRE } },
|
|
39
44
|
async handler(id) {
|
|
40
45
|
const file = cleanUrl(id);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (nativeContext?.framework === "esbuild") ({transform} = nativeContext.build.esbuild);
|
|
46
|
-
else transform = (await import("esbuild")).transform;
|
|
47
|
-
contents = (await transform(contents, {
|
|
48
|
-
loader: guessLoader(file),
|
|
49
|
-
...options.transform.options
|
|
50
|
-
})).code;
|
|
51
|
-
}
|
|
52
|
-
return `export default ${JSON.stringify(contents)}`;
|
|
46
|
+
const context = this.getNativeBuildContext?.();
|
|
47
|
+
const transform = context?.framework === "esbuild" ? context.build.esbuild.transform : void 0;
|
|
48
|
+
const contents = await transformRaw(file, transformFilter, false, options.transform.options, transform);
|
|
49
|
+
return contents;
|
|
53
50
|
}
|
|
54
51
|
},
|
|
55
52
|
esbuild: { setup(build) {
|
|
56
|
-
build.onLoad({ filter: /.*/ }, (args) => {
|
|
57
|
-
|
|
53
|
+
build.onLoad({ filter: /.*/ }, async (args) => {
|
|
54
|
+
const isBytes = args.with.type === "bytes";
|
|
55
|
+
if (args.with.type === "text" || isBytes) {
|
|
56
|
+
const contents = await transformRaw(args.path, transformFilter, isBytes, options.transform.options, build.esbuild.transform);
|
|
57
|
+
return {
|
|
58
|
+
contents,
|
|
59
|
+
loader: typeof contents === "string" ? "js" : "binary"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
58
62
|
});
|
|
59
63
|
} }
|
|
60
64
|
};
|
|
@@ -85,6 +89,17 @@ const ExtToLoader = {
|
|
|
85
89
|
function guessLoader(id) {
|
|
86
90
|
return ExtToLoader[path.extname(id).toLowerCase()] || "js";
|
|
87
91
|
}
|
|
92
|
+
async function transformRaw(file, transformFilter, isBytes, options, transform) {
|
|
93
|
+
let contents = await readFile(file, isBytes ? void 0 : "utf8");
|
|
94
|
+
if (!isBytes && transformFilter(file)) {
|
|
95
|
+
transform ||= (await import("esbuild")).transform;
|
|
96
|
+
contents = (await transform(contents, {
|
|
97
|
+
loader: guessLoader(file),
|
|
98
|
+
...options
|
|
99
|
+
})).code;
|
|
100
|
+
}
|
|
101
|
+
return isBytes ? contents : `export default ${JSON.stringify(contents)}`;
|
|
102
|
+
}
|
|
88
103
|
|
|
89
104
|
//#endregion
|
|
90
105
|
export { guessLoader, src_default };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import unplugin from
|
|
2
|
-
import 'unplugin';
|
|
3
|
-
import 'esbuild';
|
|
4
|
-
import 'unplugin-utils';
|
|
1
|
+
import { unplugin } from "./index-CbkvuMB_.js";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
* This entry file is for Vite plugin.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
3
|
+
//#region src/vite.d.ts
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Vite plugin
|
|
@@ -23,5 +16,5 @@ import 'unplugin-utils';
|
|
|
23
16
|
* ```
|
|
24
17
|
*/
|
|
25
18
|
declare const vite: typeof unplugin.vite;
|
|
26
|
-
|
|
27
|
-
export { vite as
|
|
19
|
+
//#endregion
|
|
20
|
+
export { vite as default, vite as "module.exports" };
|
package/dist/vite.js
CHANGED
package/dist/webpack.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import unplugin from
|
|
2
|
-
import 'unplugin';
|
|
3
|
-
import 'esbuild';
|
|
4
|
-
import 'unplugin-utils';
|
|
1
|
+
import { unplugin } from "./index-CbkvuMB_.js";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
* This entry file is for webpack plugin.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
3
|
+
//#region src/webpack.d.ts
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Webpack plugin
|
|
@@ -21,5 +14,5 @@ import 'unplugin-utils';
|
|
|
21
14
|
* ```
|
|
22
15
|
*/
|
|
23
16
|
declare const webpack: typeof unplugin.webpack;
|
|
24
|
-
|
|
25
|
-
export { webpack as
|
|
17
|
+
//#endregion
|
|
18
|
+
export { webpack as default, webpack as "module.exports" };
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-raw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Transform file to a default-export string.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -49,26 +49,26 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"esbuild": "^0.25.
|
|
53
|
-
"unplugin": "^2.3.
|
|
52
|
+
"esbuild": "^0.25.8",
|
|
53
|
+
"unplugin": "^2.3.5",
|
|
54
54
|
"unplugin-utils": "^0.2.4"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@sxzz/eslint-config": "^
|
|
58
|
-
"@sxzz/prettier-config": "^2.2.
|
|
59
|
-
"@types/node": "^
|
|
60
|
-
"bumpp": "^10.
|
|
61
|
-
"eslint": "^9.
|
|
62
|
-
"prettier": "^3.
|
|
63
|
-
"rollup": "^4.
|
|
64
|
-
"tsdown": "^0.
|
|
65
|
-
"tsx": "^4.
|
|
66
|
-
"typescript": "^5.
|
|
67
|
-
"vite": "^
|
|
68
|
-
"vitest": "^3.
|
|
57
|
+
"@sxzz/eslint-config": "^7.1.2",
|
|
58
|
+
"@sxzz/prettier-config": "^2.2.3",
|
|
59
|
+
"@types/node": "^24.1.0",
|
|
60
|
+
"bumpp": "^10.2.2",
|
|
61
|
+
"eslint": "^9.32.0",
|
|
62
|
+
"prettier": "^3.6.2",
|
|
63
|
+
"rollup": "^4.46.2",
|
|
64
|
+
"tsdown": "^0.13.2",
|
|
65
|
+
"tsx": "^4.20.3",
|
|
66
|
+
"typescript": "^5.9.2",
|
|
67
|
+
"vite": "^7.0.6",
|
|
68
|
+
"vitest": "^3.2.4"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
|
-
"node": ">=18.
|
|
71
|
+
"node": ">=20.18.0"
|
|
72
72
|
},
|
|
73
73
|
"prettier": "@sxzz/prettier-config",
|
|
74
74
|
"scripts": {
|