umijs / babel-plugin-import

Modularly import plugin for babel.
3.15k stars 403 forks source link

Not working when used with parcel v2 #595

Open hbarcelos opened 2 years ago

hbarcelos commented 2 years ago

I am trying to use this plugin with parcel v2 but I keep getting the following error:

ReferenceError: Layout is not defined

The relevant config files are:

.parcelrc

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.svg": ["@parcel/transformer-svgo", "@parcel/transformer-svg-react", "@parcel/transformer-js"]
  }
}

.babelrc

{
  "plugins": [
    [
      "import",
      {
        "libraryName": "antd",
        "style": "css"
      },
      "antd"
    ]
  ]
}

If I install @babel/cli and run babel myFile.js with

.babelrc

{
  "presets": ["@babel/preset-react"],
  "plugins": [
    "@babel/plugin-syntax-jsx",
    [
      "import",
      {
        "libraryName": "antd",
        "style": "css"
      },
      "antd"
    ]
  ]
}

then the component is still imported.

But if I remove the "presets" line, then the import is removed even though there is a JSX element that references it.