Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.tag.html extension for server-side rendered tags #57

Open
tas12 opened this issue Dec 5, 2016 · 5 comments
Open

.tag.html extension for server-side rendered tags #57

tas12 opened this issue Dec 5, 2016 · 5 comments

Comments

@tas12
Copy link

tas12 commented Dec 5, 2016

Thank you for sharing this style guide

Is there a way to use the .tag.html extension when using the riot.render() method in the server?

Example from http://riotjs.com/guide/#server-side-rendering:

var riot = require('riot')
var timer = require('timer.tag')

var html = riot.render(timer, { start: 42 })

console.log(html) // <timer><p>Seconds Elapsed: 42</p></timer>

I would like to 'require' a riot tag with .tag.html ext but this causes an error when starting the server

@petergoes
Copy link
Contributor

Hi Tas12,

My solution was to let riot first compile the tag into a .js file, and require that .js file in your server side code. I made a (very basic) proof of concept here: riot-serverside-rendering

I don't know if this is the 'official' way to do it, but thats how I got it to work.

@phortuin
Copy link
Member

phortuin commented Dec 6, 2016

@tas12 Could your issue be similar to this: #6 (comment)? In that case, you probably should omit the .html extension!

@tas12
Copy link
Author

tas12 commented Dec 7, 2016

@petergoes @phortuin thanks for your helpful responses! I also thought of these solutions and went with omitting the .html extension for server-side rendered tags. I guess this would just have to be documented clearly in a readme. For me, pre-compiling would an extra step on top of bundling frontend js and compiling scss files. Is it worth adding a note in the style guide?

@petergoes
Copy link
Contributor

As long as riot does not support custom extensions in server side rendering, I do think it is worth adding it to the guide.

@jbmoelker
Copy link
Member

@tas12 @petergoes @phortuin You can use require('timer.tag') after requiring riot as riot extends require to support .tag files:

require.extensions['.tag'] = function(module, filename) {
  loadAndCompile(filename, {}, module)
}

However, you can also simply use the require method exposed on riot itself:

// instead of
var riot = require('riot')
var timer = require('timer.tag')

// use
var riot = require('riot')
var timer = riot.require('timer.tag.html')

@petergoes maybe you can test this and change this in #59, to simply say that if you want to use riot server-side, use riot.require('filename.tag.html').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants