@mapl/web 0.3.0 → 0.3.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/README.md +17 -43
- package/build/rolldown.d.ts +13 -0
- package/build/rolldown.js +19 -0
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -54,51 +54,25 @@ export default router(
|
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
// build.ts
|
|
57
|
-
import app from './main.ts';
|
|
58
|
-
import { compileToDependency } from '@mapl/web/compiler/jit';
|
|
59
|
-
import { evaluateToString } from "runtime-compiler/jit";
|
|
60
|
-
|
|
61
|
-
import { rolldown } from "rolldown";
|
|
62
57
|
import terser from '@rollup/plugin-terser';
|
|
58
|
+
import build from '@mapl/web/build/rolldown';
|
|
63
59
|
|
|
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,
|
|
60
|
+
build({
|
|
61
|
+
input: INPUT,
|
|
62
|
+
output: {
|
|
63
|
+
file: OUTPUT,
|
|
64
|
+
},
|
|
65
|
+
finalizeOptions: {
|
|
66
|
+
plugins: [
|
|
67
|
+
terser({
|
|
68
|
+
compress: {
|
|
69
|
+
// passes should be >= 2, recommend 3
|
|
70
|
+
passes: 3,
|
|
71
|
+
},
|
|
72
|
+
mangle: false,
|
|
73
|
+
}),
|
|
74
|
+
],
|
|
75
|
+
},
|
|
102
76
|
});
|
|
103
77
|
```
|
|
104
78
|
As of rn only `terser` can DCE `@mapl/web` patterns.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type BuildOptions, type OutputOptions } from "rolldown";
|
|
2
|
+
export interface MaplBuildOptions {
|
|
3
|
+
input: string;
|
|
4
|
+
output: Omit<OutputOptions, "dir"> & {
|
|
5
|
+
file: string
|
|
6
|
+
};
|
|
7
|
+
buildOptions?: Omit<BuildOptions, "input" | "output">;
|
|
8
|
+
finalizeOptions?: Omit<BuildOptions, "input" | "output">;
|
|
9
|
+
asynchronous?: boolean;
|
|
10
|
+
target?: "bun";
|
|
11
|
+
}
|
|
12
|
+
declare const _default: (opts: MaplBuildOptions) => Promise<void>;
|
|
13
|
+
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.1",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -22,19 +22,20 @@
|
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
"./constants": "./constants.js",
|
|
25
|
+
"./core": "./core/index.js",
|
|
25
26
|
".": "./index.js",
|
|
27
|
+
"./core/context": "./core/context.js",
|
|
28
|
+
"./core/handler": "./core/handler.js",
|
|
26
29
|
"./core/middleware": "./core/middleware.js",
|
|
27
30
|
"./core/utils": "./core/utils.js",
|
|
28
31
|
"./utils/static-headers": "./utils/static-headers.js",
|
|
32
|
+
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
29
33
|
"./utils/cors": "./utils/cors.js",
|
|
34
|
+
"./build/rolldown": "./build/rolldown.js",
|
|
35
|
+
"./compiler/jit": "./compiler/jit.js",
|
|
30
36
|
"./compiler/aot": "./compiler/aot.js",
|
|
31
|
-
"./core/handler": "./core/handler.js",
|
|
32
|
-
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
33
37
|
"./compiler/bun/jit": "./compiler/bun/jit.js",
|
|
34
|
-
"./compiler/jit": "./compiler/jit.js",
|
|
35
38
|
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
36
|
-
"./
|
|
37
|
-
"./compiler/bun/aot": "./compiler/bun/aot.js",
|
|
38
|
-
"./core/context": "./core/context.js"
|
|
39
|
+
"./compiler/bun/aot": "./compiler/bun/aot.js"
|
|
39
40
|
}
|
|
40
41
|
}
|