umijs / babel-plugin-import

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

Cant I use it in build package/node_modules ? #519

Open ngoctuan001 opened 3 years ago

ngoctuan001 commented 3 years ago

I have a project A using antd library (like a wrapper for every components of antd). So in order for A to work, I use babel-plugin-import to import the style. So far it works correctly when running A.

However, lets say if I wanna package the project A to become like a npm package, then use it in another project B.

In project B when running, I need to import babel config for antd again in project B so that it will add the antd style.

Is there anyway that project A will auto add the required style to the build package. So that in project B I don't need to add the babel config for antd again

project A babel.config.js

module.exports = {
  presets: ['razzle/babel', '@babel/typescript'],
  plugins: [
    [
      'import',
      {
        libraryName: 'antd',
        style: true,
      },
      'antd',
    ],
  ]
};

project B babel.config.js

 module.exports = {
      presets: ['razzle/babel', '@babel/typescript'],
      plugins: [
        [
          'import',
          {
            libraryName: 'antd', /// here I have to add the config again
            style: true,
          },
          'antd',
        ],
   [
          'import',
          {
            libraryName: 'projectA',
            style: true,
          },
          'A',
        ],
      ]
    };
wangpengfeido commented 3 years ago

If you are using babel-loader with webpack,I think you could add the path of projectA to "Rule.include" option of projectB.