umijs / babel-plugin-import

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

import doesn't work if babel configured into package.json #114

Open sashakru opened 7 years ago

sashakru commented 7 years ago

I'm using babel configuration into my package.json:

"babel": {
    "presets": [
      "react",
      "stage-0"
    ],
    "plugins": [
      "syntax-trailing-function-commas",
      "transform-async-to-generator",
      "transform-es2015-destructuring",
      "transform-es2015-parameters",
      "transform-es2015-duplicate-keys",
      "transform-es2015-modules-commonjs",
      "transform-exponentiation-operator",
      "transform-runtime",
      ["import", { "libraryName": "antd", "style": "css" }]
    ],
    "env": {
      "test": {
        "plugins": [
          "rewire"
        ]
      }
    }
  },

When I'm importing antd components I still get You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size. console error, and component styles are not loaded.

Component example:

import {Card, Button} from 'antd';
import React, {PropTypes} from 'react';

class Login extends React.Component {
render() {
    const { login, loginInProcess } = this.props;
    return (
      <div>
        <Card
          style={CARD_STYLE}
          bordered={false}
        >
          <h2>Welcome</h2>
          <Button
            loading={loginInProcess}
            onClick={login}
          >
            Sign In with google
          </Button>
        </Card>
      </div>
    );
  }
}
matteosaporiti commented 7 years ago

Same thing it's happening on meteor (which uses this package to call the Babel API).