安装Element-UI

npm i element-ui -S

执行报错


ERROR in ./~/element-ui/lib/theme-default/index.css

Module parse failed: /Users/huzhixin/www/qnzsresearch/node_modules/element-ui/lib/theme-default/index.css Unexpected character '@' (1:0)

You may need an appropriate loader to handle this file type.

| @charset "UTF-8";.


报错是由于我们引入了index.css这个 CSS 文件,但是 webpack 打包的时候无法识别并转换成 js,所以就需要配置才能读取 css 和字体文件,运行命令安装下面三个东西(如果之前安装过就不需要了)

执行安装

npm install style-loader --save-dev

npm install css-loader --save-dev

npm install file-loader --save-dev

修改webpack.config.js

{

          test: /\.css$/,

          loader: "style-loader!css-loader"

},

{

          test: /\.(eot|woff|woff2|ttf)([\\?]?.*)$/,

          loader: "file-loader"

},


npm run dev



参考内容

https://segmentfault.com/a/1190000007124470#articleHeader24