crank icon indicating copy to clipboard operation
crank copied to clipboard

jsx-runtime missing

Open xdev1 opened this issue 2 years ago • 5 comments

It would be really great if Crank had a jsx-runtime. As hint, please find the Preact counterpart here.

Would allow the following tsconfig.json entries:

  "jsx": "react-jsx",
  "jsxImportSource": "@b9g/crank"

xdev1 avatar Aug 06 '22 15:08 xdev1

Hi,

I may be off-track here but the similarities strike me. Note that I'm not using Typescript nor is Babel part of my environment.

I'm using Vite and to build jsx with Crank my vite config esbuild setting contains the following:

export default defineConfig({
  esbuild: {
    jsxFactory: 'createElement',
    jsxFragment: 'Fragment'
  }
})

This may be completely unhelpful. My apologies in advance.

Sincerely, Darryl Cousins

darrylcousins avatar Aug 06 '22 23:08 darrylcousins

@darrylcousins But you still have to import createElement (and Fragment if needed) explicitly in each of your component files, don't you? This should not be necessary any longer if you use "jsxImportSource" with a jsx-runtime.

xdev1 avatar Aug 06 '22 23:08 xdev1

Hi,

The example offered for esbuild config options is:

export default defineConfig({
  esbuild: {
    jsxInject: `import React from 'react'`
  }
})

I've tested the following and it works. Of course it complains that Identifier 'createElement' has already been declared if I do explicitly define the import in any jsx file:

export default defineConfig({
  esbuild: {
    jsxFactory: 'createElement',
    jsxFragment: 'Fragment'
    jsxInject: `import {createElement, Fragment} from '@b9g/crank'`
  }
})

Hope that helps.

Sincere regards, Darryl Cousins

darrylcousins avatar Aug 07 '22 07:08 darrylcousins

@darrylcousins Thank you very much, Darryl, for all that info about how JSX can be configured with Vite. This was indeed very informative and helpful. I've not used Vite yet, but after your posts above, I'll give it a try ... actually really very nice ... Nevertheless, as not everybody uses Vite and jsx-runtimes are some kind of standard now, it would still be great if Crank had a jsx-runtime, I guess :wink:

xdev1 avatar Aug 09 '22 11:08 xdev1

Hi @xdev1,

Hey, no problem at all. I'm relatively new to nodejs development (python background). I went (sort of) webpack -> brunch -> vite. Most happy with vite. I pass this on to Brian for addressing jsx-runtime.

Go well, happy coding, Darryl Cousins

darrylcousins avatar Aug 09 '22 11:08 darrylcousins

Added in 0.5. Sorry for delay!

brainkim avatar Feb 27 '23 00:02 brainkim