Skip to content

Commit 1e5993f

Browse files
committed
init
1 parent 35e1d22 commit 1e5993f

32 files changed

+8362
-4
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414
.phpunit.result.cache
1515
/phpunit.xml
1616
###< symfony/phpunit-bridge ###
17+
18+
###> symfony/webpack-encore-bundle ###
19+
/node_modules/
20+
/public/build/
21+
npm-debug.log
22+
yarn-error.log
23+
###< symfony/webpack-encore-bundle ###

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sf-vue-ssr.iml

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/symfony2.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* User: Karol Krupa <[email protected]>
4+
* Date: 23/07/2020
5+
*/
6+
7+
namespace KarolKrupa\SymfonyVueSrrBundle;
8+
9+
10+
use Symfony\Component\HttpKernel\Bundle\Bundle;
11+
12+
class SymfonyVueSsrBundle extends Bundle
13+
{
14+
15+
}

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Symfony Twig + Vue components SSR (V8js/node) example
2+
3+
This is example of implementation server side rendering vue components in
4+
twig based on V8js (rendering in V8js is much faster than rendering in node.
5+
v8js renders the content within 30 ms, when the node taking about 300+ ms)
6+
7+
## Usage
8+
9+
```bash
10+
# build server side bundle
11+
$ npx webpack --config ssr.webpack.js --target node
12+
13+
# build client side bundle
14+
$ yarn encore dev
15+
```
16+
17+
#### Client side bundle
18+
19+
The most important thing is we have to update template string in client
20+
side script before building `assets/vue/vue.js`
21+
22+
A good solution would be to insert the template in the html script tag as global
23+
javascript variable. We must remember that the template should be
24+
passed to the client-side script after rendering in javascript it must be
25+
identical to the template inserted on the server to avoid warning
26+
about vue template mismatch

assets/css/app.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: lightgray;
3+
}

assets/js/app.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Welcome to your app's main JavaScript file!
3+
*
4+
* We recommend including the built version of this JavaScript file
5+
* (and its CSS file) in your base layout (base.html.twig).
6+
*/
7+
8+
// any CSS you import will output into a single css file (app.css in this case)
9+
import '../css/app.css';
10+
11+
// Need jQuery? Install it with "yarn add jquery", then uncomment to import it.
12+
// import $ from 'jquery';
13+
14+
console.log('Hello Webpack Encore! Edit me in assets/js/app.js');

assets/vue/TestComponent.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div>
3+
Counter: {{ counter }}
4+
<button @click="add">Add</button>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
name: "test-component",
11+
data() {
12+
return {
13+
counter: 0
14+
}
15+
},
16+
methods: {
17+
add() {
18+
this.counter++;
19+
}
20+
}
21+
}
22+
</script>
23+
24+
<style scoped>
25+
26+
</style>

assets/vue/vm.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Vue from 'vue'
2+
import TestComponent from "./TestComponent.vue";
3+
4+
let vm = new Vue({
5+
template: PHP.html,
6+
7+
components: {
8+
TestComponent
9+
}
10+
})
11+
12+
renderVueComponentToString(vm, (err, res) => {
13+
print(res)
14+
})

0 commit comments

Comments
 (0)