@web-remarq/unplugin 0.0.1 → 0.0.2
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 +154 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @web-remarq/unplugin
|
|
2
|
+
|
|
3
|
+
Universal build plugin that injects source location attributes into JSX and Vue template elements for [web-remarq](https://www.npmjs.com/package/web-remarq).
|
|
4
|
+
|
|
5
|
+
Works with Vite, webpack, Rollup, esbuild, and Rspack. Supports JSX/TSX and Vue SFC templates.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -D @web-remarq/unplugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
### Vite
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// vite.config.js
|
|
19
|
+
import remarq from '@web-remarq/unplugin/vite'
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
plugins: [remarq()]
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### webpack
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// webpack.config.js
|
|
30
|
+
const remarq = require('@web-remarq/unplugin/webpack').default
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
plugins: [remarq()]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Rollup
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// rollup.config.js
|
|
41
|
+
import remarq from '@web-remarq/unplugin/rollup'
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
plugins: [remarq()]
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### esbuild
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import remarq from '@web-remarq/unplugin/esbuild'
|
|
52
|
+
import { build } from 'esbuild'
|
|
53
|
+
|
|
54
|
+
build({
|
|
55
|
+
plugins: [remarq()]
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Rspack
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
// rspack.config.js
|
|
63
|
+
const remarq = require('@web-remarq/unplugin/rspack').default
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
plugins: [remarq()]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## What it does
|
|
71
|
+
|
|
72
|
+
Transforms this:
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
function LoginForm() {
|
|
76
|
+
return <button className="submit">Log in</button>
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Into this:
|
|
81
|
+
|
|
82
|
+
```jsx
|
|
83
|
+
function LoginForm() {
|
|
84
|
+
return <button className="submit"
|
|
85
|
+
data-remarq-source="src/components/LoginForm.tsx:3:9"
|
|
86
|
+
data-remarq-component="LoginForm">Log in</button>
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Vue SFC templates are also transformed:
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
<template>
|
|
94
|
+
<div class="wrapper">
|
|
95
|
+
<button>Save</button>
|
|
96
|
+
</div>
|
|
97
|
+
</template>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Becomes:
|
|
101
|
+
|
|
102
|
+
```vue
|
|
103
|
+
<template>
|
|
104
|
+
<div class="wrapper"
|
|
105
|
+
data-remarq-source="src/components/SavePanel.vue:2:4"
|
|
106
|
+
data-remarq-component="SavePanel">
|
|
107
|
+
<button
|
|
108
|
+
data-remarq-source="src/components/SavePanel.vue:3:8"
|
|
109
|
+
data-remarq-component="SavePanel">Save</button>
|
|
110
|
+
</div>
|
|
111
|
+
</template>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Options
|
|
115
|
+
|
|
116
|
+
| Option | Type | Default | Description |
|
|
117
|
+
|--------|------|---------|-------------|
|
|
118
|
+
| `include` | `string[]` | `['**/*.jsx', '**/*.tsx', '**/*.vue']` | Glob patterns for files to transform |
|
|
119
|
+
| `exclude` | `string[]` | `['node_modules/**']` | Glob patterns to skip |
|
|
120
|
+
| `production` | `boolean` | `false` | Enable in production builds |
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
remarq({
|
|
124
|
+
include: ['src/**/*.tsx', 'src/**/*.vue'],
|
|
125
|
+
exclude: ['node_modules/**', '**/*.test.*'],
|
|
126
|
+
production: false,
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Security note:** `production: true` exposes source file paths in the DOM. Use only for internal/staging environments.
|
|
131
|
+
|
|
132
|
+
## JSX/TSX
|
|
133
|
+
|
|
134
|
+
Uses `@babel/parser` for AST-based transformation. Handles TypeScript, decorators, and all JSX patterns. Component name is detected from the nearest function/class declaration.
|
|
135
|
+
|
|
136
|
+
## Vue SFC
|
|
137
|
+
|
|
138
|
+
Parses `<template>` blocks and injects attributes on HTML elements. Vue built-in tags (`template`, `slot`, `component`, `transition`, `keep-alive`, `teleport`, `suspense`) are skipped. Component name is derived from the filename.
|
|
139
|
+
|
|
140
|
+
## How it differs from `@web-remarq/babel-plugin`
|
|
141
|
+
|
|
142
|
+
| | `@web-remarq/babel-plugin` | `@web-remarq/unplugin` |
|
|
143
|
+
|-|---|---|
|
|
144
|
+
| **Use when** | Project uses Babel | Project uses Vite/SWC/esbuild without Babel |
|
|
145
|
+
| **Bundlers** | Babel only | Vite, webpack, Rollup, esbuild, Rspack |
|
|
146
|
+
| **JSX** | Yes | Yes |
|
|
147
|
+
| **Vue SFC** | No | Yes |
|
|
148
|
+
| **Parsing** | Babel AST (native) | `@babel/parser` (bundled) |
|
|
149
|
+
|
|
150
|
+
If your project already uses Babel, prefer `@web-remarq/babel-plugin` — it's lighter and integrates natively.
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|