Created
January 16, 2018 14:42
-
-
Save CaptainJojo/873515633265a2c266073caad630445b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import App from './components/App.vue'; | |
import Vue from 'vue'; | |
export function createApp() { | |
return new Vue({ | |
render: h => h(App) | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Route("/") | |
*/ | |
public function home() | |
{ | |
$ssr = $this->renderJs(); | |
return $this->render('home.html.twig', ['ssr' => $ssr]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createApp } from './app' | |
createApp().$mount('#app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createApp } from './app' | |
renderVueComponentToString(createApp(), (err, res) => { | |
print(res); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>{% block title %}Welcome!{% endblock %}</title> | |
{% block stylesheets %}{% endblock %} | |
</head> | |
<body> | |
{% block body %} | |
{{ ssr|raw }} | |
{% endblock %} | |
{% block javascripts %} | |
{% endblock %} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function renderJs() | |
{ | |
$renderer_source = file_get_contents(__DIR__ . '/../../node_modules/vue-server-renderer/basic.js'); | |
$app_source = file_get_contents(__DIR__ . '/../../public/build/entry-server.js'); | |
$v8 = new \V8Js(); | |
ob_start(); | |
$v8->executeString('var process = { env: { VUE_ENV: "server", NODE_ENV: "production" }}; this.global = { process: process };'); | |
$v8->executeString($renderer_source); | |
$v8->executeString($app_source); | |
return ob_get_clean(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Encore = require('@symfony/webpack-encore'); | |
Encore | |
// the project directory where compiled assets will be stored | |
.setOutputPath('public/build/') | |
// the public path used by the web server to access the previous directory | |
.setPublicPath('/build') | |
.addEntry('entry-client', './assets/js/entry-client.js') | |
.addEntry('entry-server', './assets/js/entry-server.js') | |
.cleanupOutputBeforeBuild() | |
.enableSourceMaps(!Encore.isProduction()) | |
.enableVueLoader() | |
; | |
module.exports = Encore.getWebpackConfig(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment