privatenumber / esbuild-loader

💠 Speed up your Webpack with esbuild ⚡️
MIT License
3.58k stars 106 forks source link

inject JSX helpers in options #106

Closed gozeon closed 3 years ago

gozeon commented 3 years ago
{
  jsxInject: `import React from 'react'`,
  loader: 'jsx', 
  ...
}
xzilja commented 3 years ago

This would be nice, as since typescript 4.2 a warning is thrown when importing React saying 'React' is declared but its value is never read

Related stackoverflow issue https://stackoverflow.com/questions/66358237/react-is-declared-but-its-value-is-never-read-in-ts-4-2?noredirect=1#comment117315694_66358237

privatenumber commented 3 years ago

Webpack has a built-in solution for this via ProvidePlugin.

deleonio commented 3 years ago

Hello together, that is not the same!

import {h, Fragment} from 'preact'; ?!

plugins: [
  new webpack.ProvidePlugin({
    '{h, Fragment}': 'preact'
  })
]

image

gozeon commented 3 years ago

Hello together, that is not the same!

import {h, Fragment} from 'preact'; ?!

plugins: [
  new webpack.ProvidePlugin({
    '{h, Fragment}': 'preact'
  })
]

image

{
   loader: 'jsx',
   jsxFactory: 'Preact.createElement' // or Preact.h
}
deleonio commented 3 years ago

Hi @gozeon

thats not the same, too.

jsxInject enabled to remove all for JSX needed React or Preact imports.

Take a Look at vite or snowpack

privatenumber commented 3 years ago

@deleonio

Consider opening a question in Discussions for configuration help with Preact. This thread is originally about React, and Provide Plugin is demonstrated to be a valid solution here. Make sure your goal and blockers are clearly communicated.

This is a closed thread so it doesn't get much visibility. Not to mention, no one has provided a clear description of the problem so it's not great for discoverability either.