unplugin-raw 0.5.0 → 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 CHANGED
@@ -1,19 +1,6 @@
1
- import { unplugin } from "./index-DfjJYIkP.js";
1
+ import { unplugin } from "./index-CbkvuMB_.js";
2
2
 
3
3
  //#region src/esbuild.d.ts
4
- /**
5
- * Esbuild plugin
6
- *
7
- * @example
8
- * ```ts
9
- * // esbuild.config.js
10
- * import { build } from 'esbuild'
11
- *
12
- * build({
13
- * plugins: [require('unplugin-raw/esbuild')()],
14
- * })
15
- * ```
16
- */
17
4
 
18
5
  /**
19
6
  * Esbuild plugin
@@ -28,5 +15,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
28
15
  * })
29
16
  * ```
30
17
  */
31
- declare const esbuild: typeof unplugin.esbuild; //#endregion
18
+ declare const esbuild: typeof unplugin.esbuild;
19
+ //#endregion
32
20
  export { esbuild as default, esbuild as "module.exports" };
package/dist/esbuild.js CHANGED
@@ -1,4 +1,4 @@
1
- import { src_default } from "./src-i5caNZ-U.js";
1
+ import { src_default } from "./src-DE-h8IJW.js";
2
2
 
3
3
  //#region src/esbuild.ts
4
4
  /**
@@ -15,10 +15,10 @@ interface Options {
15
15
  /** @default {} */
16
16
  options?: TransformOptions;
17
17
  };
18
- } //#endregion
18
+ }
19
+ //#endregion
19
20
  //#region src/index.d.ts
20
21
  declare const unplugin: UnpluginInstance<Options | undefined, false>;
21
22
  declare function guessLoader(id: string): Loader;
22
-
23
23
  //#endregion
24
- export { guessLoader as guessLoader$1, unplugin };
24
+ export { guessLoader, unplugin };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { guessLoader$1 as guessLoader, unplugin } from "./index-DfjJYIkP.js";
1
+ import { guessLoader, unplugin } from "./index-CbkvuMB_.js";
2
2
  export { unplugin as default, guessLoader };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { guessLoader, src_default } from "./src-i5caNZ-U.js";
1
+ import { guessLoader, src_default } from "./src-DE-h8IJW.js";
2
2
 
3
3
  export { src_default as default, guessLoader };
@@ -1,19 +1,6 @@
1
- import { unplugin } from "./index-DfjJYIkP.js";
1
+ import { unplugin } from "./index-CbkvuMB_.js";
2
2
 
3
3
  //#region src/rolldown.d.ts
4
- /**
5
- * Rolldown plugin
6
- *
7
- * @example
8
- * ```ts
9
- * // rolldown.config.js
10
- * import Raw from 'unplugin-raw/rolldown'
11
- *
12
- * export default {
13
- * plugins: [Raw()],
14
- * }
15
- * ```
16
- */
17
4
 
18
5
  /**
19
6
  * Rolldown plugin
@@ -28,5 +15,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
28
15
  * }
29
16
  * ```
30
17
  */
31
- declare const rolldown: typeof unplugin.rolldown; //#endregion
18
+ declare const rolldown: typeof unplugin.rolldown;
19
+ //#endregion
32
20
  export { rolldown as default, rolldown as "module.exports" };
package/dist/rolldown.js CHANGED
@@ -1,4 +1,4 @@
1
- import { src_default } from "./src-i5caNZ-U.js";
1
+ import { src_default } from "./src-DE-h8IJW.js";
2
2
 
3
3
  //#region src/rolldown.ts
4
4
  /**
package/dist/rollup.d.ts CHANGED
@@ -1,19 +1,6 @@
1
- import { unplugin } from "./index-DfjJYIkP.js";
1
+ import { unplugin } from "./index-CbkvuMB_.js";
2
2
 
3
3
  //#region src/rollup.d.ts
4
- /**
5
- * Rollup plugin
6
- *
7
- * @example
8
- * ```ts
9
- * // rollup.config.js
10
- * import Raw from 'unplugin-raw/rollup'
11
- *
12
- * export default {
13
- * plugins: [Raw()],
14
- * }
15
- * ```
16
- */
17
4
 
18
5
  /**
19
6
  * Rollup plugin
@@ -28,5 +15,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
28
15
  * }
29
16
  * ```
30
17
  */
31
- declare const rollup: typeof unplugin.rollup; //#endregion
18
+ declare const rollup: typeof unplugin.rollup;
19
+ //#endregion
32
20
  export { rollup as default, rollup as "module.exports" };
package/dist/rollup.js CHANGED
@@ -1,4 +1,4 @@
1
- import { src_default } from "./src-i5caNZ-U.js";
1
+ import { src_default } from "./src-DE-h8IJW.js";
2
2
 
3
3
  //#region src/rollup.ts
