GithubHelp home page GithubHelp logo

Comments (7)

artemyarulin avatar artemyarulin commented on June 24, 2024 8

Hi guys, I've created small example project

Thank you for the project, me == happy 😍

from express-react-views.

rcanessa89 avatar rcanessa89 commented on June 24, 2024 6

Well I have found a way, I don't know if it is the best manner but if you set in your "compilerOptions": { "jsx": "react" } the tsx files will be js files. And then you can set the engine like js instead of jsx.

app.engine('js', expressReactViews.createEngine()); app.set('view engine', 'js');

Also I have tried to use "jsx": "preserve" and the tsx files will be jsx with jsx syntax inside but it does not work.

from express-react-views.

zpao avatar zpao commented on June 24, 2024

It's surely possible to do but hasn't been. If you're going to be using TS throughout your project you could skip making changes to this projects and use something like, then just register as the very first step in app.js or if you have app.ts, run with ts-node directly. You probably have to register your views with 'tsx' (instead of 'jsx' as in the docs).

Alternatively you could try to make changes here so that it works but it's not something I'll be working on. Much like adding support for CoffeeScript (#34), I'd be willing to accept patches

from express-react-views.

zpao avatar zpao commented on June 24, 2024

Looks like this is working well enough so going to close out. Thanks folks for figuring out how to make it work.

from express-react-views.

sant123 avatar sant123 commented on June 24, 2024

Another approach with sections (coming from ASP.NET MVC) 🤷‍♂️


from express-react-views.

RicardoFredes avatar RicardoFredes commented on June 24, 2024

Hi guys, i used @artemyarulin 's solution for my project, but in production version i needed to change de engine view extension from tsx to js. I resolved it using a env var:

// server.ts
import express from 'express'
import { createEngine } from 'express-react-views'

const dev = process.env.NODE_ENV === 'dev'
const viewFileExtension = dev ? 'tsx' : 'js'

const app = express()

app.set('views', __dirname + '/views')
app.set('view engine', viewFileExtension)
app.engine(viewFileExtension, createEngine())

app.get('/', (_, req) => req.render('index', { title: 'Hello world' }))
"scripts": {
    "build": "tsc",
    "dev": "NODE_ENV=dev nodemon src/server.ts --watch src",
    "start": "node dist/server.js"

Thanks, @artemyarulin and I hope to help anybody.

from express-react-views.

ZuraM avatar ZuraM commented on June 24, 2024

@RicardoFredes do you compile .tsx files when building? tsc command doesn't compile them automatically so i guess i need to compile them manually?

from express-react-views.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.