0

I'm using Webpack together with the css-loader, sass-loader and extract-text-webpack-plugin plugins to bundle styles for my application.

However, I'm seeing weird source map/resource paths using the plugins shown below:

The actual app.scss path is ./src/styles/app.scss

correct path

However the source map path for the file becomes ./src/styles/src/styles/app.scss and the absolute resource path:
C:/Users/m51n/source/repos/source-map-path/src/styles/src/styles/app.scss (does not exist)

weird path

I've created a sample project here-- using the source map example from the sass-loader docs and code from the extract-text-webpack-plugin docs here

Here is the webpack.config.js used in the above project:

const CleanWebpackPlugin = require("clean-webpack-plugin")
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const path = require("path")

module.exports = {
  entry: {
    app: "./src/styles/app.scss"
  },
  devtool: "inline-source-map",
  output: {
    filename: "[name].[hash].js",
    path: path.resolve("./dist"),
    // devtoolModuleFilenameTemplate: (info) => {
    //   console.log(info.resourcePath)
    //   console.log(info.absoluteResourcePath)

    //   return `webpack:///${info.resourcePath}`
    // }
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: ["style-loader"],
          use: [
            {
              loader: "css-loader",
              options: {
                sourceMap: true
              }
            },
            {
              loader: "sass-loader",
              options: {
                sourceMap: true
              }
            }
          ]
        })
      }
    ]
  },
  resolve: {
    extensions: [".js", ".scss", ".css"]
  },
  plugins: [
    new CleanWebpackPlugin(["dist"]),
    new HtmlWebpackPlugin({
      template: "src/index.html"
    }),
    new ExtractTextPlugin({
      filename: "app.[contenthash].css"
    })
  ]
}

Expected source map path returned by the plugin in this case would be ./src/styles/app.scss and absolute resource path as it exist on disk:
C:/Users/m51n/source/repos/source-map-path/src/styles/app.scss

How can I rewrite the sample code above so that I get the desired source map paths?

Related GitHub issue for reference: https://github.com/webpack-contrib/sass-loader/issues/484

  • I've edited the original question to include more information related to this issue, hopefully someone has any idea how to approach my problem. – Jean Alexander Woldner Jan 06 '18 at 09:18
  • I have the same problem. Posted my question here: https://stackoverflow.com/questions/52256634/chrome-debugger-no-domain-section-showing-duplicated-paths-after-webpack. There is way too little support for this... – Magnus Sep 10 '18 at 11:19

0 Answers0