react+webpack 引入字体图标

  在使用react+webpack 构建项目过程中免不了要用到字体图标,在引入过程中报错,不能识别字体图标文件中的@符,报错

  

 Uncaught Error: Module parse failed: Unexpected character '@'

解决办法,修改webpack的配置文件

  

webpack.config.js
{
                test:/\.css$/,
                use:[
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test:/\.less$/,
                exclude:/node_modules/,
                use:ExtractTextPlugin.extract({
                    fallback:"style-loader",
                    use:[
                        {loader:"css-loader"},
                        {loader:"less-loader"}
                    ]
                })

            },
            {
                test:/\.(woff|svg|eot|ttf)\??.*$/,
                use:[
                    'file-loader'
                ]
            }

  不要忘了,在安装extract-text-webpack-plugin后,引入

  

const ExtractTextPlugin = require('extract-text-webpack-plugin');


plugins:[
    new ExtractTextPlugin('src/style/style.css')//字体图标路径
]

最后将字体图标的style.css 文件正常引入到文件中即可

import '../style/style.css'//根据实际路径引进