-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
config.define incorrectly escapes - #9964
Comments
The define functionality currently doesn't work as a generic search-and-replace solution, it's only meant to "define global constant replacements". That's also why your proposed fix only works in build mode: the dev server doesn't perform any text replacements at all but instead defines global variables: https:/vitejs/vite/blob/main/packages/vite/src/client/env.ts. (which, like all JS identifiers, mustn't contain dashes) For a generic search-and-replace functionality, try something like vite-plugin-replace or write your own |
Anyhow, here's a fix: #9980 But as I said, it'll only work in build mode as there are no text replacements in dev mode |
I see. That was a bit unclear to me. Great that you're fixing the incorrect RegExp though. 👍 |
Your original config looks like it's just trying to create an alias. You can do that with // vite.config.js
import { defineConfig } from 'vite'
export default defineConfig({
resolve: {
alias: {
'styled-components': 'styled-components/macro',
}
}
}) |
Yeah, I tried that, but babel did not recognize the import as a macro when I did that. I ended up using the macro explicitly on an as needed basis. The code works fine without the macro. Class names are just less readable. Hardly the biggest issue with migrating a large 6 year old ejected CRA application to Vite without messing up pull requests. 😄 I managed to do it though! |
Describe the bug
Removing
-
in dist/node/chunks/dep-0fc8e132.js fixes the problem:I'm on [email protected]
Reproduction
https://stackblitz.com/edit/vitejs-vite-vvdzuy?file=vite.config.js
System Info
Used Package Manager
yarn
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: