Babel-plugin-lodash实现

时间:2018-06-29 21:36:22

标签: babel tree-shaking

实施Babel-Plugin-Lodash时是否存在重大“陷阱”?

节点:6.14.1 通天塔:6.26

我在.babelrc中添加了以下内容:

{   
    "env": {
        "development": {
            "presets": [
                [
                    "env",
                    {
                        "targets": {
                            "browsers": [
                                "last 2 versions",
                                "ie >= 9"
                            ],
                            "node": "current"
                        }
                    }
                ],
                "stage-2",
                "react"
            ],
            "plugins": [
                "lodash",
                "istanbul",
                "transform-es2015-template-literals",
                [
                    "module-alias",
                    [
                        {
                            "src": "./server",
                            "expose": "server"
                        }
                    ]
                ]
            ]
        },
        "test": {
            "presets": [
                [
                    "env",
                    {
                        "targets": {
                            "node": "current"
                        }
                    }
                ]
            ]
        }
    },
    "presets": [
        [
            "env",
            {   
                "targets": {
                    "browsers": [
                        "last 2 versions",
                        "ie >= 9"
                    ],
                    "node": 6
                },
                "modules": false
            }
        ],
        "stage-2",
        "react"
    ],
    "plugins": [
        "lodash",
        "transform-es2015-template-literals",
        ["module-alias", [
            { "src": "./server", "expose": "server" },

        ]]
    ]
}

文档似乎显示了插件,即使在导入整个库时也能识别使用的lodash方法:

import _ from 'lodash';

_.get(obj, 'key', null)

在尝试正确实施时,我还有什么要关注或关注的?

0 个答案:

没有答案