unplugin-raw 0.6.2 → 0.6.3

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 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.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Options, OptionsResolved, TransformOptions, resolveOptions } from "./options-DupdgTT1.js";
2
+ import { Buffer } from "node:buffer";
2
3
  import * as esbuild0 from "esbuild";
3
4
  import { TransformOptions as TransformOptions$1 } from "esbuild";
4
- import { Buffer } from "node:buffer";
5
5
 
6
6
  //#region src/core/transform.d.ts
7
7
  declare function transformRaw(file: string, isBytes: boolean, transform?: typeof esbuild0.transform, transformFilter?: (id: string | unknown) => boolean, options?: TransformOptions$1): Promise<string | Buffer>;
package/dist/esbuild.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-C8tBe-z3.js";
2
+ import { src_default } from "./src-CKGRYIxm.js";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  /**
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-C8tBe-z3.js";
2
+ import { src_default } from "./src-CKGRYIxm.js";
3
3
 
4
4
  export { src_default as default };
package/dist/rolldown.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-C8tBe-z3.js";
2
+ import { src_default } from "./src-CKGRYIxm.js";
3
3
 
4
4
  //#region src/rolldown.ts
5
5
  /**
package/dist/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-C8tBe-z3.js";
2
+ import { src_default } from "./src-CKGRYIxm.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  /**
package/dist/rspack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-C8tBe-z3.js";
2
+ import { src_default } from "./src-CKGRYIxm.js";
3
3
 
4
4
  //#region src/rspack.ts
5
5
  /**
@@ -1,9 +1,11 @@
1
1
  import { resolveOptions, transformRaw } from "./options-BTT0I76V.js";
2
+ import { Buffer } from "node:buffer";
2
3
  import { createUnplugin } from "unplugin";
3
4
  import { createFilter } from "unplugin-utils";
4
5
 
5
6
  //#region src/index.ts
6
7
  const rawRE = /[&?]raw(?:&|$)/;
8
+ const bytesRE = /[&?]bytes(?:&|$)/;
7
9
  const postfixRE = /[#?].*$/s;
8
10
  function cleanUrl(url) {
9
11
  return url.replace(postfixRE, "");
@@ -22,19 +24,22 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
22
24
  const attributeType = options$1?.attributes?.type;
23
25
  if (attributeType === "text") id += `${id.includes("?") ? "&" : "?"}raw`;
24
26
  else if (attributeType === "bytes") id += `${id.includes("?") ? "&" : "?"}bytes`;
25
- if (!rawRE.test(id)) return;
27
+ else if (!rawRE.test(id) && !bytesRE.test(id)) return;
26
28
  const file = cleanUrl(id);
27
29
  const resolved = await this.resolve(file, importer);
28
30
  if (!resolved) return;
29
31
  return id.replace(file, resolved.id);
30
32
  } : void 0,
31
33
  load: {
32
- filter: { id: { include: rawRE } },
34
+ filter: { id: { include: [rawRE, bytesRE] } },
33
35
  async handler(id) {
36
+ const isBytes = bytesRE.test(id);
34
37
  const file = cleanUrl(id);
35
38
  const context = this.getNativeBuildContext?.();
36
39
  const transform = context?.framework === "esbuild" ? context.build.esbuild.transform : void 0;
37
- return await transformRaw(file, false, transform, transformFilter, options.transform ? options.transform.options : void 0);
40
+ let contents = await transformRaw(file, isBytes, transform, transformFilter, options.transform ? options.transform.options : void 0);
41
+ if (Buffer.isBuffer(contents)) contents = `export default new Uint8Array([${contents.join(", ")}])`;
42
+ return contents;
38
43
  }
39
44
  },
40
45
  esbuild: { setup(build) {
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-C8tBe-z3.js";
2
+ import { src_default } from "./src-CKGRYIxm.js";
3
3
 
4
4
  //#region src/vite.ts
5
5
  /**
package/dist/webpack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-C8tBe-z3.js";
2
+ import { src_default } from "./src-CKGRYIxm.js";
3
3
 
4
4
  //#region src/webpack.ts
5
5
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-raw",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Transform file to a default-export string.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -64,16 +64,16 @@
64
64
  "devDependencies": {
65
65
  "@sxzz/eslint-config": "^7.1.4",
66
66
  "@sxzz/prettier-config": "^2.2.4",
67
- "@types/node": "^24.5.0",
67
+ "@types/node": "^24.5.2",
68
68
  "bumpp": "^10.2.3",
69
- "esbuild": "^0.25.9",
70
- "eslint": "^9.35.0",
69
+ "esbuild": "^0.25.10",
70
+ "eslint": "^9.36.0",
71
71
  "prettier": "^3.6.2",
72
- "rolldown": "1.0.0-beta.38",
73
- "rollup": "^4.50.2",
74
- "tsdown": "^0.15.1",
72
+ "rolldown": "^1.0.0-beta.38",
73
+ "rollup": "^4.52.0",
74
+ "tsdown": "^0.15.4",
75
75
  "typescript": "^5.9.2",
76
- "vite": "^7.1.5",
76
+ "vite": "^7.1.6",
77
77
  "vitest": "^3.2.4"
78
78
  },
79
79
  "engines": {