@primate/svelte 0.3.2 → 0.4.0
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 +15 -3
- package/package.json +5 -2
- package/src/module.js +42 -44
package/README.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
# Primate Svelte
|
|
1
|
+
# Primate Svelte module
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Install
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`npm i @primate/svelte`
|
|
6
|
+
|
|
7
|
+
## Configure
|
|
8
|
+
|
|
9
|
+
Add to `primate.config.js`
|
|
10
|
+
|
|
11
|
+
``js
|
|
12
|
+
import svelte from "@primate/svelte";
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
modules: [svelte()],
|
|
16
|
+
};
|
|
17
|
+
``
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"bugs": "https://github.com/primatejs/svelte/issues",
|
|
5
5
|
"repository": "https://github.com/primatejs/svelte",
|
|
6
|
-
"description": "Primate Svelte
|
|
6
|
+
"description": "Primate Svelte module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"runtime-compat": "^0.14.1",
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"maximin": "^0.1.2"
|
|
14
14
|
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"primate": "0.14.0"
|
|
17
|
+
},
|
|
15
18
|
"type": "module",
|
|
16
19
|
"exports": "./exports.js"
|
|
17
20
|
}
|
package/src/module.js
CHANGED
|
@@ -36,48 +36,46 @@ const handler = path => (component, props = {}, {status = 200} = {}) =>
|
|
|
36
36
|
}];
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
register
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
await
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}));
|
|
39
|
+
const {svelte, js} = endings;
|
|
40
|
+
export default directory => ({
|
|
41
|
+
register(env, next) {
|
|
42
|
+
env.register("svelte", handler(directory ?? env.paths.components));
|
|
43
|
+
return next(env);
|
|
44
|
+
},
|
|
45
|
+
async compile(env, next) {
|
|
46
|
+
const path = directory ?? env.paths.components;
|
|
47
|
+
const options = {generate: "ssr", hydratable: true};
|
|
48
|
+
const components = await path.list(filename => filename.endsWith(svelte));
|
|
49
|
+
await Promise.all(components.map(async component => {
|
|
50
|
+
const file = await component.file.read();
|
|
51
|
+
const server = compiler.compile(file, options);
|
|
52
|
+
const compiled = server.js.code.replaceAll(svelte, js);
|
|
53
|
+
await File.write(`${component.path}.js`, compiled);
|
|
54
|
+
}));
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
56
|
+
return next(env);
|
|
57
|
+
},
|
|
58
|
+
async publish(env, next) {
|
|
59
|
+
const path = directory ?? env.paths.components;
|
|
60
|
+
const options = {
|
|
61
|
+
generate: "dom",
|
|
62
|
+
hydratable: true,
|
|
63
|
+
css: false,
|
|
64
|
+
sveltePath: "./svelte",
|
|
65
|
+
};
|
|
66
|
+
const components = await path.list(filename => filename.endsWith(svelte));
|
|
67
|
+
const scriptPath = ["node_modules", "svelte", "internal", "index.mjs"];
|
|
68
|
+
// publish svelte itself
|
|
69
|
+
const code = await Path.resolve().join(...scriptPath).file.read();
|
|
70
|
+
await env.publish({src: "svelte/internal.js", code, type});
|
|
71
|
+
await Promise.all(components.map(async component => {
|
|
72
|
+
const file = await component.file.read();
|
|
73
|
+
const client = compiler.compile(file, options);
|
|
74
|
+
const compiled = client.js.code
|
|
75
|
+
.replaceAll(svelte, js)
|
|
76
|
+
.replace("./svelte/internal", "./svelte/internal.js");
|
|
77
|
+
await env.publish({src: `${component.name}.js`, code: compiled, type});
|
|
78
|
+
}));
|
|
79
|
+
return next(env);
|
|
80
|
+
},
|
|
81
|
+
});
|