4
4
  /**
package/dist/rspack.d.ts CHANGED
@@ -1,17 +1,6 @@
1
- import { unplugin } from "./index-DfjJYIkP.js";
1
+ import { unplugin } from "./index-CbkvuMB_.js";
2
2
 
3
3
  //#region src/rspack.d.ts
4
- /**
5
- * Rspack plugin
6
- *
7
- * @example
8
- * ```ts
9
- * // rspack.config.js
10
- * module.exports = {
11
- * plugins: [require('unplugin-raw/rspack')()],
12
- * }
13
- * ```
14
- */
15
4
 
16
5
  /**
17
6
  * Rspack plugin
@@ -24,5 +13,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
24
13
  * }
25
14
  * ```
26
15
  */
27
- declare const rspack: typeof unplugin.rspack; //#endregion
16
+ declare const rspack: typeof unplugin.rspack;
17
+ //#endregion
28
18
  export { rspack as default, rspack as "module.exports" };
package/dist/rspack.js CHANGED
@@ -1,4 +1,4 @@
1
- import { src_default } from "./src-i5caNZ-U.js";
1
+ import { src_default } from "./src-DE-h8IJW.js";
2
2
 
3
3
  //#region src/rspack.ts
4
4
  /**
@@ -25,9 +25,14 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
25
25
  return {
26
26
  name: "unplugin-raw",
27
27
  enforce: options.enforce,
28
- resolveId: meta.framework === "rollup" ? async function(id, importer, opt) {
29
- if (opt?.attributes?.type === "text") if (id.includes("?")) id += "&raw";
30
- else id += "?raw";
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
- let contents = await readFile(file, "utf-8");
42
- if (transformFilter(file)) {
43
- let transform;
44
- const nativeContext = this.getNativeBuildContext?.();
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
- if (args.with.type === "text") return { contents: "export default \"123\"" };
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,19 +1,6 @@
1
- import { unplugin } from "./index-DfjJYIkP.js";
1
+ import { unplugin } from "./index-CbkvuMB_.js";
2
2
 
3
3
  //#region src/vite.d.ts
4
- /**
5
- * Vite plugin
6
- *
7
- * @example
8
- * ```ts
9
- * // vite.config.ts
10
- * import Raw from 'unplugin-raw/vite'
11
- *
12
- * export default defineConfig({
13
- * plugins: [Raw()],
14
- * })
15
- * ```
16
- */
17
4
 
18
5
  /**
19
6
  * Vite plugin
@@ -28,5 +15,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
28
15
  * })
29
16
  * ```
30
17
  */
31
- declare const vite: typeof unplugin.vite; //#endregion
18
+ declare const vite: typeof unplugin.vite;
19
+ //#endregion
32
20
  export { vite as default, vite as "module.exports" };
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import { src_default } from "./src-i5caNZ-U.js";
1
+ import { src_default } from "./src-DE-h8IJW.js";
2
2
 
3
3
  //#region src/vite.ts
4
4
  /**
package/dist/webpack.d.ts CHANGED
@@ -1,17 +1,6 @@
1
- import { unplugin } from "./index-DfjJYIkP.js";
1
+ import { unplugin } from "./index-CbkvuMB_.js";
2
2
 
3
3
  //#region src/webpack.d.ts
4
- /**
5
- * Webpack plugin
6
- *
7
- * @example
8
- * ```ts
9
- * // webpack.config.js
10
- * module.exports = {
11
- * plugins: [require('unplugin-raw/webpack')()],
12
- * }
13
- * ```
14
- */
15
4
 
16
5
  /**
17
6
  * Webpack plugin
@@ -24,5 +13,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
24
13
  * }
25
14
  * ```
26
15
  */
27
- declare const webpack: typeof unplugin.webpack; //#endregion
16
+ declare const webpack: typeof unplugin.webpack;
17
+ //#endregion
28
18
  export { webpack as default, webpack as "module.exports" };
package/dist/webpack.js CHANGED
@@ -1,4 +1,4 @@
1
- import { src_default } from "./src-i5caNZ-U.js";
1
+ import { src_default } from "./src-DE-h8IJW.js";
2
2
 
3
3
  //#region src/webpack.ts
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-raw",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Transform file to a default-export string.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -49,23 +49,23 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "esbuild": "^0.25.4",
53
- "unplugin": "^2.3.2",
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": "^7.0.0",
58
- "@sxzz/prettier-config": "^2.2.1",
59
- "@types/node": "^22.15.17",
60
- "bumpp": "^10.1.0",
61
- "eslint": "^9.26.0",
62
- "prettier": "^3.5.3",
63
- "rollup": "^4.40.2",
64
- "tsdown": "^0.11.1",
65
- "tsx": "^4.19.4",
66
- "typescript": "^5.8.3",
67
- "vite": "^6.3.5",
68
- "vitest": "^3.1.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
71
  "node": ">=20.18.0"