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 +3 -15
- package/dist/esbuild.js +1 -1
- package/dist/{index-DfjJYIkP.d.ts → index-CbkvuMB_.d.ts} +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rolldown.d.ts +3 -15
- package/dist/rolldown.js +1 -1
- package/dist/rollup.d.ts +3 -15
- package/dist/rollup.js +1 -1
- package/dist/rspack.d.ts +3 -13
- package/dist/rspack.js +1 -1
- package/dist/{src-i5caNZ-U.js → src-DE-h8IJW.js} +32 -17
- package/dist/vite.d.ts +3 -15
- package/dist/vite.js +1 -1
- package/dist/webpack.d.ts +3 -13
- package/dist/webpack.js +1 -1
- package/package.json +15 -15
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import { unplugin } from "./index-
|
|
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;
|
|
18
|
+
declare const esbuild: typeof unplugin.esbuild;
|
|
19
|
+
//#endregion
|
|
32
20
|
export { esbuild as default, esbuild as "module.exports" };
|
package/dist/esbuild.js
CHANGED
|
@@ -15,10 +15,10 @@ interface Options {
|
|
|
15
15
|
/** @default {} */
|
|
16
16
|
options?: TransformOptions;
|
|
17
17
|
};
|
|
18
|
-
}
|
|
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
|
|
24
|
+
export { guessLoader, unplugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { guessLoader
|
|
1
|
+
import { guessLoader, unplugin } from "./index-CbkvuMB_.js";
|
|
2
2
|
export { unplugin as default, guessLoader };
|
package/dist/index.js
CHANGED
package/dist/rolldown.d.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import { unplugin } from "./index-
|
|
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;
|
|
18
|
+
declare const rolldown: typeof unplugin.rolldown;
|
|
19
|
+
//#endregion
|
|
32
20
|
export { rolldown as default, rolldown as "module.exports" };
|
package/dist/rolldown.js
CHANGED
package/dist/rollup.d.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import { unplugin } from "./index-
|
|
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;
|
|
18
|
+
declare const rollup: typeof unplugin.rollup;
|
|
19
|
+
//#endregion
|
|
32
20
|
export { rollup as default, rollup as "module.exports" };
|
package/dist/rollup.js
CHANGED
package/dist/rspack.d.ts
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import { unplugin } from "./index-
|
|
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;
|
|
16
|
+
declare const rspack: typeof unplugin.rspack;
|
|
17
|
+
//#endregion
|
|
28
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,19 +1,6 @@
|
|
|
1
|
-
import { unplugin } from "./index-
|
|
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;
|
|
18
|
+
declare const vite: typeof unplugin.vite;
|
|
19
|
+
//#endregion
|
|
32
20
|
export { vite as default, vite as "module.exports" };
|
package/dist/vite.js
CHANGED
package/dist/webpack.d.ts
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import { unplugin } from "./index-
|
|
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;
|
|
16
|
+
declare const webpack: typeof unplugin.webpack;
|
|
17
|
+
//#endregion
|
|
28
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.5.
|
|
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.
|
|
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": "^7.
|
|
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
71
|
"node": ">=20.18.0"
|