1

I am trying to generate a css sourcemap from webpack. However, currently the css.map file that is generate is largely empty.

{"version":3,"sources":[],"names":[],"mappings":"","file":"si-styles.css","sourceRoot":""}

I understand that I need to add something similar to the below

css-loader?sourceMap

But I am unsure how I chain this with importLoaders = 1, which I currently have within my webpack.config.js.

const webpack = require('webpack');
const path = require('path');
//post css
var precss       = require('precss');
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var postcssImport = require('postcss-import');

module.exports = {

  context: __dirname + '/frontend',
  devtool: 'source-map',
  entry: "./index.js",
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, './static')
},
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/,
        query: {
          presets: ['es2015']
        }
      },
      {
        test:   /\.css$/,
        loader: ExtractTextPlugin.extract('style-loader', '!css-loader?importLoaders=1!postcss-loader')
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin("si-styles.css")
  ],
  // postcss: [
  //             precss,
  //             autoprefixer({ browsers: ['last 2 versions']  })
  // ]
   postcss: function(webpack) {
        return [
            postcssImport({ addDependencyTo: webpack }), // Must be first item in list
            precss,
            autoprefixer({ browsers: ['last 2 versions']  })
        ];
    },

}

1 Answer 1

2

I just found an example with the correct way to do this. I have used '&' to chain together ie

 {
    test:   /\.css$/,
    loader: ExtractTextPlugin.extract('style-loader', '!css-loader?sourceMap&importLoaders=1!postcss-loader')
  }
Sign up to request clarification or add additional context in comments.

1 Comment

You should accept your own answer stackoverflow.com/help/self-answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.