jedireza / hapi-react-views

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

How to use babel as the jsx-transformer? #27

Closed Gnimuc closed 9 years ago

Gnimuc commented 9 years ago

the doc says when using another jsx-transformer instead of node-jsx, one should set useNodeJsx to false.

i want to use babel as the transformer, my configuration looks like this:

'visionary': {
            engines: {
                jsx: 'hapi-react-views'
            },
            compileOptions: { useNodeJsx: false },
            relativeTo: __dirname,
            path: './server/views'
        }

i simply added require(babel/register) at the top of home.jsx, then this error occurred.

Debug: internal, implementation, error 
    /Users/gnimuc/Documents/test/server/views/home.jsx:25
            <div className="commentBox">
            ^
SyntaxError: Unexpected token <

i guess this is not the correct way to change the jsx-transformer.

i'm very new to nodejs, sorry for disturbing.

jedireza commented 9 years ago

Thanks for opening an issue. When working on #19, the goal was to turn off node-jsx. I believe the idea was that the .jsx files were already preprocessed. However what you're trying to do sounds reasonable, you may need to move the require('babel/register') higher up. Have you tried putting that in your main server file?

Gnimuc commented 9 years ago

yes that was the problem. i reinstalled babel and put require('babel/register') in my server.js, then the error was killed. thank you so much @jedireza :+1:

jedireza commented 9 years ago

:boom: great to hear!!