CRA和捆绑式加载器

时间:2017-05-22 14:38:25

标签: javascript webpack react-router eslint create-react-app

我正在尝试在react-router应用程序中使用create-react-appcode splitting

import loadSettings from 'bundle-loader?lazy!./Settings';

这一行出错:

 Line 5:  Unexpected '!' in 'bundle-loader?lazy!./Settings'. Do not use import syntax to configure webpack loaders  import/no-webpack-loader-syntax

我认为这是因为某些es-lint设置。如何禁用它以便我可以在CRA应用程序中使用webpack bundle-loader

1 个答案:

答案 0 :(得分:1)

我设法解决了这个问题。 我做的是:

  1. 通过运行creact-react-app
  2. 退出npm run eject
  3. 通过向package.json添加rules密钥来修改eslintConfig文件,如下所示:

    "eslintConfig": {
        "extends": "react-app", // This was already in the file
        "rules": {
            "import/no-webpack-loader-syntax": 0
        }
    }
    
  4. 按照docs

  5. 中的说明设置您的组件

    希望这有助于某些人,因为我在没有找到正确答案的情况下挖掘了很多论坛!

    BTW对动态导入代码拆分的支持应尽快进入CRA