WOFF文件无法加载,我也不知道为什么文件加载器无法加载WOFF,WOFF2和SVG。

这是我的Webpack 4加载程序配置:

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"]
            }
        ]
    }

请给我一个解决方案。

最佳答案

您可以使用webpack url-loader来解决问题。如果您使用的是npm,则可以安装npm install url-loader --save-dev,并在webpack.config.js中编写如下的模块设置

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

并导入像import img from './image.svg'这样的图片

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

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

关于reactjs - Webpack 4 : WOFF, WOFF2,SVG加载失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51277381/

10-16 20:51