Skip to content

Commit 11af32c

Browse files
authored
Merge branch 'main' into deepsource-transform-5629fa4f
2 parents fc7b7e6 + 753929b commit 11af32c

File tree

15 files changed

+566
-497
lines changed

15 files changed

+566
-497
lines changed

.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-06-25_08:28:32
1+
2025-06-29_01:49:18

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010

1111
**Lightweight ESBuild/TSUP plugin to import files as raw content — zero config required.**
1212

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).
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).
1515
1616
> <img src="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.
1717
1818
---
1919

2020
## 🚀 Features
2121

22+
> 🔥 Import any file as raw content with zero config in ESBuild or TSUP — text, base64, binary, docx templates & more!\
23+
> ⚡️ Fast, smart, and extensible → `esbuild-raw-plugin`
24+
2225
- 🔧 Supports `?raw`, `?text`, `?base64`, `?dataurl`, `?binary`, and `?file` query suffixes
2326
- 🧠 Smart fallback to extensions like `.ts`, `.tsx`, `index.[ext]`, etc.
2427
- 🔍 Custom loader mapping (e.g., `module.scss``text`, `png``dataurl`)

SECURITY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ We provide support for the latest minor version. Pull requests aimed at fixing s
66

77
| Version | Support Status |
88
| ------- | ------------------ |
9-
| 0.2.x | :white_check_mark: |
10-
| 0.1.x | :warning: |
11-
| < 0.1 | :x: |
9+
| 0.3.x | :white_check_mark: |
10+
| 0.2.x | :warning: |
11+
| < 0.2 | :x: |
1212

1313
## Patching Long-Term Support (LTS) Versions
1414

