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

Defining global variable replacements in 'optimizeDeps' looks not correct. #2893

Closed
6 tasks done
daief opened this issue Apr 7, 2021 · 0 comments · Fixed by #2929
Closed
6 tasks done

Defining global variable replacements in 'optimizeDeps' looks not correct. #2893

daief opened this issue Apr 7, 2021 · 0 comments · Fixed by #2929
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@daief
Copy link

daief commented Apr 7, 2021

Describe the bug

My config file. I set a optimizeDeps and define. But the GLOBAL_VAR is replaced differently when I use GLOBAL_VAR in the module included by optimizeDeps and it looks not correct (it still be quoted after replaced).

import { defineConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [reactRefresh()],
  optimizeDeps: {
    include: ["@local/a"]
  },
  define: {
    GLOBAL_VAR: JSON.stringify("This is injected.")
  }
});

Reproduction

The codesandbox can reproduce the problem: https://codesandbox.io/s/vite-define-ior1b?file=/src/main.jsx

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Memory: 7.60 GB / 62.73 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 12.20.0 - ~/.nvm/versions/node/v12.20.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.20.0/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.20.0/bin/npm
  npmPackages:
    vite: 2.1.5 => 2.1.5

Used package manager: yarn

Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
@underfin underfin added bug p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Apr 10, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants