question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] source-maps with css or sass?

See original GitHub issue

Hi,

I am using sass-loader to compile sass code. Can we have the source-map to trace back the source file with webpack for sass?

Currently, I setup Sass-loader by

 { test: /\.scss/, loader: "style-loader!sass-loader?outputStyle=expanded" },

with

    cache: true,
    debug: true,
    devtool: 'source-map',
    'output-pathinfo': true,

Is it possible to trace back the source sass file in chrome dev tools?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:33 (5 by maintainers)

github_iconTop GitHub Comments

35reactions
kyle-johnsoncommented, Feb 18, 2015

This works for me:

{ test: /\.scss$/, loader: ExtractTextPlugin.extract('style-loader',
 'css-loader?sourceMap!sass-loader?outputStyle=expanded&sourceMap=true&sourceMapContents=true') }
7reactions
shannonsumner-zzcommented, Mar 9, 2017

I was able to get it working by doing the following:

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

module.exports = {
    entry: [
        path.join(__dirname, 'src/index')
    ],
    output: {
        path: path.join(__dirname, 'dist'),
        publicPath: "/dist",
        filename: 'js/bundle.js'
    },
    devtool: 'source-map',
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query: {
                    presets: [ 'es2015' ],
                    plugins: [ 'transform-runtime' ]
                }
            },
            {
                test: /(\.scss|\.css)$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: 'css-loader',
                            options: {
                                sourceMap: true
                            }
                        },
                        {
                            loader: 'sass-loader',
                            options: {
                                sourceMap: true,
                                outFile: 'css/bundle.css',
                                outputStyle: 'expanded',
                            }
                        }
                    ],
                })
            },
            {
                test: /\.(png)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 100000,
                        outputPath: '../images/',
                        publicPath: '/dist/images/'
                    }
                },
            }, {
                test: /\.jpg$/,
                use: {
                    loader: 'file-loader',
                    options: {
                        outputPath: '../images/',
                        publicPath: '/dist/images/'
                    }
                }
            }, {
                test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 10000,
                        outputPath: '../fonts/',
                        publicPath: '/dist/fonts/',
                        mimetype: 'application/font-woff'
                    }
                }
            }, {
                test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                use: {
                    loader: "file-loader",
                    options: {
                        outputPath: '../fonts/',
                        publicPath: '/dist/fonts/'
                    }
                }
            }
        ],
    },
    resolve: {
        modules: [ 'node_modules', './src' ]
    },
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        }),
        new ExtractTextPlugin({ filename: 'css/bundle.css', disable: false, allChunks: true }
        )
    ]
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I Use Source Maps in Production? | CSS-Tricks
Typically, source maps are a configuration option from the preprocessor. Here's Babel's options. I believe that with Sass, you don't even have ...
Read more >
No sourcemap for CSS - sass - Stack Overflow
1 Answer 1 · never — causes no source maps to be generated at all. · always — source maps will always be...
Read more >
Using source maps in Sass - Mario Araque
One of the new features in Sass 3.3 is source maps. We can use it to improve the debugging of our Sass code...
Read more >
Debugging Sass with Sourcemaps (How To) - Treehouse
Sass creates a sourcemap to help you see the original Sass/SCSS source while debugging in the browser. Sourcemaps contain information that ...
Read more >
sass-loader - webpack - JS.ORG
sass / .scss file in which they are specified (like in regular .css files). Thankfully there are a two solutions to this problem:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found