3

There is my extremly simple test.scss file:

@font-face {
    font-family: Roboto;
    src: url("../fonts/Roboto/Roboto-Regular.ttf");
    font-weight: 400;
}

.test {
    display: flex;
    font-family: Roboto;
}

And this is my webpack config:

const path = require("path");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    mode: 'development',
    plugins: [
        new MiniCssExtractPlugin(),
    ],
    entry: './src/sass/test.scss',
    output: {
        path: path.resolve(__dirname, 'dist/css/'),
        filename: '[name].css',
    },
    module: {
        rules: [
            {
                test: /\.scss$/i,
                use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
            }
        ]
    },
    devtool: 'source-map'
};

When running webpack it throws the following error:

ERROR in ./src/sass/test.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleNotFoundError: Module not found: Error: Can't resolve '../fonts/Roboto/Roboto-Regular.ttf'

So the mini-css-extract-plugin has a problem with my font. Already tried different approaches but anything worked. I am happy about any solution. It does not seem that easy to compile sass in css using webpack ...

michaelT
  • 1,533
  • 12
  • 41

0 Answers0