You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**An ESBuild/TSUP plugin to import files as raw text.**
6
-
Ideal for scenarios like importing code files for documentation, interactive tools like `react-live`, or other text-based use cases.
11
+
**Lightweight ESBuild/TSUP plugin to import files as raw content — zero config required.**
7
12
8
-
> <imgsrc="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png"style="height: 20px"/> Star [this repository](https://github.com/react18-tools/esbuild-raw-plugin) and share it with your friends.
13
+
> Import `.ts`, `.js`, `.css`, `.scss`, `.md`, `.html`, `.docx`, and more — perfect for documentation, live editors (`react-live`), markdown tooling, or template-driven workflows.
14
+
> Power users: Load `.docx` templates directly for [mdast2docx](https://github.com/md2docx/mdast2docx).
15
+
16
+
> <imgsrc="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png"style="height: 20px"/> Star [this repository](https://github.com/react18-tools/esbuild-raw-plugin) and share it with your dev circle.
9
17
10
18
---
11
19
12
-
## Features
20
+
## 🚀 Features
13
21
14
-
- Import any file (e.g., `.js`, `.ts`, `.css`, etc.) as raw text.
15
-
- Works seamlessly with **ESBuild** and **TSUP**.
16
-
- Perfect for documentation generators, live code editors, and similar tools.
Add the following to your declaration file. If you do not have one, create a `declarations.d.ts` file and add the following:
83
+
Add this to your `declarations.d.ts` file:
80
84
81
-
```typescript
85
+
```ts
82
86
declaremodule"*?raw" {
83
-
constvalue:string;
84
-
exportdefaultvalue;
87
+
constcontent:string;
88
+
exportdefaultcontent;
85
89
}
86
90
```
87
91
88
-
## Importing Files as Raw Text
92
+
> For other suffixes (`?base64`, `?binary`, etc.), add similar declarations if needed.
93
+
94
+
---
89
95
90
-
With the plugin enabled, you can import files as raw text directly:
96
+
## 📥 Importing Raw Files
91
97
92
-
```js
93
-
importmyCodefrom"./example.js?raw";
98
+
```ts
99
+
importcontentfrom"./example.js?raw";
94
100
95
-
console.log(myCode);
96
-
// Outputs the content of 'example.js' as a string.
101
+
console.log(content); // Entire file content as string or Buffer
97
102
```
98
103
99
-
### Good News:
104
+
### ✅ Simplified Imports
100
105
101
-
With the latest update, you no longer need to specify the file extension explicitly.
106
+
You don’t need to specify full filenames or extensions:
102
107
103
-
```js
104
-
importmyCodefrom"./example?raw";
108
+
```ts
109
+
importcodefrom"./utils?raw";// Resolves to utils/index.ts, utils.js, etc.
105
110
```
106
111
107
-
This works seamlessly! Additionally, if you're exporting from files like `index.tsx`, `index.jsx`, etc., you can simplify imports. For example, if your file path is `my-lib/index.ts`, you can import the raw content like this:
112
+
Great for:
108
113
109
-
```js
110
-
importmyCodefrom"./my-lib?raw";
111
-
```
114
+
- Library or folder-level imports
115
+
- Auto-resolving `.ts`, `.tsx`, `.css`, `.scss`, etc.
112
116
113
-
### Extension Options (Optional)
117
+
---
118
+
119
+
## ⚙️ Plugin Options
114
120
115
121
```ts
116
122
exportinterfaceRawPluginOptions {
117
-
/**
118
-
* Extensions to check in order if the file does not exist.
119
-
* If it's a directory, the plugin will look for `dir/index.[ext]`.
This library is licensed under the MPL-2.0 open-source license.
212
+
Licensed under the **MPL-2.0** open-source license.
203
213
204
-
> <imgsrc="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png"style="height: 20px"/> Please enroll in [our courses](https://mayank-chaudhari.vercel.app/courses) or [sponsor](https://github.com/sponsors/mayank1513) our work.
214
+
> <imgsrc="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png"style="height: 20px"/> Please consider [sponsoring](https://github.com/sponsors/mayank1513) or [joining a course](https://mayank-chaudhari.vercel.app/courses) to support this work.
205
215
206
-
<hr />
216
+
---
207
217
208
218
<palign="center"style="text-align:center">with 💖 by <ahref="https://mayank-chaudhari.vercel.app"target="_blank">Mayank Kumar Chaudhari</a></p>
0 commit comments