-
-
Save paulogr/0fbdfbb1483f0580bdd0a4736a3a6e3f to your computer and use it in GitHub Desktop.
Flexible server side rendering script for Stencil when used in other platforms
This file contains hidden or 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
| // Put this file in a directory where @stencil/core exists in node_modules, then run: | |
| // $ echo $HTML | node ssr.js [root] [build-dir] [namespace] | |
| // Full example from my use case: | |
| // $ echo '<sam-text text="Hello, world"></sam-text>' | node ssr.js /var/www/stencil/sams-components/dist ../ sam | |
| // Pipes are used because HTML strings can be really long, and bash has limits on how large argument lists can get (~256k usually). | |
| var stencil = require('@stencil/core'); | |
| var args = process.argv.slice(2); | |
| if (args.length < 3) { | |
| console.error('Not enough args'); | |
| } | |
| var data = ''; | |
| process.stdin.resume(); | |
| process.stdin.setEncoding('utf8'); | |
| process.stdin.on('data', function(chunk) { | |
| data += chunk; | |
| }); | |
| process.stdin.on('end', function() { | |
| var renderer = stencil.createRenderer({ | |
| rootDir: args[0], | |
| buildDir: args[1], | |
| namespace: args[2] | |
| }); | |
| renderer.hydrateToString({ | |
| html: data | |
| }, function(results) { | |
| if (results.diagnostics.length) { | |
| console.error(results.diagnostics); | |
| } | |
| console.log(results.html); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment