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

🐛 [Bug]: mock false 无效 并不能启用非mock 模式 #125

Closed
xjspace opened this issue Dec 11, 2023 · 8 comments
Closed

🐛 [Bug]: mock false 无效 并不能启用非mock 模式 #125

xjspace opened this issue Dec 11, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@xjspace
Copy link

xjspace commented Dec 11, 2023

Version

@opentiny/[email protected]

Vue Version

2.69

Link to minimal reproduction

config\vite.config.base.ts
微信截图_20231211154600
`import { mergeConfig, loadEnv } from 'vite';
import eslint from 'vite-plugin-eslint';
import baseConfig from './vite.config.base';

const proxyConfig = {
[loadEnv('', process.cwd()).VITE_BASE_API]: {
target: loadEnv('', process.cwd()).VITE_SERVER_HOST,
changeOrigin: true,
logLevel: 'debug',
mock: false,
rewrite: (path) =>
path.replace(
new RegExp(${loadEnv('', process.cwd()).VITE_BASE_API}),
''
),
},
};
export default mergeConfig(
{
mode: 'development',
server: {
open: true,
fs: {
strict: true,
},
proxy: {
...proxyConfig,
},
},
plugins: [
eslint({
include: ['src//*.ts', 'src//.tsx', 'src/**/.vue'],
exclude: ['node_modules'],
}),
],
},
baseConfig
);
.env
VITE_CONTEXT = /fire/
VITE_BASE_API = /api
VITE_SERVER_HOST = http://0.0.0.0:8080 //实际是服务器ip
VITE_USE_MOCK = false
`
修改配置后无效,并没有启用非mock模式

Step to reproduce

按上述修改,并没有启用非mock 模式,也许是我哪里没搞对

What is expected

No response

What is actually happening

No response

Any additional comments (optional)

No response

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: 🐛 [Bug]: mock false is invalid and cannot enable non-mock mode

@kagol kagol added the bug Something isn't working label Dec 14, 2023
@kagol
Copy link
Member

kagol commented Dec 14, 2023

@fengyon This is a issue of https://github.com/opentiny/tiny-cli

@fengyon
Copy link
Contributor

fengyon commented Dec 19, 2023

感谢您的反馈,此问题的根因是

  1. main.ts 导入了 mockProdServer的运行时
  2. 配置.env 中的 VITE_USE_MOCK 不会透传至 process.env.VITE_USE_MOCK的问题

目前的临时修复措施是

  1. 去掉 src/main.ts 的文件中导入 mockProdServer 的相关内容
...
- import { setupProdMockServer } from './mockProdServer';
...
- if(import.meta.env.VITE_USE_MOCK) {
-   setupProdMockServer();
- }
  1. 修改config/vite.config.base.ts 文件关于 useMock的内容
...
+ import { loadEnv } from 'vite';
...
- const useMock = !! process.env.VITE_USE_MOCK
+ const useMock = loadEnv('', process.cwd()).VITE_USE_MOCK === 'true'

我们将尽快优化模板

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Thanks for your feedback, the root cause of this issue is

  1. main.ts imports the runtime of mockProdServer
  2. The problem that VITE_USE_MOCK in configuration .env is not transparently transmitted to process.env.VITE_USE_MOCK

The current temporary fix is

  1. Remove the content related to importing mockProdServer in the src/main.ts file.
...
- import { setupProdMockServer } from './mockProdServer';
...
- if(import.meta.env.VITE_USE_MOCK) {
- setupProdMockServer();
- }
  1. Modify the contents of the config/vite.config.base.ts file regarding useMock
...
+ import { loadEnv } from 'vite';
...
- const useMock = !! process.env.VITE_USE_MOCK
+ const useMock = loadEnv('', process.cwd()).VITE_USE_MOCK === 'true'

We will optimize the template as soon as possible

@xjspace
Copy link
Author

xjspace commented Dec 19, 2023

感谢您的反馈,此问题的根因是

  1. main.ts 导入了 mockProdServer的运行时
  2. 配置.env 中的 VITE_USE_MOCK 不会透传至 process.env.VITE_USE_MOCK的问题

目前的临时修复措施是

  1. 去掉 src/main.ts 的文件中导入 mockProdServer 的相关内容
...
- import { setupProdMockServer } from './mockProdServer';
...
- if(import.meta.env.VITE_USE_MOCK) {
-   setupProdMockServer();
- }
  1. 修改config/vite.config.base.ts 文件关于 useMock的内容
...
+ import { loadEnv } from 'vite';
...
- const useMock = !! process.env.VITE_USE_MOCK
+ const useMock = loadEnv('', process.cwd()).VITE_USE_MOCK === 'true'

我们将尽快优化模板

已解决,谢谢

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Thanks for your feedback, the root cause of this issue is

  1. main.ts imports the runtime of mockProdServer
  2. The problem that VITE_USE_MOCK in configuration .env is not transparently transmitted to process.env.VITE_USE_MOCK

The current temporary fix is

  1. Remove the relevant content of importing mockProdServer from the src/main.ts file
...
- import { setupProdMockServer } from './mockProdServer';
...
- if(import.meta.env.VITE_USE_MOCK) {
- setupProdMockServer();
- }
  1. Modify the contents of the config/vite.config.base.ts file regarding useMock
...
+ import { loadEnv } from 'vite';
...
- const useMock = !! process.env.VITE_USE_MOCK
+ const useMock = loadEnv('', process.cwd()).VITE_USE_MOCK === 'true'

We will optimize the template as soon as possible

Solved, thank you

@fengyon fengyon transferred this issue from opentiny/tiny-vue Dec 21, 2023
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: 🐛 [Bug]: mock false is invalid and cannot enable non-mock mode

@kagol
Copy link
Member

kagol commented Apr 3, 2024

Fixed by @fengyon on tiny-cli

@kagol kagol closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants