@primate/vue 0.4.0 → 0.6.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 +4 -45
- package/package.json +5 -5
- package/src/module.js +16 -14
package/README.md
CHANGED
|
@@ -1,47 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This handler module supports SSR and serves Vue SFC components with the .vue
|
|
4
|
+
extension.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Configure
|
|
8
|
-
|
|
9
|
-
Add to `primate.config.js`
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
import vue from "@primate/vue";
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
modules: [vue()],
|
|
16
|
-
};
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Use
|
|
20
|
-
|
|
21
|
-
Create a [SFC][sfc] component in `components`, e.g. `PostIndex.vue`.
|
|
22
|
-
|
|
23
|
-
```vue
|
|
24
|
-
<template>
|
|
25
|
-
<h1>All posts</h1>
|
|
26
|
-
<div v-for="post in posts">
|
|
27
|
-
<h2><a :href="`/vue/post/view/${post.id}`">{{post.title}}</a></h2>
|
|
28
|
-
</div>
|
|
29
|
-
</template>
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Create a route, for example in `routes/vue.js` (mapping `/vue`).
|
|
33
|
-
|
|
34
|
-
```js
|
|
35
|
-
import {view} from "primate";
|
|
36
|
-
|
|
37
|
-
const posts = [{
|
|
38
|
-
id: 1,
|
|
39
|
-
title: "First post",
|
|
40
|
-
}];
|
|
41
|
-
|
|
42
|
-
export default {
|
|
43
|
-
get() {
|
|
44
|
-
return view("PostIndex.vue", {posts});
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
```
|
|
6
|
+
## [Documentation](https://primatejs.com/modules/vue)
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Primate Vue module",
|
|
5
5
|
"homepage": "https://primatejs.com/modules/vue",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
9
|
-
"src
|
|
9
|
+
"src/**/*.js",
|
|
10
10
|
"!src/**/*.spec.js"
|
|
11
11
|
],
|
|
12
12
|
"repository": {
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"directory": "packages/vue"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"runtime-compat": "^0.
|
|
19
|
-
"vue": "^3.3.
|
|
18
|
+
"runtime-compat": "^0.20.2",
|
|
19
|
+
"vue": "^3.3.4"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"primate": "0.
|
|
22
|
+
"primate": "0.20"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
25
|
"main": "./src/exports.js"
|
package/src/module.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import {createSSRApp} from "vue";
|
|
2
2
|
import {renderToString} from "vue/server-renderer";
|
|
3
3
|
import {parse} from "vue/compiler-sfc";
|
|
4
|
-
import {File} from "runtime-compat/fs";
|
|
5
4
|
|
|
6
5
|
const render = (template, props) => {
|
|
7
6
|
const app = createSSRApp({data: () => props, template});
|
|
8
7
|
return renderToString(app);
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
const handler =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const handler = _ => (name, props = {}, {status = 200} = {}) => async app => {
|
|
11
|
+
const {paths, config} = app;
|
|
12
|
+
const target = paths.server.join(config.build.app).join(`${name}.js`);
|
|
13
|
+
const body = await render(await target.text(), props);
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
// -> spread into new Response()
|
|
16
|
+
return [await app.render({body}), {
|
|
17
|
+
status,
|
|
18
|
+
headers: {...app.headers(), "Content-Type": "text/html"},
|
|
19
|
+
}];
|
|
20
|
+
};
|
|
22
21
|
|
|
23
22
|
export default ({directory} = {}) => ({
|
|
24
23
|
name: "@primate/vue",
|
|
@@ -27,13 +26,16 @@ export default ({directory} = {}) => ({
|
|
|
27
26
|
return next(app);
|
|
28
27
|
},
|
|
29
28
|
async compile(app, next) {
|
|
29
|
+
const source = directory ?? app.paths.components;
|
|
30
|
+
const target = app.paths.server.join(app.config.build.app);
|
|
31
|
+
await target.file.create();
|
|
30
32
|
const vue = ".vue";
|
|
31
|
-
const
|
|
32
|
-
const components = await path.list(filename => filename.endsWith(vue));
|
|
33
|
+
const components = await source.list(filename => filename.endsWith(vue));
|
|
33
34
|
await Promise.all(components.map(async component => {
|
|
34
35
|
const file = await component.file.read();
|
|
35
36
|
const {descriptor} = parse(file);
|
|
36
|
-
|
|
37
|
+
const to = target.join(`${component.path}.js`.replace(source, ""));
|
|
38
|
+
await to.file.write(descriptor.template.content);
|
|
37
39
|
}));
|
|
38
40
|
|
|
39
41
|
return next(app);
|