webpack 2 预期 '!'与导入一起使用时出错 [英] webpack 2 expected '!' error using with import

查看:46
本文介绍了webpack 2 预期 '!'与导入一起使用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用这个 svg 加载器,https://github.com/jhamlet/svg-反应加载器

I want to use this svg loader, https://github.com/jhamlet/svg-react-loader

在说明中我遵循了用法,例如

in the instruction I followed the usage, like

import Logo from 'svg-react-loader?name=Logo!../images/logo.svg';

但是我遇到了错误

Line 3:  Unexpected '!' in 'svg-react-loader?name=Logo!../images/logo.svg'. Do not use import syntax to configure webpack loaders  import/no-webpack-loader-syntax

推荐答案

这不是来自 webpack 的错误,而是来自 ESLint,特别是来自 eslint-plugin-import.

That is not an error from webpack, but from ESLint, specifically from eslint-plugin-import.

通常不推荐使用内联加载器,并且 ESLint 规则 import/no-webpack-loader-syntax 的存在是为了警告您不要这样做.如果您确实想使用内联加载器并且不想让 ESLint 抱怨,您可以在 .eslintrc 中禁用该规则.

Using inline loaders is generally not recommended and the ESLint rule import/no-webpack-loader-syntax exists to warn you from doing this. If you do want to use inline loaders and don't want ESLint to complain, you can disable the rule in your .eslintrc.

"rules": {
  "import/no-webpack-loader-syntax": "off"
}

或者您可以仅针对该特定导入禁用规则,如果您想收到有关内联加载程序的警告,除了这个,因为在这种特殊情况下您可能需要它.

Or you can disable the rule just for that specific import, if you want to be warned about inline loaders, except for this one, because you might need it in this particular case.

// eslint-disable-next-line import/no-webpack-loader-syntax
import Logo from 'svg-react-loader?name=Logo!../images/logo.svg';

这篇关于webpack 2 预期 '!'与导入一起使用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