jedireza / hapi-react-views

:package: A hapi view engine for React components
MIT License
231 stars 33 forks source link

Possibility to use .js extension for views #22

Closed bbondy closed 9 years ago

bbondy commented 9 years ago

Wondering if it's already possible, or if not if it could be made possible to use .js for view extensions. I prefer to transpile my code and babel renames the .jsx to .js in the output directory. I run my server from the dist transpiled directory.

I'm working around it currently with a separate gulp task that uses gulp-extname to force a .jsx extension in the output directory, but it'd be much cleaner if I could just use .js to begin with and have server.render find the .js view.

Thanks for the great project by the way!

jedireza commented 9 years ago

Thanks for creating an issue. There is an option you can pass useNodeJsx, which defaults to true. When false we'll skip using node-jsx. Then you could try something like:

server.views({
    engines: {
        js: require('hapi-react-views') // note the key is js instead of jsx
    },
    relativeTo: __dirname,
    useNodeJsx: false,
    path: 'views'
});

I haven't tested this myself, but I'm guessing it could work.

bbondy commented 9 years ago

Thank you, I verified this works! For useNodeJsx I got:

[1] "useNodeJsx" is not allowed

But without it, it worked fine. I guess the missing part was just using a js key instead of jsx

abritinthebay commented 8 years ago

for reference - this is what I'm using and it works fine:

server.views({
    engines: {
        js: require("hapi-react-views")
    },
    compileOptions: {
        renderMethod: "renderToString",
        useNodeJsx: false
    },
    relativeTo: __dirname,
    path: "./components"
});