fontswebpacknode-modulespostcsscssnext

How can I import fonts from node_modules with webpack and postcss/cssnext


I'm need to use font-awesome.
PostCSS tries to find font in source directory but not in node_modules/font-awesome/fonts

Error text:

Error: Can't resolve '../fonts/fontawesome-webfont.eot?v=4.7.0' in 'F:\OpenServer\domains\polymer-postcss\src'

Import:

@import "font-awesome/css/font-awesome.min.css";

webpack.config.js:

var cssPlugin = require('extract-text-webpack-plugin');
module.exports = {
    entry:      {app: './src/app.js'},
    output: {
        path:       './dist',
        filename:   '[name].js',
        publicPath: '/dist/',

    },
    plugins: [new cssPlugin({filename: '[name].css'}),],
    module: {
        rules: [
            {
                test: /\.css$/,
                loader: cssPlugin.extract({
                    use: 'css-loader?importLoaders=1&sourceMap!postcss-loader?sourceMap',
                }),
            },
            {   
                test: /\.(svg|png|gif|jpe?g|woff|woff2|eot|ttf)$/i,
                use: "url-loader?limit=10000&name=[path][name].[ext]?[hash]"
            },
        ],
    },
}

postcss.config.js

module.exports = {
    plugins: {
        'postcss-import': {},
        'postcss-cssnext': {
            browsers: ['last 2 versions', '> 20%'],
        },
    },
};

Solution

  • This PostCSS module really solved my problem

    https://github.com/devex-web-frontend/postcss-assets-rebase