how to tree-shake the unused variables?

12 views Asked by At

the code was like:

// env.ts
function getUA() {
  return typeof navigator !== 'undefined' ? navigator.userAgent : 'unknow';
}

function checkIsWeb() {
  return typeof window !== 'undefined' && 'onload' in window;
}

export const ua = /*#__PURE__*/ getUA();

/**判断是不是h5 */
export const isWeb = /*#__PURE__*/ checkIsWeb();
export const isMobile = /Mobi|Android/i.test(ua);
export const isBrowser = isWeb && !isMobile;
export const isIOS = /(iPhone|iPad|iPod)/.test(ua);
export const isAndroid = /Android/.test(ua);

export const isTrue = true

the entry file :

// entry.ts
import { isTrue } from './env.ts'

becasue isMobile and other variables use ua , so they are all bundled , you can try it out here

enter image description here

how to remove the other unused variable except isTrue

0

There are 0 answers