umijs / babel-plugin-import

Modularly import plugin for babel.
3.16k stars 405 forks source link

Support Babel 7 + @babel/preset-typescript #210

Open pedroteixeira opened 6 years ago

pedroteixeira commented 6 years ago

Hi, trying to use with "babel 7.0.0-beta.40" but plugin does not seem to work. Is there any known issues or workarounds?

Don't have a unit test, I'm testing with antd and can see that the transform did not work by the console message "you are using a whole package of antd" :)

thanks! Pedro

.babelrc:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "browsers": [
            "last 2 versions"
          ]
        }
      }
    ],
    "@babel/react",
    "@babel/stage-3",
    "@babel/typescript"
  ],
  "plugins": [
    [
      "module-resolver",
      {
        "extensions": [
          ".js",
          ".jsx",
          ".ts",
          ".tsx"
        ],
        "root": [
          "./src",
          "../../node_modules"
        ]
      }
    ],
    [
      "import",
      {
        "libraryName": "antd",
        "style": true
      }
    ]
]
}
cloudever commented 6 years ago

Try to move the babel-plugin-import on top of module-resolver. The order of plugins has an effect while your app is building.

bkniffler commented 6 years ago

I'm having annoying problems with import plugin on babel 7. It removes babel runtime polyfills from the top of the files, resulting in errors like _typeOf is not declared. Changing the order doesn't seem to help.

bkniffler commented 6 years ago

Commenting out this line seems to help:

https://github.com/ant-design/babel-plugin-import/blob/master/src/Plugin.js#L118

edit: If anyone wants to try: npm i babel-plugin-import-7

Whoaa512 commented 6 years ago

Also seeing the same behavior as @bkniffler with latest beta version of babel 7 beta-40.

Any updates to fix this besides not removing all paths as is suggested in the babel-plugin-import-7 fork?