jedireza / hapi-react-views

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

Babel transpile JSX to JS - Handling for different file extensions #58

Closed danielbayerlein closed 8 years ago

danielbayerlein commented 8 years ago

I use Babel CLI for production to compile my ES6 code to ES5. The files with the extension .jsx be compiled to .js. The server will only recognize the .jsx ending. How do you solve the problem?

  server.views({
    engines: {
      jsx: HapiReactViews,
    },
    compileOptions: {
      doctype: '',
    },
    relativeTo: __dirname,
    path: 'views',
  });
tribou commented 8 years ago

I'm able to get my code working with:

engines: {
  js: HapiReactViews,
}

However, you have to restart the server after every change since only .jsx files currently benefit from the removeCache option. (I submitted #60 to hopefully resolve this.)

jedireza commented 8 years ago

Thanks for opening an issue @danielbayerlein. @tribou's answer should work. Please give it a shot and let us know.

danielbayerlein commented 8 years ago

@tribou @jedireza

Thanks for the response. In production the server will recognize the .js ending - in development the .jsx. So I think we need a different configuration for production and development, or?

jedireza commented 8 years ago

I'd reach for confidence in this case. confidence allows you to change your configuration based on a criteria (in your case NODE_ENV).

danielbayerlein commented 8 years ago

@jedireza Thank you!

ThiagoMiranda commented 7 years ago

@danielbayerlein Sorry to bother you in this issue but I'm experiencing the same issue here and when I add js: HapiReactViews in my engines configuration object I got an error: Unknown extension and no defaultExtension configured for view template: Default ( my original file is name Default.jsx ).

In my view route I just put reply.view('Default') so do I have to write an extension? If so, how did you deal with it? Using a env argument? Thanks

Update: solved it with the defaultExtension option on the server.views

danielbayerlein commented 7 years ago

@ThiagoMiranda Nice to hear that it works. 👍