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