@reckona/mreact-vite 0.0.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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/diagnostics.d.ts +3 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +7 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +15 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +68 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tatsuo Kaniwa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @reckona/mreact-vite
|
|
2
|
+
|
|
3
|
+
`@reckona/mreact-vite` is the lower-level Vite plugin for compiling mreact
|
|
4
|
+
modules. It wires the mreact compiler into Vite transforms.
|
|
5
|
+
|
|
6
|
+
## Basic Usage
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { defineConfig } from "vite";
|
|
10
|
+
import { modularReact } from "@reckona/mreact-vite";
|
|
11
|
+
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
plugins: [modularReact()],
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Options
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
modularReact({
|
|
21
|
+
include: [/\.mreact\.tsx$/],
|
|
22
|
+
target: "client",
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Notes
|
|
27
|
+
|
|
28
|
+
For app-router projects, prefer `mreactRouter()` from
|
|
29
|
+
`@reckona/mreact-router/vite`. That plugin owns route discovery, dev middleware,
|
|
30
|
+
client bundle inference, and production builds. Use this package when you need
|
|
31
|
+
the compiler transform without the app router.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,UAAU,GACrB,MAAM,CAOR"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function formatDiagnostic(filename, diagnostic) {
|
|
2
|
+
const loc = diagnostic.loc === undefined
|
|
3
|
+
? ""
|
|
4
|
+
: `:${diagnostic.loc.line}:${diagnostic.loc.column}`;
|
|
5
|
+
return `${filename}${loc} [${diagnostic.code}] ${diagnostic.message}`;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAC9B,QAAgB,EAChB,UAAsB;IAEtB,MAAM,GAAG,GACP,UAAU,CAAC,GAAG,KAAK,SAAS;QAC1B,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;IAEzD,OAAO,GAAG,QAAQ,GAAG,GAAG,KAAK,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC;AACxE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ClientReferenceMetadata, type ServerBootstrapMode, type ServerOutputMode } from "@reckona/mreact-compiler";
|
|
2
|
+
import type { Plugin } from "vite";
|
|
3
|
+
export interface ModularReactViteOptions {
|
|
4
|
+
include?: RegExp;
|
|
5
|
+
mode?: "reactive" | "compat";
|
|
6
|
+
serverOutput?: ServerOutputMode;
|
|
7
|
+
serverBootstrap?: ServerBootstrapMode;
|
|
8
|
+
serverBootstrapNonce?: string | (() => string);
|
|
9
|
+
serverBootstrapSrc?: string;
|
|
10
|
+
serverHydration?: boolean;
|
|
11
|
+
reactSuspenseRevealScriptSrc?: string;
|
|
12
|
+
onFlightClientReferences?: (filename: string, entries: ClientReferenceMetadata[]) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function modularReact(options?: ModularReactViteOptions): Plugin;
|
|
15
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAEtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC7B,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,oBAAoB,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IAC/C,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,wBAAwB,CAAC,EAAE,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,uBAAuB,EAAE,KAC/B,IAAI,CAAC;CACX;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,uBAA4B,GAAG,MAAM,CA4E1E"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { transform as compile, } from "@reckona/mreact-compiler";
|
|
2
|
+
import { formatDiagnostic } from "./diagnostics.js";
|
|
3
|
+
export function modularReact(options = {}) {
|
|
4
|
+
const include = options.include ?? /\.[cm]?[jt]sx$/;
|
|
5
|
+
return {
|
|
6
|
+
name: "modular-react",
|
|
7
|
+
enforce: "pre",
|
|
8
|
+
transform(code, id, transformOptions) {
|
|
9
|
+
const filename = stripQuery(id);
|
|
10
|
+
if (!include.test(filename)) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const input = {
|
|
14
|
+
code,
|
|
15
|
+
filename,
|
|
16
|
+
target: transformOptions?.ssr === true ? "server" : "client",
|
|
17
|
+
dev: this.environment?.mode === "dev",
|
|
18
|
+
};
|
|
19
|
+
if (options.mode !== undefined) {
|
|
20
|
+
input.mode = options.mode;
|
|
21
|
+
}
|
|
22
|
+
if (transformOptions?.ssr === true && options.serverOutput !== undefined) {
|
|
23
|
+
input.serverOutput = options.serverOutput;
|
|
24
|
+
}
|
|
25
|
+
if (transformOptions?.ssr === true && options.serverBootstrap !== undefined) {
|
|
26
|
+
input.serverBootstrap = options.serverBootstrap;
|
|
27
|
+
}
|
|
28
|
+
if (transformOptions?.ssr === true && options.serverBootstrapNonce !== undefined) {
|
|
29
|
+
input.serverBootstrapNonce =
|
|
30
|
+
typeof options.serverBootstrapNonce === "function"
|
|
31
|
+
? options.serverBootstrapNonce()
|
|
32
|
+
: options.serverBootstrapNonce;
|
|
33
|
+
}
|
|
34
|
+
if (transformOptions?.ssr === true && options.serverBootstrapSrc !== undefined) {
|
|
35
|
+
input.serverBootstrapSrc = options.serverBootstrapSrc;
|
|
36
|
+
}
|
|
37
|
+
if (transformOptions?.ssr === true && options.serverHydration !== undefined) {
|
|
38
|
+
input.serverHydration = options.serverHydration;
|
|
39
|
+
}
|
|
40
|
+
if (transformOptions?.ssr === true && options.reactSuspenseRevealScriptSrc !== undefined) {
|
|
41
|
+
input.reactSuspenseRevealScriptSrc = options.reactSuspenseRevealScriptSrc;
|
|
42
|
+
}
|
|
43
|
+
const output = compile(input);
|
|
44
|
+
if (transformOptions?.ssr === true &&
|
|
45
|
+
output.metadata.clientReferenceManifest !== undefined) {
|
|
46
|
+
options.onFlightClientReferences?.(filename, output.metadata.clientReferenceManifest);
|
|
47
|
+
}
|
|
48
|
+
for (const diagnostic of output.diagnostics) {
|
|
49
|
+
const message = formatDiagnostic(filename, diagnostic);
|
|
50
|
+
if (diagnostic.level === "error") {
|
|
51
|
+
this.error(message);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.warn(message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
code: output.code,
|
|
59
|
+
map: output.map ?? null,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function stripQuery(id) {
|
|
65
|
+
const queryIndex = id.indexOf("?");
|
|
66
|
+
return queryIndex === -1 ? id : id.slice(0, queryIndex);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,OAAO,GAKrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAiBpD,MAAM,UAAU,YAAY,CAAC,UAAmC,EAAE;IAChE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAC;IAEpD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,IAAI,EAAE,EAAE,EAAE,gBAAgB;YAClC,MAAM,QAAQ,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;YAEhC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5B,OAAO,IAAI,CAAC;YACd,C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0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reckona/mreact-vite",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Vite plugin for compiling mreact modules.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"compiler",
|
|
7
|
+
"jsx",
|
|
8
|
+
"mreact",
|
|
9
|
+
"plugin",
|
|
10
|
+
"typescript",
|
|
11
|
+
"vite"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/t-k/mreact/tree/main/packages/vite-plugin#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/t-k/mreact/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/t-k/mreact.git",
|
|
21
|
+
"directory": "packages/vite-plugin"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist/**/*.js",
|
|
25
|
+
"dist/**/*.js.map",
|
|
26
|
+
"dist/**/*.d.ts",
|
|
27
|
+
"dist/**/*.d.ts.map"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@reckona/mreact-compiler": "0.0.1"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"vite": ">=8 <9"
|
|
46
|
+
}
|
|
47
|
+
}
|