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 CHANGED
@@ -1,13 +1,6 @@
1
- import unplugin from './index.js';
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 "\"module.exports\"", esbuild as default };
19
+ //#endregion
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
  /**
@@ -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 { UnpluginInstance } from 'unplugin';
2
- import { TransformOptions, Loader } from 'esbuild';
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
@@ -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,13 +1,6 @@
1
- import unplugin from './index.js';
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 "\"module.exports\"", rolldown as default };
19
+ //#endregion
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,13 +1,6 @@
1
- import unplugin from './index.js';
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 "\"module.exports\"", rollup as default };
19
+ //#endregion
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,13 +1,6 @@
1
- import unplugin from './index.js';
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 "\"module.exports\"", rspack as default };
17
+ //#endregion
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,13 +1,6 @@
1
- import unplugin from './index.js';
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 "\"module.exports\"", vite as default };
19
+ //#endregion
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,13 +1,6 @@
1
- import unplugin from './index.js';
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 "\"module.exports\"", webpack as default };
17
+ //#endregion
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.4.5",
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.2",
53
- "unplugin": "^2.3.0",
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": "^6.1.1",
58
- "@sxzz/prettier-config": "^2.2.1",
59
- "@types/node": "^22.14.0",
60
- "bumpp": "^10.1.0",
61
- "eslint": "^9.24.0",
62
- "prettier": "^3.5.3",
63
- "rollup": "^4.39.0",
64
- "tsdown": "^0.6.10",
65
- "tsx": "^4.19.3",
66
- "typescript": "^5.8.3",
67
- "vite": "^6.2.5",
68
- "vitest": "^3.1.1"
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.12.0"
71
+ "node": ">=20.18.0"
72
72
  },
73
73
  "prettier": "@sxzz/prettier-config",
74
74
  "scripts": {