Skip to content

How to use .js instead of .jsx #3448

Discussion options

You must be logged in to vote

@marialovesbeans here's a working config:

import fs from 'fs/promises';

export default defineConfig(() => ({
  esbuild: {
    loader: "jsx",
    include: /src\/.*\.jsx?$/,
    // loader: "tsx",
    // include: /src\/.*\.[tj]sx?$/,
    exclude: [],
  },
  optimizeDeps: {
    esbuildOptions: {
      plugins: [
        {
          name: "load-js-files-as-jsx",
          setup(build) {
            build.onLoad({ filter: /src\/.*\.js$/ }, async (args) => ({
              loader: "jsx",
              contents: await fs.readFile(args.path, "utf8"),
            }));
          },
        },
      ],
    },
  },
}));

I would only recommend using this to try out Vite in your project - the plugin ci…

Replies: 21 comments 59 replies

Comment options

You must be logged in to vote
8 replies
@marialovesbeans
Comment options

@prathmesh-ka-github
Comment options

@luckymore
Comment options

@rd273001
Comment options

@rd273001
Comment options

Comment options

You must be logged in to vote
20 replies
@blackboldxdevmedia
Comment options

@sostene12
Comment options

@Namnika
Comment options

@oh-wion
Comment options

@Namnika
Comment options

Answer selected by nihalgonsalves
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@LeungJacky
Comment options

@wingoflan
Comment options

@Srivathsa-km
Comment options

@LeungJacky
Comment options

@agosmou
Comment options

Comment options

You must be logged in to vote
2 replies
@shinaBR2
Comment options

@jules-deguglielmi
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@aboucodeur
Comment options

Comment options

You must be logged in to vote
1 reply
@dons20
Comment options

Comment options

You must be logged in to vote
1 reply
@FezVrasta
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@christiaanwesterbeek
Comment options

@pmorim
Comment options

Comment options

You must be logged in to vote
2 replies
@istonejoeljonsson
Comment options

@istonejoeljonsson
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@pmorim
Comment options

@opsb
Comment options

@tscritch
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@tscritch
Comment options

@amcsi
Comment options

@ThinkerDreamer
Comment options

@fwextensions
Comment options

Comment options

You must be logged in to vote
2 replies
@gbedardsiceupgrade
Comment options

@oh-wion
Comment options

Comment options

You must be logged in to vote
7 replies
@dac09
Comment options

@dac09
Comment options

@gbedardsiceupgrade
Comment options

@Staz
Comment options

@ElliotNB
Comment options

Comment options

You must be logged in to vote
1 reply
@prathmesh-ka-github
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #3443 on May 17, 2021 11:18.