Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esbuild support for CSS property? #348

Open
FezVrasta opened this issue Aug 18, 2021 · 6 comments
Open

Esbuild support for CSS property? #348

FezVrasta opened this issue Aug 18, 2021 · 6 comments

Comments

@FezVrasta
Copy link

Hi, I was wondering if there is any plan to add support for an alternative to the Babel Plugin Macro in order to be able to use the CSS property with Esbuild?

@kitten kitten transferred this issue from styled-components/styled-components Aug 18, 2021
@FezVrasta
Copy link
Author

I think a possible alternative could be to provide a custom jsx pragma like Emotion does.

@FezVrasta
Copy link
Author

@kitten may I know why this was moved to the Babel plugin repository? My issue is about esbuild, not Babel. If a solution is going to be found, it will not involve Babel.

@mquandalle
Copy link

Did anyone fund a solution to support the css prop on a ViteJS/ESBuild application?

@SergeyVolynkin
Copy link

For now 'babel-plugin-styled-components' babel transformation needs to be called during esbuild.build(…)
Almost doubles the build time of esbuild project, but works

// build.mjs
import * as esbuild from 'esbuild';
import esbuildPluginBabel from 'esbuild-plugin-babel'; // small utility plugin making a bit easier to run babel transformation
//…
await esbuild.build({
  logLevel: 'info',
  outdir: './build',
  entryPoints: ['./src/index.tsx'],
  entryNames: 'static/[name]-[hash]',
  metafile: true,
  bundle: true,
  minify: true,
  sourcemap: true,
  platform: 'browser',
  target: 'chrome117',
  tsconfig: './tsconfig-src.json',
  define: {
    global: 'globalThis',
  },
  plugins: [
    // run as the first plugin
    esbuildPluginBabel({
      filter: /\.(jsx|tsx)$/u, // only process .jsx and .tsx files
      config: {
        plugins: [['babel-plugin-styled-components', { pure: true }]],
      },
    }),
    //… other plugins you have
  ],
});

cc @probablyup as the major contributor to the https://github.com/styled-components/babel-plugin-styled-components repo maybe you would know if styled-components team has plans to port the babel-plugin-styled-components to esbuild-native plugin? esbuild provides way to write a plugin on JS and Go lang, https://esbuild.github.io/plugins/#example-plugins

@quantizor
Copy link
Collaborator

I really have no time for that unfortunately. Maybe when one of the AI tools gets good enough we can generate one unless someone wants to take a stab at it

@quantizor
Copy link
Collaborator

The tricky thing with esbuild is it just gives you raw content and you have to provide your own AST parser. So you end up with something babel-like anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants