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.

Webpack, Autoprefixer and Source Maps

See original GitHub issue

Hi there,

I have an issue and I don’t know exactly where I should mention it. But I think this is the best place. I hope you can help me further.

I have a Webpack config file, to compile all Javascript and SCSS. For the SCSS I use the sass-loader, then resolve-url-loader, then postcss-loader and the css-loader is the last one.

In the options I pass the sourceMap: true, so I’ll have source maps for developing. But when I use autoprefixer, the linenumbers of the sourcemap aren’t correct.

I made a simple example with display: flex. Autoprefixer will add two lines for that. But when I check my Chrome Developers Console, the linenumbers are incorrect. The sourcemaps have included the two new lines, but in de .scss file I can only see display: flex;.

It is a little bit hard to explain, but I hope you understand.

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

let webpackConfig = {

	entry: {
		'/js/main': [
			path.resolve( __dirname, 'src/js/main.js' ),
			path.resolve( __dirname, 'src/scss/main.scss' )
		]
	},

	output: {
		path: path.resolve( __dirname, 'public' ),
		filename: '[name].js',
		chunkFilename: 'js/[name].js'
	},

	devtool: false,

	stats: {
		hash: false,
		version: false,
		timings: false,
		children: false,
		errors: true
	},

	module: {
		rules: [{
			test: /\.s[ac]ss$/,
			use: ExtractTextPlugin.extract({

				fallback: 'style-loader',

				use: [{
					loader: 'css-loader',
					options: {
						importLoaders: 3,
						sourceMap: true
					}
				}, {
					loader: 'postcss-loader',
					options: {
						sourceMap: true
					}
				}, {
					loader: 'resolve-url-loader'
				}, {
					loader: 'sass-loader',
					options: {
						precision: 8,
						outputStyle: 'expanded',
						sourceMap: true
					}
				}],
			})
		}]
	},

	plugins: [

		new ExtractTextPlugin({
			filename: '/css/main.css',
			allChunks: true
		}),

		new webpack.LoaderOptionsPlugin({
			minimize: process.env.NODE_ENV === 'production',
		}),

		new webpack.DefinePlugin({
			'process.env': {
				NODE_ENV: JSON.stringify( process.env.NODE_ENV )
			}
		})
	]
}

module.exports = webpackConfig;

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
michael-ciniawskycommented, Jul 11, 2017

Could you try without resolve-url-loader, it uses rework (deprecated) internally, just to have a third CSS tool in there 😉 and uses sourcemaps to resolve urls somehow.

Another source might be between postcss-loader => css-loader updating the sourcemap incorrectly, if you use just the simple main.scss file without any url() or @import, you can remove css-loader temporarily and just use postcss-loader as the loader will export a module instead of a {String} then. Also the { sourceMap: 'inline' } (postcss-loader) option might be helpful, which inlines the sourcemap generated by PostCSS directly as an annotation comment into the source (Firefox || Chrome >= 58 should support it), so we can ensure at least if it’s an issue with postcss-loader or not. If you could provide small test repo I can also take a look into it 😃

1reaction
aicommented, Jul 11, 2017

Strange. Could you create a issue in postcss-loader. I am not sure that all options are passed correctly.

But, honesty, source maps between different tools (like Sass > PostCSS) doesn’t always work perfectly.

This is why using one tool for most of tasks is better. Also it will be much faster.

Read more comments on GitHub >

github_iconTop Results From Across the Web

source-map-loader - webpack
The source-map-loader extracts existing source maps from all JavaScript entries. This includes both inline source maps as well as those linked via URL....
Read more >
Autoprefixer is causing node-sass source map to point to the ...
Watch .scss files for changes. · On change, compile the SCSS to CSS with node-sass and generate a source map with node-sass at...
Read more >
Solution to no CSS source map file generated under ...
After some trial and error, I have found the culprit which is the "Optimize CSS Assets Webpack Plugin". I use this plugin to...
Read more >
Source Maps - SurviveJS
Webpack can generate both inline or separate source map files. The inline ones are included to the emitted bundles and are valuable during...
Read more >
Setting up Webpack, Babel and React from scratch - Part 2
To enable source maps, we'll pass the sourceMap option to the sass and the css loaders ... At the top of our webpack...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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