Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack 4: WOFF, WOFF2, SVGs failed to load

ERROR in ./node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.woff 1:4 Module parse failed: Unexpected character '' (1:4) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)

WOFF files are failing to load and I am not getting an idea to why file-loader is failing to load WOFF, WOFF2 and SVG.

Here is my Webpack 4 loaders config:

module: {
        rules: [
            {
                //tell webpack to use jsx-loader for all *.jsx files
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                loader: "babel-loader"
            },
            {
                test: /\.css$/,
                loader: "style-loader!css-loader"
            },
            {
                test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
                exclude: /node_modules/,
                loader: "file-loader"
            },
            {
                test: /\.(eot|ttf)$/,
                loader: "file-loader",
            },
            {
                test: /\.html$/,
                exclude: /node_modules/,
                loader: 'html-loader'
            },
            {
                test: /\.scss$/,
                loaders: ["style-loader", "css-loader", "sass-loader"]
            }
        ]
    }

Please suggest a solution to me.

like image 647
Hemadri Dasari Avatar asked Jul 11 '18 04:07

Hemadri Dasari


Video Answer


1 Answers

You can user webpack url-loader for that and it will resolve your problem.If you are using npm you can install npm install url-loader --save-dev and in your webpack.config.js you can write module settings like this

   {test: /\.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)$/,loader: 'url-loader?limit=100000'}

and import images like import img from './image.svg'

Github : https://github.com/webpack-contrib/url-loader

NPM : https://www.npmjs.com/package/url-loader

like image 145
Subhanshu Avatar answered Oct 24 '22 01:10

Subhanshu