Font-awesome-sass-loader变量导入不适用于Webpack 4

时间:2018-07-13 10:48:42

标签: sass font-awesome webpack-4

我一直在尝试在Webpack4中用font-awesome-sass-loader加载font-awesome,但是似乎我有导入问题。这是我从Webpack获得的错误消息:“ 找不到要导入的文件或不可读的文件:〜font-awesome / scss / variables ”。

这是我的webpack.config.js文件:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
    entry: path.resolve(__dirname, 'src/js/scripts.js'),
    output: {
        path: path.resolve(__dirname,'dist'),
        filename: '[name].[chunkhash].js'
    },
    module: {
        rules: [
            //FONTS
            {
                test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 10000,
                            mimetype: 'application/font-woff'
                        }
                    }
                ]
            },
            {
                test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                use: [
                    { loader: 'file-loader' }
                ]
            },            
            //JS
            {
                //Tipo de Archivo quiero reconocer
                test: /\.js$/,
                exclude: /node_modules/,
                //Que Loader se encarga del tipo de extension de archivo
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets:['babel-preset-env']
                    }
                },
            },                                   
            //IMAGES
            {
                test: /\.(jpg|png|gif)$/,
                use: {
                    loader: 'file-loader',
                    options: {
                        outputPath: 'img/',
                        name:'[name].[ext]', 
                    }
                }
            },                       
            //SASS
            {
                test: /\.scss$/,
                use: ['style-loader', MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
            }           
        ]
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename:'css/style.min.[contenthash].css',
        }),
        new HtmlWebpackPlugin ({
            inject: false,
            hash: true,
            template: './src/index.html',
            filename: 'index.html'        
        }),
        new WebpackMd5Hash()   
    ]
}

这是我的index.js:

import '../styles/style.scss';
require.context("../img/", true, /\.(png|svg|jpg|gif)$/);
require("font-awesome-sass-loader");

0 个答案:

没有答案