unplugin-raw 0.5.0 → 0.6.0
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 +35 -9
- package/dist/api.d.ts +9 -0
- package/dist/api.js +3 -0
- package/dist/esbuild.d.ts +4 -15
- package/dist/esbuild.js +2 -1
- package/dist/index-BMXQlGcW.d.ts +7 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/options-BTT0I76V.js +55 -0
- package/dist/options-DupdgTT1.d.ts +27 -0
- package/dist/rolldown.d.ts +4 -15
- package/dist/rolldown.js +2 -1
- package/dist/rollup.d.ts +4 -15
- package/dist/rollup.js +2 -1
- package/dist/rspack.d.ts +4 -13
- package/dist/rspack.js +2 -1
- package/dist/src-BAcSYQaW.js +58 -0
- package/dist/vite.d.ts +4 -15
- package/dist/vite.js +2 -1
- package/dist/webpack.d.ts +4 -13
- package/dist/webpack.js +2 -1
- package/package.json +24 -16
- package/dist/index-DfjJYIkP.d.ts +0 -24
- package/dist/src-i5caNZ-U.js +0 -90
package/README.md
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/unplugin/unplugin-raw/actions/workflows/unit-test.yml)
|
|
4
4
|
|
|
5
|
-
Transform file to a default-export string
|
|
5
|
+
Transform file to a default-export string, and can be transformed by esbuild.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm i -D unplugin-raw
|
|
11
|
+
|
|
12
|
+
npm i -D esbuild # Optional, if you want to transform TypeScript to JavaScript
|
|
11
13
|
```
|
|
12
14
|
|
|
13
15
|
<details>
|
|
@@ -38,6 +40,20 @@ export default {
|
|
|
38
40
|
|
|
39
41
|
<br></details>
|
|
40
42
|
|
|
43
|
+
<details>
|
|
44
|
+
<summary>Rolldown</summary><br>
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// rolldown.config.js
|
|
48
|
+
import Raw from 'unplugin-raw/rolldown'
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
plugins: [Raw()],
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
<br></details>
|
|
56
|
+
|
|
41
57
|
<details>
|
|
42
58
|
<summary>esbuild</summary><br>
|
|
43
59
|
|
|
@@ -52,18 +68,28 @@ build({
|
|
|
52
68
|
|
|
53
69
|
<br></details>
|
|
54
70
|
|
|
55
|
-
|
|
56
|
-
<summary>Webpack</summary><br>
|
|
71
|
+
## Options
|
|
57
72
|
|
|
58
73
|
```ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
export interface TransformOptions {
|
|
75
|
+
/** @default [/\.[cm]?[jt]sx?$/] */
|
|
76
|
+
include?: FilterPattern
|
|
77
|
+
/** @default [/node_modules/] */
|
|
78
|
+
exclude?: FilterPattern
|
|
79
|
+
/** @default {} */
|
|
80
|
+
options?: EsbuildTransformOptions
|
|
63
81
|
}
|
|
64
|
-
```
|
|
65
82
|
|
|
66
|
-
|
|
83
|
+
export interface Options {
|
|
84
|
+
/** @default 'pre' */
|
|
85
|
+
enforce?: 'pre' | 'post' | undefined
|
|
86
|
+
/**
|
|
87
|
+
* Transform
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
transform?: TransformOptions | boolean
|
|
91
|
+
}
|
|
92
|
+
```
|
|
67
93
|
|
|
68
94
|
## Usage
|
|
69
95
|
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
ADDED
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./options-DupdgTT1.js";
|
|
2
|
+
import { unplugin } from "./index-BMXQlGcW.js";
|
|
2
3
|
|
|
3
4
|
//#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
5
|
|
|
18
6
|
/**
|
|
19
7
|
* Esbuild plugin
|
|
@@ -28,5 +16,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
|
|
|
28
16
|
* })
|
|
29
17
|
* ```
|
|
30
18
|
*/
|
|
31
|
-
declare const esbuild: typeof unplugin.esbuild;
|
|
19
|
+
declare const esbuild: typeof unplugin.esbuild;
|
|
20
|
+
//#endregion
|
|
32
21
|
export { esbuild as default, esbuild as "module.exports" };
|
package/dist/esbuild.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "./options-DupdgTT1.js";
|
|
2
|
+
import { unplugin } from "./index-BMXQlGcW.js";
|
|
3
|
+
export { unplugin as default };
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/core/transform.ts
|
|
5
|
+
async function transformRaw(file, isBytes, transform, transformFilter, options) {
|
|
6
|
+
let contents = await readFile(file, isBytes ? void 0 : "utf8");
|
|
7
|
+
if (!isBytes && transformFilter?.(file)) {
|
|
8
|
+
transform ||= (await import("esbuild")).transform;
|
|
9
|
+
contents = (await transform(contents, {
|
|
10
|
+
loader: guessLoader(file),
|
|
11
|
+
...options
|
|
12
|
+
})).code;
|
|
13
|
+
}
|
|
14
|
+
return isBytes ? contents : `export default ${JSON.stringify(contents)}`;
|
|
15
|
+
}
|
|
16
|
+
const ExtToLoader = {
|
|
17
|
+
".js": "js",
|
|
18
|
+
".mjs": "js",
|
|
19
|
+
".cjs": "js",
|
|
20
|
+
".jsx": "jsx",
|
|
21
|
+
".ts": "ts",
|
|
22
|
+
".cts": "ts",
|
|
23
|
+
".mts": "ts",
|
|
24
|
+
".tsx": "tsx",
|
|
25
|
+
".css": "css",
|
|
26
|
+
".less": "css",
|
|
27
|
+
".stylus": "css",
|
|
28
|
+
".scss": "css",
|
|
29
|
+
".sass": "css",
|
|
30
|
+
".json": "json",
|
|
31
|
+
".txt": "text"
|
|
32
|
+
};
|
|
33
|
+
function guessLoader(id) {
|
|
34
|
+
return ExtToLoader[path.extname(id).toLowerCase()] || "js";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/core/options.ts
|
|
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 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FilterPattern } from "unplugin-utils";
|
|
2
|
+
import { TransformOptions } from "esbuild";
|
|
3
|
+
|
|
4
|
+
//#region src/core/options.d.ts
|
|
5
|
+
interface TransformOptions$1 {
|
|
6
|
+
/** @default [/\.[cm]?[jt]sx?$/] */
|
|
7
|
+
include?: FilterPattern;
|
|
8
|
+
/** @default [/node_modules/] */
|
|
9
|
+
exclude?: FilterPattern;
|
|
10
|
+
/** @default {} */
|
|
11
|
+
options?: TransformOptions;
|
|
12
|
+
}
|
|
13
|
+
interface Options {
|
|
14
|
+
/** @default 'pre' */
|
|
15
|
+
enforce?: "pre" | "post" | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Transform
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
transform?: TransformOptions$1 | boolean;
|
|
21
|
+
}
|
|
22
|
+
type OptionsResolved = Pick<Options, "enforce"> & {
|
|
23
|
+
transform: TransformOptions$1 | false;
|
|
24
|
+
};
|
|
25
|
+
declare function resolveOptions(options: Options): OptionsResolved;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { Options, OptionsResolved, TransformOptions$1 as TransformOptions, resolveOptions };
|
package/dist/rolldown.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./options-DupdgTT1.js";
|
|
2
|
+
import { unplugin } from "./index-BMXQlGcW.js";
|
|
2
3
|
|
|
3
4
|
//#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
5
|
|
|
18
6
|
/**
|
|
19
7
|
* Rolldown plugin
|
|
@@ -28,5 +16,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
|
|
|
28
16
|
* }
|
|
29
17
|
* ```
|
|
30
18
|
*/
|
|
31
|
-
declare const rolldown: typeof unplugin.rolldown;
|
|
19
|
+
declare const rolldown: typeof unplugin.rolldown;
|
|
20
|
+
//#endregion
|
|
32
21
|
export { rolldown as default, rolldown as "module.exports" };
|
package/dist/rolldown.js
CHANGED
package/dist/rollup.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./options-DupdgTT1.js";
|
|
2
|
+
import { unplugin } from "./index-BMXQlGcW.js";
|
|
2
3
|
|
|
3
4
|
//#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
5
|
|
|
18
6
|
/**
|
|
19
7
|
* Rollup plugin
|
|
@@ -28,5 +16,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
|
|
|
28
16
|
* }
|
|
29
17
|
* ```
|
|
30
18
|
*/
|
|
31
|
-
declare const rollup: typeof unplugin.rollup;
|
|
19
|
+
declare const rollup: typeof unplugin.rollup;
|
|
20
|
+
//#endregion
|
|
32
21
|
export { rollup as default, rollup as "module.exports" };
|
package/dist/rollup.js
CHANGED
package/dist/rspack.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./options-DupdgTT1.js";
|
|
2
|
+
import { unplugin } from "./index-BMXQlGcW.js";
|
|
2
3
|
|
|
3
4
|
//#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
5
|
|
|
16
6
|
/**
|
|
17
7
|
* Rspack plugin
|
|
@@ -24,5 +14,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
|
|
|
24
14
|
* }
|
|
25
15
|
* ```
|
|
26
16
|
*/
|
|
27
|
-
declare const rspack: typeof unplugin.rspack;
|
|
17
|
+
declare const rspack: typeof unplugin.rspack;
|
|
18
|
+
//#endregion
|
|
28
19
|
export { rspack as default, rspack as "module.exports" };
|
package/dist/rspack.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { resolveOptions, transformRaw } from "./options-BTT0I76V.js";
|
|
2
|
+
import { createUnplugin } from "unplugin";
|
|
3
|
+
import { createFilter } from "unplugin-utils";
|
|
4
|
+
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
const rawRE = /[&?]raw(?:&|$)/;
|
|
7
|
+
const postfixRE = /[#?].*$/s;
|
|
8
|
+
function cleanUrl(url) {
|
|
9
|
+
return url.replace(postfixRE, "");
|
|
10
|
+
}
|
|
11
|
+
const unplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
12
|
+
const options = resolveOptions(rawOptions);
|
|
13
|
+
const transformFilter = options.transform ? createFilter(options.transform.include, options.transform.exclude) : void 0;
|
|
14
|
+
return {
|
|
15
|
+
name: "unplugin-raw",
|
|
16
|
+
enforce: options.enforce,
|
|
17
|
+
resolveId: [
|
|
18
|
+
"rollup",
|
|
19
|
+
"rolldown",
|
|
20
|
+
"vite"
|
|
21
|
+
].includes(meta.framework) ? async function(id, importer, options$1) {
|
|
22
|
+
const attributeType = options$1?.attributes?.type;
|
|
23
|
+
if (attributeType === "text") id += `${id.includes("?") ? "&" : "?"}raw`;
|
|
24
|
+
else if (attributeType === "bytes") id += `${id.includes("?") ? "&" : "?"}bytes`;
|
|
25
|
+
if (!rawRE.test(id)) return;
|
|
26
|
+
const file = cleanUrl(id);
|
|
27
|
+
const resolved = await this.resolve(file, importer);
|
|
28
|
+
if (!resolved) return;
|
|
29
|
+
return id.replace(file, resolved.id);
|
|
30
|
+
} : void 0,
|
|
31
|
+
load: {
|
|
32
|
+
filter: { id: { include: rawRE } },
|
|
33
|
+
async handler(id) {
|
|
34
|
+
const file = cleanUrl(id);
|
|
35
|
+
const context = this.getNativeBuildContext?.();
|
|
36
|
+
const transform = context?.framework === "esbuild" ? context.build.esbuild.transform : void 0;
|
|
37
|
+
const contents = await transformRaw(file, false, transform, transformFilter, options.transform ? options.transform.options : void 0);
|
|
38
|
+
return contents;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
esbuild: { setup(build) {
|
|
42
|
+
build.onLoad({ filter: /.*/ }, async (args) => {
|
|
43
|
+
const isBytes = args.with.type === "bytes";
|
|
44
|
+
if (args.with.type === "text" || isBytes) {
|
|
45
|
+
const contents = await transformRaw(args.path, isBytes, build.esbuild.transform, transformFilter, options.transform ? options.transform.options : void 0);
|
|
46
|
+
return {
|
|
47
|
+
contents,
|
|
48
|
+
loader: typeof contents === "string" ? "js" : "binary"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
} }
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
var src_default = unplugin;
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { src_default };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./options-DupdgTT1.js";
|
|
2
|
+
import { unplugin } from "./index-BMXQlGcW.js";
|
|
2
3
|
|
|
3
4
|
//#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
5
|
|
|
18
6
|
/**
|
|
19
7
|
* Vite plugin
|
|
@@ -28,5 +16,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
|
|
|
28
16
|
* })
|
|
29
17
|
* ```
|
|
30
18
|
*/
|
|
31
|
-
declare const vite: typeof unplugin.vite;
|
|
19
|
+
declare const vite: typeof unplugin.vite;
|
|
20
|
+
//#endregion
|
|
32
21
|
export { vite as default, vite as "module.exports" };
|
package/dist/vite.js
CHANGED
package/dist/webpack.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./options-DupdgTT1.js";
|
|
2
|
+
import { unplugin } from "./index-BMXQlGcW.js";
|
|
2
3
|
|
|
3
4
|
//#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
5
|
|
|
16
6
|
/**
|
|
17
7
|
* Webpack plugin
|
|
@@ -24,5 +14,6 @@ import { unplugin } from "./index-DfjJYIkP.js";
|
|
|
24
14
|
* }
|
|
25
15
|
* ```
|
|
26
16
|
*/
|
|
27
|
-
declare const webpack: typeof unplugin.webpack;
|
|
17
|
+
declare const webpack: typeof unplugin.webpack;
|
|
18
|
+
//#endregion
|
|
28
19
|
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.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Transform file to a default-export string.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -48,24 +48,32 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"esbuild": ">=0.25.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"esbuild": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
51
59
|
"dependencies": {
|
|
52
|
-
"
|
|
53
|
-
"unplugin": "^2.
|
|
54
|
-
"unplugin-utils": "^0.2.4"
|
|
60
|
+
"unplugin": "^2.3.5",
|
|
61
|
+
"unplugin-utils": "^0.2.5"
|
|
55
62
|
},
|
|
56
63
|
"devDependencies": {
|
|
57
|
-
"@sxzz/eslint-config": "^7.
|
|
58
|
-
"@sxzz/prettier-config": "^2.2.
|
|
59
|
-
"@types/node": "^
|
|
60
|
-
"bumpp": "^10.
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
64
|
+
"@sxzz/eslint-config": "^7.1.2",
|
|
65
|
+
"@sxzz/prettier-config": "^2.2.3",
|
|
66
|
+
"@types/node": "^24.2.1",
|
|
67
|
+
"bumpp": "^10.2.3",
|
|
68
|
+
"esbuild": "^0.25.9",
|
|
69
|
+
"eslint": "^9.33.0",
|
|
70
|
+
"prettier": "^3.6.2",
|
|
71
|
+
"rollup": "^4.46.2",
|
|
72
|
+
"tsdown": "^0.14.1",
|
|
73
|
+
"tsx": "^4.20.4",
|
|
74
|
+
"typescript": "^5.9.2",
|
|
75
|
+
"vite": "^7.1.2",
|
|
76
|
+
"vitest": "^3.2.4"
|
|
69
77
|
},
|
|
70
78
|
"engines": {
|
|
71
79
|
"node": ">=20.18.0"
|
package/dist/index-DfjJYIkP.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
} //#endregion
|
|
19
|
-
//#region src/index.d.ts
|
|
20
|
-
declare const unplugin: UnpluginInstance<Options | undefined, false>;
|
|
21
|
-
declare function guessLoader(id: string): Loader;
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
export { guessLoader as guessLoader$1, unplugin };
|
package/dist/src-i5caNZ-U.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { createUnplugin } from "unplugin";
|
|
4
|
-
import { createFilter } from "unplugin-utils";
|
|
5
|
-
|
|
6
|
-
//#region src/core/options.ts
|
|
7
|
-
function resolveOptions(options) {
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
enforce: "enforce" in options ? options.enforce : "pre",
|
|
11
|
-
transform: {
|
|
12
|
-
...options.transform,
|
|
13
|
-
include: options.transform?.include || [/\.[cm]?[jt]sx?$/],
|
|
14
|
-
exclude: options.transform?.exclude || [/node_modules/],
|
|
15
|
-
options: options.transform?.options || {}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/index.ts
|
|
22
|
-
const unplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
23
|
-
const options = resolveOptions(rawOptions);
|
|
24
|
-
const transformFilter = createFilter(options.transform.include, options.transform.exclude);
|
|
25
|
-
return {
|
|
26
|
-
name: "unplugin-raw",
|
|
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";
|
|
31
|
-
if (!rawRE.test(id)) return;
|
|
32
|
-
const file = cleanUrl(id);
|
|
33
|
-
const resolved = await this.resolve(file, importer);
|
|
34
|
-
if (!resolved) return;
|
|
35
|
-
return id.replace(file, resolved.id);
|
|
36
|
-
} : void 0,
|
|
37
|
-
load: {
|
|
38
|
-
filter: { id: { include: rawRE } },
|
|
39
|
-
async handler(id) {
|
|
40
|
-
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)}`;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
esbuild: { setup(build) {
|
|
56
|
-
build.onLoad({ filter: /.*/ }, (args) => {
|
|
57
|
-
if (args.with.type === "text") return { contents: "export default \"123\"" };
|
|
58
|
-
});
|
|
59
|
-
} }
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
var src_default = unplugin;
|
|
63
|
-
const rawRE = /[&?]raw(?:&|$)/;
|
|
64
|
-
const postfixRE = /[#?].*$/s;
|
|
65
|
-
function cleanUrl(url) {
|
|
66
|
-
return url.replace(postfixRE, "");
|
|
67
|
-
}
|
|
68
|
-
const ExtToLoader = {
|
|
69
|
-
".js": "js",
|
|
70
|
-
".mjs": "js",
|
|
71
|
-
".cjs": "js",
|
|
72
|
-
".jsx": "jsx",
|
|
73
|
-
".ts": "ts",
|
|
74
|
-
".cts": "ts",
|
|
75
|
-
".mts": "ts",
|
|
76
|
-
".tsx": "tsx",
|
|
77
|
-
".css": "css",
|
|
78
|
-
".less": "css",
|
|
79
|
-
".stylus": "css",
|
|
80
|
-
".scss": "css",
|
|
81
|
-
".sass": "css",
|
|
82
|
-
".json": "json",
|
|
83
|
-
".txt": "text"
|
|
84
|
-
};
|
|
85
|
-
function guessLoader(id) {
|
|
86
|
-
return ExtToLoader[path.extname(id).toLowerCase()] || "js";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
export { guessLoader, src_default };
|