Sourcemaps with webpack css-loader

后端 未结 2 939
灰色年华
灰色年华 2021-02-01 05:16

I am struggling to get sourcemaps working with css-loader.

Output in console:

What the documentation from css-loader says:

Sourc

2条回答
  •  悲&欢浪女
    2021-02-01 06:00

    1. Enable source-maps via webpack

      ...
      devtool: 'source-map'
      ...
      
    2. You might want to enable source-maps for Sass-Files as well

      module: {
        loaders: [
          ...
          {
            test: /\.scss$/,
            loaders: [
              'style-loader',
              'css-loader?sourceMap',
              'sass-loader?sourceMap'
            ]
          }, {
            test: /\.css$/,
            loaders: [
              "style-loader",
              "css-loader?sourceMap"
            ]
          },
          ...
        ]
      }
      
    3. Use extract text plugin to extract your css into a file.

      ...
      plugins: [
        ...
        new ExtractTextPlugin('file.css')
      ]
      ...
      

提交回复
热议问题