NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.35k stars 4.77k forks source link

期望h5打包时,可以treeshaking掉未使用的包 #12826

Closed guaizi149 closed 1 year ago

guaizi149 commented 1 year ago

相关平台

H5

浏览器版本: Chrome 62 使用框架: React

复现步骤

执行taro init,然后执行npm run build:h5

期望结果

未使用的包被treeshaking掉

实际结果

未使用的包依然被打包到了产物中 项目初始化后,直接执行npm run build:h5。 可以看到很多未使用的包, 像taro-video-control_3, mobile-detect等均被打包进了产物中

image

环境信息

Taro CLI 3.5.7 environment info:
    System:
      OS: macOS 10.15.7
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v16.14.0/bin/yarn
      npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.7 => 3.5.7 
      @tarojs/components: 3.5.7 => 3.5.7 
      @tarojs/helper: 3.5.7 => 3.5.7 
      @tarojs/plugin-framework-react: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-alipay: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-jd: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-qq: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-swan: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-tt: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-weapp: 3.5.7 => 3.5.7 
      @tarojs/react: 3.5.7 => 3.5.7 
      @tarojs/router: 3.5.7 => 3.5.7 
      @tarojs/runtime: 3.5.7 => 3.5.7 
      @tarojs/shared: 3.5.7 => 3.5.7 
      @tarojs/taro: 3.5.7 => 3.5.7 
      @tarojs/taro-h5: 3.5.7 => 3.5.7 
      @tarojs/webpack5-runner: 3.5.7 => 3.5.7 
      babel-preset-taro: 3.5.7 => 3.5.7 
      eslint-config-taro: 3.5.7 => 3.5.7 
      react: ^18.0.0 => 18.2.0 
    npmGlobalPackages:
      typescript: 4.8.4
ZakaryCode commented 1 year ago

mobile-detect 在 taro-router 中使用,taro-video 是懒加载引入,在未使用时并不会影响应用加载体验,如有特殊场景请参考文档