unplugin-raw 0.6.2 → 0.6.4
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/README.md +2 -0
- package/dist/api.d.mts +9 -0
- package/dist/api.mjs +3 -0
- package/dist/{esbuild.d.ts → esbuild.d.mts} +2 -2
- package/dist/{esbuild.js → esbuild.mjs} +7 -2
- package/dist/{index-BMXQlGcW.d.ts → index.d.mts} +2 -2
- package/dist/{src-C8tBe-z3.js → index.mjs} +11 -8
- package/dist/{options-DupdgTT1.d.ts → options-DSAzFv_P.d.mts} +1 -1
- package/dist/{rolldown.d.ts → rolldown.d.mts} +2 -2
- package/dist/{rolldown.js → rolldown.mjs} +7 -2
- package/dist/{rollup.d.ts → rollup.d.mts} +2 -2
- package/dist/{rollup.js → rollup.mjs} +7 -2
- package/dist/{rspack.d.ts → rspack.d.mts} +2 -2
- package/dist/{rspack.js → rspack.mjs} +7 -2
- package/dist/{options-BTT0I76V.js → transform-DF3vB7QY.mjs} +22 -22
- package/dist/{vite.d.ts → vite.d.mts} +2 -2
- package/dist/{vite.js → vite.mjs} +7 -2
- package/dist/{webpack.d.ts → webpack.d.mts} +2 -2
- package/dist/{webpack.js → webpack.mjs} +7 -2
- package/package.json +45 -46
- package/dist/api.d.ts +0 -9
- package/dist/api.js +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -4
package/README.md
CHANGED
|
@@ -98,10 +98,12 @@ export interface Options {
|
|
|
98
98
|
```ts
|
|
99
99
|
import text from './js.js?raw'
|
|
100
100
|
import text2 from './jsx.jsx?raw'
|
|
101
|
+
import bytes from './png.png?bytes'
|
|
101
102
|
import text3 from './ts.ts?raw'
|
|
102
103
|
|
|
103
104
|
// Import attributes (Rolldown doesn't support this syntax)
|
|
104
105
|
import text4 from './with.js' with { type: 'text' }
|
|
106
|
+
import bytes2 from './with.png' with { type: 'bytes' }
|
|
105
107
|
```
|
|
106
108
|
|
|
107
109
|
## Sponsors
|
package/dist/api.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { i as resolveOptions, n as OptionsResolved, r as TransformOptions, t as Options } from "./options-DSAzFv_P.mjs";
|
|
2
|
+
import * as esbuild0 from "esbuild";
|
|
3
|
+
import { TransformOptions as TransformOptions$1 } from "esbuild";
|
|
4
|
+
import { Buffer } from "node:buffer";
|
|
5
|
+
|
|
6
|
+
//#region src/core/transform.d.ts
|
|
7
|
+
declare function transformRaw(file: string, type: "text" | "bytes", transform?: typeof esbuild0.transform, transformFilter?: (id: string | unknown) => boolean, options?: TransformOptions$1): Promise<string | Buffer>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type Options, type OptionsResolved, type TransformOptions, resolveOptions, transformRaw };
|
package/dist/api.mjs
ADDED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import "./transform-DF3vB7QY.mjs";
|
|
2
|
+
import src_default from "./index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/esbuild.ts
|
|
5
5
|
/**
|
|
6
|
+
* This entry file is for esbuild plugin. Requires esbuild >= 0.15
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
6
11
|
* Esbuild plugin
|
|
7
12
|
*
|
|
8
13
|
* @example
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Options } from "./options-
|
|
1
|
+
import { t as Options } from "./options-DSAzFv_P.mjs";
|
|
2
2
|
import { UnpluginInstance } from "unplugin";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
declare const unplugin: UnpluginInstance<Options | undefined, false>;
|
|
6
6
|
//#endregion
|
|
7
|
-
export { unplugin };
|
|
7
|
+
export { unplugin as default };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { resolveOptions, transformRaw } from "./
|
|
1
|
+
import { n as resolveOptions, t as transformRaw } from "./transform-DF3vB7QY.mjs";
|
|
2
2
|
import { createUnplugin } from "unplugin";
|
|
3
3
|
import { createFilter } from "unplugin-utils";
|
|
4
4
|
|
|
5
5
|
//#region src/index.ts
|
|
6
6
|
const rawRE = /[&?]raw(?:&|$)/;
|
|
7
|
+
const bytesRE = /[&?]bytes(?:&|$)/;
|
|
7
8
|
const postfixRE = /[#?].*$/s;
|
|
8
9
|
function cleanUrl(url) {
|
|
9
10
|
return url.replace(postfixRE, "");
|
|
@@ -22,26 +23,28 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
22
23
|
const attributeType = options$1?.attributes?.type;
|
|
23
24
|
if (attributeType === "text") id += `${id.includes("?") ? "&" : "?"}raw`;
|
|
24
25
|
else if (attributeType === "bytes") id += `${id.includes("?") ? "&" : "?"}bytes`;
|
|
25
|
-
if (!rawRE.test(id)) return;
|
|
26
|
+
else if (!rawRE.test(id) && !bytesRE.test(id)) return;
|
|
26
27
|
const file = cleanUrl(id);
|
|
27
28
|
const resolved = await this.resolve(file, importer);
|
|
28
29
|
if (!resolved) return;
|
|
29
30
|
return id.replace(file, resolved.id);
|
|
30
31
|
} : void 0,
|
|
31
32
|
load: {
|
|
32
|
-
filter: { id: { include: rawRE } },
|
|
33
|
+
filter: { id: { include: [rawRE, bytesRE] } },
|
|
33
34
|
async handler(id) {
|
|
34
35
|
const file = cleanUrl(id);
|
|
35
36
|
const context = this.getNativeBuildContext?.();
|
|
36
37
|
const transform = context?.framework === "esbuild" ? context.build.esbuild.transform : void 0;
|
|
37
|
-
|
|
38
|
+
let contents = await transformRaw(file, bytesRE.test(id) ? "bytes" : "text", transform, transformFilter, options.transform ? options.transform.options : void 0);
|
|
39
|
+
if (typeof contents !== "string") contents = `export default new Uint8Array([${contents.join(", ")}])`;
|
|
40
|
+
return contents;
|
|
38
41
|
}
|
|
39
42
|
},
|
|
40
43
|
esbuild: { setup(build) {
|
|
41
44
|
build.onLoad({ filter: /.*/ }, async (args) => {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const contents = await transformRaw(args.path,
|
|
45
|
+
const type = args.with.type;
|
|
46
|
+
if (type === "text" || type === "bytes") {
|
|
47
|
+
const contents = await transformRaw(args.path, type, build.esbuild.transform, transformFilter, options.transform ? options.transform.options : void 0);
|
|
45
48
|
return {
|
|
46
49
|
contents,
|
|
47
50
|
loader: typeof contents === "string" ? "js" : "binary"
|
|
@@ -54,4 +57,4 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
54
57
|
var src_default = unplugin;
|
|
55
58
|
|
|
56
59
|
//#endregion
|
|
57
|
-
export { src_default };
|
|
60
|
+
export { src_default as default };
|
|
@@ -24,4 +24,4 @@ type OptionsResolved = Pick<Options, "enforce"> & {
|
|
|
24
24
|
};
|
|
25
25
|
declare function resolveOptions(options: Options): OptionsResolved;
|
|
26
26
|
//#endregion
|
|
27
|
-
export {
|
|
27
|
+
export { resolveOptions as i, OptionsResolved as n, TransformOptions$1 as r, Options as t };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import "./transform-DF3vB7QY.mjs";
|
|
2
|
+
import src_default from "./index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/rolldown.ts
|
|
5
5
|
/**
|
|
6
|
+
* This entry file is for Rolldown plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
6
11
|
* Rolldown plugin
|
|
7
12
|
*
|
|
8
13
|
* @example
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import "./transform-DF3vB7QY.mjs";
|
|
2
|
+
import src_default from "./index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/rollup.ts
|
|
5
5
|
/**
|
|
6
|
+
* This entry file is for Rollup plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
6
11
|
* Rollup plugin
|
|
7
12
|
*
|
|
8
13
|
* @example
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import "./transform-DF3vB7QY.mjs";
|
|
2
|
+
import src_default from "./index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/rspack.ts
|
|
5
5
|
/**
|
|
6
|
+
* This entry file is for rspack plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
6
11
|
* Rspack plugin
|
|
7
12
|
*
|
|
8
13
|
* @example
|
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
+
//#region src/core/options.ts
|
|
5
|
+
function resolveOptions(options) {
|
|
6
|
+
let { transform = false } = options;
|
|
7
|
+
if (transform === true) transform = {};
|
|
8
|
+
return {
|
|
9
|
+
...options,
|
|
10
|
+
enforce: "enforce" in options ? options.enforce : "pre",
|
|
11
|
+
transform: transform ? {
|
|
12
|
+
...transform,
|
|
13
|
+
include: transform.include || [/\.[cm]?[jt]sx?$/],
|
|
14
|
+
exclude: transform.exclude || [/node_modules/],
|
|
15
|
+
options: transform.options || {}
|
|
16
|
+
} : false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
4
21
|
//#region src/core/transform.ts
|
|
5
|
-
async function transformRaw(file,
|
|
6
|
-
let contents = await readFile(file,
|
|
7
|
-
if (
|
|
22
|
+
async function transformRaw(file, type, transform, transformFilter, options) {
|
|
23
|
+
let contents = await readFile(file, type === "text" ? "utf8" : void 0);
|
|
24
|
+
if (type === "text" && transformFilter?.(file)) {
|
|
8
25
|
transform ||= (await import("esbuild")).transform;
|
|
9
26
|
contents = (await transform(contents, {
|
|
10
27
|
loader: guessLoader(file),
|
|
11
28
|
...options
|
|
12
29
|
})).code;
|
|
13
30
|
}
|
|
14
|
-
return
|
|
31
|
+
return type === "bytes" ? contents : `export default ${JSON.stringify(contents)}`;
|
|
15
32
|
}
|
|
16
33
|
const ExtToLoader = {
|
|
17
34
|
".js": "js",
|
|
@@ -35,21 +52,4 @@ function guessLoader(id) {
|
|
|
35
52
|
}
|
|
36
53
|
|
|
37
54
|
//#endregion
|
|
38
|
-
|
|
39
|
-
function resolveOptions(options) {
|
|
40
|
-
let { transform = false } = options;
|
|
41
|
-
if (transform === true) transform = {};
|
|
42
|
-
return {
|
|
43
|
-
...options,
|
|
44
|
-
enforce: "enforce" in options ? options.enforce : "pre",
|
|
45
|
-
transform: transform ? {
|
|
46
|
-
...transform,
|
|
47
|
-
include: transform.include || [/\.[cm]?[jt]sx?$/],
|
|
48
|
-
exclude: transform.exclude || [/node_modules/],
|
|
49
|
-
options: transform.options || {}
|
|
50
|
-
} : false
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
export { resolveOptions, transformRaw };
|
|
55
|
+
export { resolveOptions as n, transformRaw as t };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import "./transform-DF3vB7QY.mjs";
|
|
2
|
+
import src_default from "./index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/vite.ts
|
|
5
5
|
/**
|
|
6
|
+
* This entry file is for Vite plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
6
11
|
* Vite plugin
|
|
7
12
|
*
|
|
8
13
|
* @example
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import "./transform-DF3vB7QY.mjs";
|
|
2
|
+
import src_default from "./index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/webpack.ts
|
|
5
5
|
/**
|
|
6
|
+
* This entry file is for webpack plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
6
11
|
* Webpack plugin
|
|
7
12
|
*
|
|
8
13
|
* @example
|
package/package.json
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-raw",
|
|
3
|
-
"version": "0.6.2",
|
|
4
|
-
"description": "Transform file to a default-export string.",
|
|
5
3
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"vite",
|
|
10
|
-
"esbuild",
|
|
11
|
-
"webpack"
|
|
12
|
-
],
|
|
4
|
+
"version": "0.6.4",
|
|
5
|
+
"description": "Transform file to a default-export string.",
|
|
6
|
+
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
13
7
|
"license": "MIT",
|
|
8
|
+
"funding": "https://github.com/sponsors/sxzz",
|
|
14
9
|
"homepage": "https://github.com/unplugin/unplugin-raw#readme",
|
|
15
|
-
"bugs": {
|
|
16
|
-
"url": "https://github.com/unplugin/unplugin-raw/issues"
|
|
17
|
-
},
|
|
18
10
|
"repository": {
|
|
19
11
|
"type": "git",
|
|
20
12
|
"url": "git+https://github.com/unplugin/unplugin-raw.git"
|
|
21
13
|
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/unplugin/unplugin-raw/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"unplugin",
|
|
19
|
+
"rollup",
|
|
20
|
+
"vite",
|
|
21
|
+
"esbuild",
|
|
22
|
+
"webpack"
|
|
26
23
|
],
|
|
27
|
-
"main": "./dist/index.js",
|
|
28
|
-
"module": "./dist/index.js",
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
24
|
"exports": {
|
|
31
|
-
".": "./dist/index.
|
|
32
|
-
"./api": "./dist/api.
|
|
33
|
-
"./esbuild": "./dist/esbuild.
|
|
34
|
-
"./rolldown": "./dist/rolldown.
|
|
35
|
-
"./rollup": "./dist/rollup.
|
|
36
|
-
"./rspack": "./dist/rspack.
|
|
37
|
-
"./vite": "./dist/vite.
|
|
38
|
-
"./webpack": "./dist/webpack.
|
|
25
|
+
".": "./dist/index.mjs",
|
|
26
|
+
"./api": "./dist/api.mjs",
|
|
27
|
+
"./esbuild": "./dist/esbuild.mjs",
|
|
28
|
+
"./rolldown": "./dist/rolldown.mjs",
|
|
29
|
+
"./rollup": "./dist/rollup.mjs",
|
|
30
|
+
"./rspack": "./dist/rspack.mjs",
|
|
31
|
+
"./vite": "./dist/vite.mjs",
|
|
32
|
+
"./webpack": "./dist/webpack.mjs",
|
|
39
33
|
"./package.json": "./package.json"
|
|
40
34
|
},
|
|
35
|
+
"types": "./dist/index.d.mts",
|
|
41
36
|
"typesVersions": {
|
|
42
37
|
"*": {
|
|
43
38
|
"*": [
|
|
44
|
-
"./dist
|
|
39
|
+
"./dist/*.d.mts",
|
|
45
40
|
"./*"
|
|
46
41
|
]
|
|
47
42
|
}
|
|
48
43
|
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
49
47
|
"publishConfig": {
|
|
50
48
|
"access": "public"
|
|
51
49
|
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20.19.0"
|
|
52
|
+
},
|
|
52
53
|
"peerDependencies": {
|
|
53
54
|
"esbuild": ">=0.25.0"
|
|
54
55
|
},
|
|
@@ -58,26 +59,24 @@
|
|
|
58
59
|
}
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"unplugin": "^2.3.
|
|
62
|
-
"unplugin-utils": "^0.3.
|
|
62
|
+
"unplugin": "^2.3.11",
|
|
63
|
+
"unplugin-utils": "^0.3.1"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@sxzz/eslint-config": "^7.
|
|
66
|
-
"@sxzz/prettier-config": "^2.2.
|
|
67
|
-
"@types/node": "^
|
|
68
|
-
"bumpp": "^10.2
|
|
69
|
-
"esbuild": "^0.
|
|
70
|
-
"eslint": "^9.
|
|
71
|
-
"prettier": "^3.
|
|
72
|
-
"rolldown": "1.0.0-beta.
|
|
73
|
-
"rollup": "^4.
|
|
74
|
-
"tsdown": "^0.
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
"engines": {
|
|
80
|
-
"node": ">=20.18.0"
|
|
66
|
+
"@sxzz/eslint-config": "^7.4.4",
|
|
67
|
+
"@sxzz/prettier-config": "^2.2.6",
|
|
68
|
+
"@types/node": "^25.0.3",
|
|
69
|
+
"bumpp": "^10.3.2",
|
|
70
|
+
"esbuild": "^0.27.2",
|
|
71
|
+
"eslint": "^9.39.2",
|
|
72
|
+
"prettier": "^3.7.4",
|
|
73
|
+
"rolldown": "^1.0.0-beta.58",
|
|
74
|
+
"rollup": "^4.54.0",
|
|
75
|
+
"tsdown": "^0.19.0-beta.2",
|
|
76
|
+
"tsdown-preset-sxzz": "^0.2.0",
|
|
77
|
+
"typescript": "^5.9.3",
|
|
78
|
+
"vite": "^7.3.0",
|
|
79
|
+
"vitest": "^4.0.16"
|
|
81
80
|
},
|
|
82
81
|
"prettier": "@sxzz/prettier-config",
|
|
83
82
|
"scripts": {
|
package/dist/api.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Options, OptionsResolved, TransformOptions, resolveOptions } from "./options-DupdgTT1.js";
|
|
2
|
-
import * as esbuild0 from "esbuild";
|
|
3
|
-
import { TransformOptions as TransformOptions$1 } from "esbuild";
|
|
4
|
-
import { Buffer } from "node:buffer";
|
|
5
|
-
|
|
6
|
-
//#region src/core/transform.d.ts
|
|
7
|
-
declare function transformRaw(file: string, isBytes: boolean, transform?: typeof esbuild0.transform, transformFilter?: (id: string | unknown) => boolean, options?: TransformOptions$1): Promise<string | Buffer>;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { type Options, type OptionsResolved, type TransformOptions, resolveOptions, transformRaw };
|
package/dist/api.js
DELETED
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED