Sourcemaps with webpack css-loader

Deadly 提交于 2019-12-02 18:14:24
  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')
    ]
    ...
    

There are some properties you need to set in your webpack config.

{
   output: {
      ...
   },

   debug: true, // switches loaders into debug mode
   devtool: 'eval-cheap-module-source-map', // or one of the other flavors, not entirely sure if this is required for css source maps
   ...
}

The webpack dev server doesn't have debug on by default. Instead of setting it in your config, you can also pass the -d or --debug flag to webpack-dev-server via the CLI.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!