canonicals.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- `esbuild-raw-plugin` -> [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/esbuild-raw-plugin.svg)](https://www.npmjs.com/package/esbuild-raw-plugin)
2+
3+
- `esraw` -> [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/esraw.svg)](https://www.npmjs.com/package/esraw)
4+
5+
- `esbuild-raw` -> [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/esbuild-raw.svg)](https://www.npmjs.com/package/esbuild-raw)
6+
7+
- `esbuild-raw-loader` -> [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/esbuild-raw-loader.svg)](https://www.npmjs.com/package/esbuild-raw-loader)

examples/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@next/eslint-plugin-next": "^15.3.4",
2727
"@repo/eslint-config": "workspace:*",
2828
"@repo/typescript-config": "workspace:*",
29-
"@types/node": "^24.0.4",
29+
"@types/node": "^24.0.7",
3030
"@types/react": "^19.1.8",
3131
"@types/react-dom": "^19.1.6",
3232
"typescript": "^5.8.3"

lib/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# esbuild-raw-plugin
22

3+
## 0.3.1
4+
5+
### Patch Changes
6+
7+
- 6959695: fix: backward compatibility - add support for and deprecate the deprecated textExtensions field in raw plugin options
8+
39
## 0.3.0
410

511
### Minor Changes

lib/README.md

Lines changed: 111 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
11
# Esbuild Raw Plugin <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>
22

3-
[![test](https://github.com/react18-tools/esbuild-raw-plugin/actions/workflows/test.yml/badge.svg)](https://github.com/react18-tools/esbuild-raw-plugin/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/react18-tools/esbuild-raw-plugin/maintainability) [![codecov](https://codecov.io/gh/react18-tools/esbuild-raw-plugin/graph/badge.svg)](https://codecov.io/gh/react18-tools/esbuild-raw-plugin) [![Version](https://img.shields.io/npm/v/esbuild-raw-plugin.svg?colorB=green)](https://www.npmjs.com/package/esbuild-raw-plugin) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/esbuild-raw-plugin.svg)](https://www.npmjs.com/package/esbuild-raw-plugin) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/esbuild-raw-plugin) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/from-referrer/)
3+
[![test](https://github.com/react18-tools/esbuild-raw-plugin/actions/workflows/test.yml/badge.svg)](https://github.com/react18-tools/esbuild-raw-plugin/actions/workflows/test.yml)
4+
[![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/react18-tools/esbuild-raw-plugin/maintainability)
5+
[![codecov](https://codecov.io/gh/react18-tools/esbuild-raw-plugin/graph/badge.svg)](https://codecov.io/gh/react18-tools/esbuild-raw-plugin)
6+
[![Version](https://img.shields.io/npm/v/esbuild-raw-plugin.svg?colorB=green)](https://www.npmjs.com/package/esbuild-raw-plugin)
7+
[![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/esbuild-raw-plugin.svg)](https://www.npmjs.com/package/esbuild-raw-plugin)
8+
![npm bundle size](https://img.shields.io/bundlephobia/minzip/esbuild-raw-plugin)
9+
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/from-referrer/)
410

5-
**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.**
712

8-
> <img src="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+
> <img src="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.
917
1018
---
1119

12-
## Features
20+
## 🚀 Features
1321

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.
22+
> 🔥 Import any file as raw content with zero config in ESBuild or TSUP — text, base64, binary, docx templates & more!\
23+
> ⚡️ Fast, smart, and extensible → `esbuild-raw-plugin`
1724
18-
---
25+
- 🔧 Supports `?raw`, `?text`, `?base64`, `?dataurl`, `?binary`, and `?file` query suffixes
26+
- 🧠 Smart fallback to extensions like `.ts`, `.tsx`, `index.[ext]`, etc.
27+
- 🔍 Custom loader mapping (e.g., `module.scss``text`, `png``dataurl`)
28+
- ⚡ Ultra-fast using regex-based native `onLoad` filter (Go-native perf)
29+
- 🪶 Works seamlessly with both [Tsup](https://tsup.egoist.dev/) and [ESBuild](https://esbuild.github.io/)
1930

20-
## Installation
31+
---
2132

22-
Using npm:
33+
## 📦 Installation
2334

2435
```bash
2536
npm install esbuild-raw-plugin --save-dev
2637
```
2738

28-
Using yarn:
39+
_or_
2940

3041
```bash
3142
yarn add esbuild-raw-plugin --dev
3243
```
3344

34-
Using pnpm:
45+
_or_
3546

3647
```bash
3748
pnpm add esbuild-raw-plugin --save-dev
3849
```
3950

4051
---
4152

42-
## Usage
43-
44-
### ESBuild Configuration
53+
## 🛠 Usage
4554

46-
Add the plugin to your ESBuild configuration:
55+
### ➤ With ESBuild
4756

48-
```js
57+
```ts
4958
import { build } from "esbuild";
5059
import { raw } from "esbuild-raw-plugin";
5160

@@ -57,11 +66,9 @@ build({
5766
});
5867
```
5968

60-
### TSUP Configuration
61-
62-
Add the plugin to your TSUP configuration:
69+
### ➤ With TSUP
6370

64-
```js
71+
```ts
6572
import { defineConfig } from "tsup";
6673
import { raw } from "esbuild-raw-plugin";
6774

@@ -74,135 +81,141 @@ export default defineConfig({
7481

7582
---
7683

77-
## IDE Setup for IntelliSense and Type Checking
84+
## 🧠 TypeScript Support
7885

79-
Add the following to your declaration file. If you do not have one, create a `declarations.d.ts` file and add the following:
86+
Add this to your `declarations.d.ts` file:
8087

81-
```typescript
88+
```ts
8289
declare module "*?raw" {
83-
const value: string;
84-
export default value;
90+
const content: string;
91+
export default content;
8592
}
8693
```
8794

88-
## Importing Files as Raw Text
95+
> For other suffixes (`?base64`, `?binary`, etc.), add similar declarations if needed.
8996
90-
With the plugin enabled, you can import files as raw text directly:
97+
---
98+
99+
## 📥 Importing Raw Files
91100

92-
```js
93-
import myCode from "./example.js?raw";
101+
```ts
102+
import content from "./example.js?raw";
94103

95-
console.log(myCode);
96-
// Outputs the content of 'example.js' as a string.
104+
console.log(content); // Entire file content as string or Buffer
97105
```
98106

99-
### Good News:
107+
### ✅ Simplified Imports
100108

101-
With the latest update, you no longer need to specify the file extension explicitly.
109+
You don’t need to specify full filenames or extensions:
102110

103-
```js
104-
import myCode from "./example?raw";
111+
```ts
112+
import code from "./utils?raw"; // Resolves to utils/index.ts, utils.js, etc.
105113
```
106114

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:
115+
Great for:
108116

109-
```js
110-
import myCode from "./my-lib?raw";
111-
```
117+
- Library or folder-level imports
118+
- Auto-resolving `.ts`, `.tsx`, `.css`, `.scss`, etc.
119+
120+
---
112121

113-
### Extension Options (Optional)
122+
## ⚙️ Plugin Options
114123

115124
```ts
116125
export interface RawPluginOptions {
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]`.
120-
* @defaultValue ["tsx", "ts", "jsx", "js", "mjs", "mts", "module.css", "module.scss", "css", "scss"]
121-
*
122-
* You can provide your own extensions to optimize build performance or extend the list based on your use case.
123-
*/
124126
ext?: string[];
125-
126-
/**
127-
* Custom loader for file processing.
128-
* @defaultValue "text"
129-
*/
130127
loader?: "text" | "base64" | "dataurl" | "file" | "binary" | "default";
131-
132-
/**
133-
* Extensions to be treated as text files.
134-
*/
135-
textExtensions?: string[];
128+
customLoaders?: Record<string, "text" | "base64" | "dataurl" | "file" | "binary" | "default">;
129+
name?: string;
136130
}
137131
```
138132

139-
### Supported File Types
133+
<details>
134+
<summary><strong>🔧 Option Details</strong></summary>
140135

141-
You can use `?raw` with any file type, including:
136+
- `ext`: Extensions to resolve if the file or folder is missing. Defaults to common types like `ts`, `tsx`, `module.css`, etc.
137+
- `loader`: Default loader if no `?query` is specified. Usually `"text"`.
138+
- `customLoaders`: Per-extension loader mapping. Example:
142139

143-
- `.js`, `.ts`, `.jsx`, `.tsx`
144-
- `.css`, `.scss`
145-
- `.html`
146-
- `.md`
147-
- and more!
140+
```ts
141+
{
142+
"module.scss": "text",
143+
"png": "dataurl",
144+
"docx": "file"
145+
}
146+
```
148147

149-
---
148+
- `name`: Optional plugin name override for debugging or deduplication.
150149

151-
## Example Use Case
150+
</details>
152151

153-
### Live Code Preview with `react-live`
152+
---
154153

155-
```jsx
156-
import React from "react";
157-
import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live";
158-
import exampleCode from "./example.js?raw";
154+
## 🧪 Supported Query Loaders
159155

160-
const App = () => (
161-
<LiveProvider code={exampleCode}>
162-
<LiveEditor />
163-
<LiveError />
164-
<LivePreview />
165-
</LiveProvider>
166-
);
156+
Import with query-based syntax:
167157

168-
export default App;
158+
```ts
159+
import doc from "./readme.md?text";
160+
import logo from "./logo.png?base64";
161+
import wasm from "./core.wasm?binary";
169162
```
170163

171-
---
172-
173-
## Why Use `esbuild-raw-plugin`?
174-
175-
- Simplifies importing files as raw text for documentation and live previews.
176-
- Seamlessly integrates with modern build tools like ESBuild and TSUP.
177-
- Lightweight and easy to configure.
164+
| Query Suffix | Description |
165+
| ------------ | -------------------------------------------------- |
166+
| `?raw` | Uses the default loader (options.loader ?? "text") |
167+
| `?text` | Loads file as UTF-8 text |
168+
| `?base64` | Returns base64 string |
169+
| `?dataurl` | Returns full data URL |
170+
| `?file` | Emits file to output dir |
171+
| `?binary` | Returns raw `Buffer` |
178172

179173
---
180174

181-
## Keywords
175+
## 🧬 Use Case: Live Code Preview
176+
177+
```tsx
178+
import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live";
179+
import exampleCode from "./example.js?raw";
182180

183-
`esbuild`, `esbuild-plugin`, `tsup-plugin`, `raw-text-import`, `import-as-text`, `file-loader`, `react-live`, `documentation-tools`, `frontend-tooling`
181+
export default function LiveDemo() {
182+
return (
183+
<LiveProvider code={exampleCode}>
184+
<LiveEditor />
185+
<LiveError />
186+
<LivePreview />
187+
</LiveProvider>
188+
);
189+
}
190+
```
184191

185192
---
186193

187-
## Contributing
194+
## 🔍 Why Choose `esbuild-raw-plugin`?
188195

189-
Contributions are welcome!
190-
Feel free to open issues or pull requests to improve the plugin.
196+
- ✅ Works out of the box — no config needed
197+
- 📁 Handles smart file resolution
198+
- 💬 Excellent developer experience
199+
- 🧩 Supports both query-based and extension-based mappings
200+
- 🧪 Stable, fast, and production-tested
191201

192202
---
193203

194-
Let me know if you'd like further tweaks! 🚀
204+
## 🛠 Contributing
205+
206+
PRs and ideas welcome!
207+
Open an issue or submit a pull request to help improve the plugin.
195208

196209
![Alt](https://repobeats.axiom.co/api/embed/1ae166ef108b33b36ceaa60be208a5dafce25c5c.svg "Repobeats analytics image")
197210

198211
---
199212

200-
## License
213+
## 🧾 License
201214

202-
This library is licensed under the MPL-2.0 open-source license.
215+
Licensed under the **MPL-2.0** open-source license.
203216

204-
> <img src="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.
217+
> <img src="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.
205218
206-
<hr />
219+
---
207220

208221
<p align="center" style="text-align:center">with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>

0 commit comments

Comments
 (0)