Skip to content

css-loader with sourceMap: true cause adding style tag delayed #613

Closed
@Aqours

Description

@Aqours

Version: 0.28.7

webpack.config.js

const path = require('path');
const webpack = require('webpack');

module.exports = {
    entry: './src/index.js',
    devtool: 'inline-source-map',
    module: {
        rules: [
            // babel-loader, ...
            {
                test: /\.less$/,
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true, // [1] `sourceMap: true` option will cause some problems.
                            minimize: {
                                discardComments: { removeAll: true }
                            }
                        }
                    },
                    {
                        loader: 'less-loader',
                        options: { sourceMap: true }
                    }
                ]
            }
        ]
    },
    output: {
        path: path.resolve(__dirname, 'dist/'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.jsx', '.js']
    }
};

// src/index.js file
import './less/index.less';
// other code, ...

What is the current behavior?
bundle.js will add <style> tag to <head> tag when page loading bundle.js.
normally, <style> tag will added firstly.
actually, <style> tag added delayed when i setting sourceMap: true[1], which cause page flickering and error result style computed by scripts.

It works great when set sourceMap: false[1].

If the current behavior is a bug, please provide the steps to reproduce.
repo link

webpack version: 3.6.0
node.js version: 8.0.0
Operating System: Windows 10 x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions