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'//根據實際路徑引進

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM