Code Monkey home page Code Monkey logo

Comments (3)

pengzhanbo avatar pengzhanbo commented on May 28, 2024

经过检查,发现是 @vitejs/plugin-legacy 插件会在 viteConfig.define 配置中插入{ "import.meta.env.LEGACY": '__VITE_IS_LEGACY__' } 。在mock插件中,也会使用 viteConfig.define 用于 插件内部 esbuild 的 define 配置。
但是 在 esbuild 内部 编译时, '__VITE_IS_LEGACY__' 会被替换为一个普通的代码片段 __VITE_IS_LEGACY__,由于代码未定义该变量,导致了编译错误。

from vite-plugin-mock-dev-server.

pengzhanbo avatar pengzhanbo commented on May 28, 2024

由于 不好判断 viteConfig.define 中的配置,哪些是用户配置的,哪些是插件配置的,以及是否是 注入的待替换字符,目前的解决方式是 过滤掉 import.meta.env.LEGACY

from vite-plugin-mock-dev-server.

pengzhanbo avatar pengzhanbo commented on May 28, 2024

采用了新的思路, viteConfig.define 配置的字段,如果字符串值 无法被 JSON.parse 解析为 基础类型或 普通对象、普通数组,则将其过滤掉。 从而适配其他可能使用的插件传入的 define 或用户配置的 define 中存在的类似问题。

from vite-plugin-mock-dev-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.