账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    TS 中如何 有效的使用 webpack 的tree-shaking
    28
    0

    TS 中 使用 import {A} from 'component';
    webpack4 在 mode = production 情况下 也不会 使用 tree-shaking,会导致 打包整个 component 的代码,

    只能写成 import A from 'component/A' 的方式;

    tsconfig.json 中已经写成 了

    
    {
        "compilerOptions": {
            "target": "es6",
            "module": "esnext",
            "moduleResolution": "node",
            "allowSyntheticDefaultImports": true,
            "sourceMap": true,
            "removeComments": false,
            ...
            }
    }
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 琉离 普通会员 1楼

      在 TypeScript 中,使用 webpack 的 tree-shaking 有以下几种方法:

      1. 使用 use 函数和 importexport 语句:

      在组件中,可以使用 use 函数和 importexport 语句来实现 tree-shaking。例如:

      ```jsx import React from 'react'; import './MyComponent.css';

      function MyComponent() { const myComponent = () => { // ... };

      return (

      ); }

      export default MyComponent; ```

      1. 使用 importexportuse 函数:

      在模块化编程中,可以使用 importexportuse 函数来实现 tree-shaking。例如:

      ```jsx import React from 'react'; import './MyComponent.css';

      function MyComponent() { const myComponent = () => { // ... };

      return (

      ); }

      export default MyComponent; ```

      1. 使用 use 函数和 import

      在使用 TypeScript 的 import 语句时,可以使用 use 函数来实现 tree-shaking。例如:

      ```jsx import React from 'react'; import './MyComponent.css';

      function MyComponent() { const myComponent = () => { // ... };

      return (

      ); }

      export default MyComponent; ```

      以上三种方法都可以在 TypeScript 中实现 tree-shaking,可以根据项目的实际情况和需求来选择合适的方案。

    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部