Z
Z
zwezew2018-12-13 12:28:55
JavaScript
zwezew, 2018-12-13 12:28:55

Why doesn't webpack always load css via require?

In Js file I use this code

require('ion-rangeslider');
require('ion-rangeslider/css/ion.rangeSlider.css');

On the server, css works, not always when building. Why doesn't webpack always load css via require?
Build/Development Settings
module.exports = function(env) {
  process.env.mode = env;
    if (env === 'production') {
    return merge([
      common,
      extractCSS(),
      uglifyJS,
    ]);
  } else if (env === 'development') {
        return merge([
            common,
            devserver(),						
      sass(),
      css(),
        ]);
    }
};

css loader config
spoiler
module.exports = function(paths) {
    return {
        module: {
            rules: [
                {
                    test: /\.css$/,
                    include: paths,
                    use: ['style-loader','css-loader','postcss-loader']
                }
            ]
        }
    };
};


css extract
spoiler
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = function(paths) {
    return {
        module: {
            rules: [
                {
                    test: /\.scss$/,
                    include: paths,
                    use: ExtractTextPlugin.extract({
                        publicPath: '../../',
                        fallback: 'style-loader',
            use: [{
                            loader: 'css-loader',
                            options: { importLoaders: 1 },
                        },
                        'postcss-loader','sass-loader'],
                    }),
                },
                {
                    test: /\.css$/,
                    include: paths,
                    use: ExtractTextPlugin.extract({
            publicPath: '../../',
                        fallback: 'style-loader',
            use: [{
                            loader: 'css-loader',
                            options: { importLoaders: 1 },
                        },
                        'postcss-loader'],
                    }),
                },
            ],
        },
        plugins: [
      new ExtractTextPlugin('assets/css/main.css'),
        ],
    };
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question