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

How to use this with Vite? #5

Open
FezVrasta opened this issue Mar 31, 2023 · 8 comments
Open

How to use this with Vite? #5

FezVrasta opened this issue Mar 31, 2023 · 8 comments

Comments

@FezVrasta
Copy link

Thanks for the plugin! I tried to use the styled-components plugin on a Vite project but it doesn't seem to do anything, I tried to use it in the optimizeDeps.esbuildOptions.plugins and in the plugins but it has no effect. Could you provide guidance please?

@alexkuz alexkuz mentioned this issue Apr 1, 2023
@alexkuz
Copy link
Contributor

alexkuz commented Apr 1, 2023

@FezVrasta Vite uses different plugin API than Esbuild, so this plugin wouldn't work there.
I haven't used Vite a lot, but I wrote a Vite version, can you try it out?

yarn add --dev 'https://gitpkg.now.sh/lukalabs/lukalabs-npm/packages/esbuild-styled-components?vite-plugin'

Here's how you would use it in vite.config.js:

import styledComponentsPlugin from '@lukalabs/esbuild-styled-components/vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [styledComponentsPlugin({ namespace: 'xxx' }), react()],
})

@FezVrasta
Copy link
Author

Thanks, I get this error when I try your command, may you publish it on npm please?

Internal Error: Invalid descriptor (https://gitpkg.now.sh/lukalabs/lukalabs-npm/packages/esbuild-styled-components?vite-plugin)

@alexkuz
Copy link
Contributor

alexkuz commented Apr 3, 2023

Are you using Yarn 2?
I will publish this later, meanwhile please try this one:

yarn add --dev '@lukalabs/esbuild-styled-components@https://gitpkg.now.sh/api/pkg.tgz?url=lukalabs%2Flukalabs-npm%2Fpackages%2Fesbuild-styled-components&commit=vite-plugin'

@FezVrasta
Copy link
Author

Thanks, this installs correctly with Yarn 2, but the plugin doesn't seem to do anything, my css properties are not compiled into className ones.

@alexkuz
Copy link
Contributor

alexkuz commented Apr 4, 2023

Yes, the implementation here is limited and doesn't include css props, at least for now. I should have mentioned it in README. It was created mainly to solve server rendering issues. I can look into implementing css, not sure when though.

Have you tried using vite-plugin-babel-macros + babel-plugin-styled-components, as discussed here?

@FezVrasta
Copy link
Author

I'm using the react-plugin-swc with the swc styled-components plugin for now, having a esbuild-native solution would have been great though!

@igor-levkov
Copy link

I'm using the react-plugin-swc with the swc styled-components plugin for now, having a esbuild-native solution would have been great though!

@FezVrasta are you using awc plugin setup with Vite? If yes, then do you have sample repo for it?

@FezVrasta
Copy link
Author

I'm just using this in the plugins list:

const react = require('@vitejs/plugin-react-swc').default;

[...]

      react({ plugins: [['@swc/plugin-styled-components', {}]] }),

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

3 participants