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

Code conditional compilation #19175

Closed
4 tasks done
choao opened this issue Jan 10, 2025 · 1 comment
Closed
4 tasks done

Code conditional compilation #19175

choao opened this issue Jan 10, 2025 · 1 comment

Comments

@choao
Copy link

choao commented Jan 10, 2025

Description

in develop
`
import { A } from '@/config';
import { B } from '@/static';
let data;
if(import.meta.env.DEV){
// doSomething
data = A.data;
};

if(import.meta.env.PROD){
// doSomething
data = B.data;
}
`

Suggested solution

I want it's:
`
/* vite-env-dev start /
import { A } from '@/config';
/
vite-end /
/
vite-env-pro start /
import { B } from '@/static';
/
vite-end */

let data;

/* vite-env-dev start /
if(import.meta.env.DEV){
// doSomething
data = A.data;
};
/
vite-end /
/
vite-env-pro start /
if(import.meta.env.PROD){
// doSomething
data = B.data;
}
/
vite-end */
`
This can reduce the size and usage of packaged files.

Alternative

No response

Additional context

No response

Validations

@bluwy
Copy link
Member

bluwy commented Jan 10, 2025

You should be able to achieve the same by dynamically importing the module. Otherwise you can create a plugin that detects the comments and strip them out.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants