毛线启动不适用于react-app-rewired

时间:2019-05-23 10:04:41

标签: reactjs npm yarnpkg antd

运行头纱时,得到以下输出

$ yarn start
yarn run v1.15.2
$ react-app-rewired start
The "injectBabelPlugin" helper has been deprecated as of v2.0. You can use customize-cra plugins in replacement - https://github.com/arackaf/customize-cra#available-plugins
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我尝试在https://github.com/arackaf/customize-cra#available-plugins上阅读文档,但是由于我是React和npm的新手,所以对我来说意义不大,我也不知道用哪个插件替换不赞成使用的帮助程序

我的config-overrides.js如下:

const { injectBabelPlugin } = require('react-app-rewired');
const rewireLess = require('react-app-rewire-less');

module.exports = function override(config, env) {
   config = injectBabelPlugin(['import', { libraryName: 'antd', style: true }], config);  // change importing css to less
   config = rewireLess.withLoaderOptions({
       modifyVars: {
           "@primary-color": "#1DA57A"
       },
   })(config, env);
    return config;
};

1 个答案:

答案 0 :(得分:1)

请勿使用injectBabelPlugin此Pugin已弃用

像这样enter link description here

使用
const {
  override,
  fixBabelImports,
  addLessLoader,
} = require("customize-cra");


module.exports = override(
  fixBabelImports("import", {
    libraryName: "antd", libraryDirectory: "es", style: true // change importing css to less
  }),
  addLessLoader({
    javascriptEnabled: true,
    modifyVars: { "@primary-color": "#1DA57A" }
  })
);