@mapl/web 0.3.0 → 0.3.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 +23 -44
- package/build/rolldown.d.ts +31 -0
- package/build/rolldown.js +19 -0
- package/package.json +10 -12
package/README.md
CHANGED
|
@@ -32,11 +32,13 @@ export default {
|
|
|
32
32
|
## AOT compilation (experimental)
|
|
33
33
|
Build `@mapl/web` to improve startup time.
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
### Rolldown
|
|
36
|
+
Dependencies: `rolldown`, `@rollup/plugin-terser`.
|
|
36
37
|
```ts
|
|
37
38
|
// main.ts
|
|
38
39
|
import { handle, layer, router } from '@mapl/web';
|
|
39
40
|
|
|
41
|
+
// Main app
|
|
40
42
|
export default router(
|
|
41
43
|
[
|
|
42
44
|
layer.tap((c) => {
|
|
@@ -53,52 +55,29 @@ export default router(
|
|
|
53
55
|
},
|
|
54
56
|
);
|
|
55
57
|
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
import { compileToDependency } from '@mapl/web/compiler/jit';
|
|
59
|
-
import { evaluateToString } from "runtime-compiler/jit";
|
|
58
|
+
// Additional options
|
|
59
|
+
export const serveOptions = {};
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
// build.ts
|
|
62
62
|
import terser from '@rollup/plugin-terser';
|
|
63
|
+
import build from '@mapl/web/build/rolldown';
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
import { getDependency } from 'runtime-compiler';
|
|
82
|
-
export default {
|
|
83
|
-
fetch: getDependency(${HANDLER})
|
|
84
|
-
};`,
|
|
85
|
-
);
|
|
86
|
-
const input = await rolldown({
|
|
87
|
-
input: ENTRY,
|
|
88
|
-
plugins: [
|
|
89
|
-
terser({
|
|
90
|
-
module: true,
|
|
91
|
-
mangle: false,
|
|
92
|
-
compress: {
|
|
93
|
-
// passes should be at least 2, recommend 3 - 5
|
|
94
|
-
passes: 3,
|
|
95
|
-
},
|
|
96
|
-
}),
|
|
97
|
-
],
|
|
98
|
-
});
|
|
99
|
-
await input.write({
|
|
100
|
-
file: ENTRY,
|
|
101
|
-
inlineDynamicImports: true,
|
|
65
|
+
build({
|
|
66
|
+
input: INPUT,
|
|
67
|
+
output: {
|
|
68
|
+
file: OUTPUT,
|
|
69
|
+
},
|
|
70
|
+
finalizeOptions: {
|
|
71
|
+
plugins: [
|
|
72
|
+
terser({
|
|
73
|
+
compress: {
|
|
74
|
+
// passes should be >= 2
|
|
75
|
+
passes: 3,
|
|
76
|
+
},
|
|
77
|
+
mangle: false,
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
102
81
|
});
|
|
103
82
|
```
|
|
104
83
|
As of rn only `terser` can DCE `@mapl/web` patterns.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type BuildOptions, type OutputOptions } from "rolldown";
|
|
2
|
+
export interface MaplBuildOptions {
|
|
3
|
+
/**
|
|
4
|
+
* App entry point
|
|
5
|
+
*/
|
|
6
|
+
input: string;
|
|
7
|
+
/**
|
|
8
|
+
* Output options
|
|
9
|
+
*/
|
|
10
|
+
output: Omit<OutputOptions, "dir"> & {
|
|
11
|
+
file: string
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* App build options
|
|
15
|
+
*/
|
|
16
|
+
buildOptions?: Omit<BuildOptions, "input" | "output">;
|
|
17
|
+
/**
|
|
18
|
+
* App output build options
|
|
19
|
+
*/
|
|
20
|
+
finalizeOptions?: Omit<BuildOptions, "input" | "output">;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to emit asynchronous output
|
|
23
|
+
*/
|
|
24
|
+
asynchronous?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Build target
|
|
27
|
+
*/
|
|
28
|
+
target?: "bun";
|
|
29
|
+
}
|
|
30
|
+
declare const _default: (opts: MaplBuildOptions) => Promise<void>;
|
|
31
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{writeFileSync}from"node:fs";import{build}from"rolldown";import{compileToExportedDependency as generic}from"../compiler/jit.js";import{compileToExportedDependency as bun}from"../compiler/bun/jit.js";import{evaluateToString}from"runtime-compiler/jit";import{clear}from"runtime-compiler";export default async opts=>{let output=opts.output;let input=opts.input;await build({...opts.buildOptions,input,output:{file:output.file}});let appMod=await import(output.file);let HANDLER=(opts.target===`bun`?bun:generic)(appMod.default);writeFileSync(output.file,`
|
|
2
|
+
import 'runtime-compiler/hydrate-loader';
|
|
3
|
+
|
|
4
|
+
import app, { serveOptions } from ${JSON.stringify(input)};
|
|
5
|
+
import hydrateRouter from '@mapl/web/compiler/${opts.target===`bun`?`bun/`:``}aot';
|
|
6
|
+
hydrateRouter(app);
|
|
7
|
+
|
|
8
|
+
import { hydrate } from 'runtime-compiler/hydrate';
|
|
9
|
+
import { getDependency } from 'runtime-compiler';
|
|
10
|
+
|
|
11
|
+
${opts.asynchronous?`await(async`:`(`}${evaluateToString()})(...hydrate());
|
|
12
|
+
${opts.target===`bun`?`Bun.serve({
|
|
13
|
+
routes: getDependency(${HANDLER}),
|
|
14
|
+
...serveOptions
|
|
15
|
+
});`:`export default {
|
|
16
|
+
fetch: getDependency(${HANDLER}),
|
|
17
|
+
...serveOptions
|
|
18
|
+
};`}
|
|
19
|
+
`);clear();await build({...opts.finalizeOptions??opts.buildOptions,input:output.file,output})};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -17,24 +17,22 @@
|
|
|
17
17
|
"@safe-std/error": "^1.0.1",
|
|
18
18
|
"runtime-compiler": "^1.2.5"
|
|
19
19
|
},
|
|
20
|
-
"optionalDependencies": {
|
|
21
|
-
"secure-headers": "^0.0.6"
|
|
22
|
-
},
|
|
23
20
|
"exports": {
|
|
24
21
|
"./constants": "./constants.js",
|
|
25
|
-
".": "./index.js",
|
|
26
|
-
"./core/middleware": "./core/middleware.js",
|
|
27
|
-
"./core/utils": "./core/utils.js",
|
|
28
22
|
"./utils/static-headers": "./utils/static-headers.js",
|
|
23
|
+
".": "./index.js",
|
|
24
|
+
"./compiler/jit": "./compiler/jit.js",
|
|
25
|
+
"./build/rolldown": "./build/rolldown.js",
|
|
29
26
|
"./utils/cors": "./utils/cors.js",
|
|
30
27
|
"./compiler/aot": "./compiler/aot.js",
|
|
31
|
-
"./core/handler": "./core/handler.js",
|
|
32
28
|
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
33
|
-
"./compiler/bun/jit": "./compiler/bun/jit.js",
|
|
34
|
-
"./compiler/jit": "./compiler/jit.js",
|
|
35
|
-
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
36
29
|
"./core": "./core/index.js",
|
|
30
|
+
"./core/context": "./core/context.js",
|
|
31
|
+
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
32
|
+
"./core/middleware": "./core/middleware.js",
|
|
33
|
+
"./core/handler": "./core/handler.js",
|
|
34
|
+
"./core/utils": "./core/utils.js",
|
|
37
35
|
"./compiler/bun/aot": "./compiler/bun/aot.js",
|
|
38
|
-
"./
|
|
36
|
+
"./compiler/bun/jit": "./compiler/bun/jit.js"
|
|
39
37
|
}
|
|
40
38
|
}
|