Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack sass loader with sourcemaps and url statements

I have read that in order to have source maps, I have to use absolute urls in the url('') statement. I did it this way :

body
    background-image: url('/elements/assets/tmp_background.jpg')

It works when I remove the sourceMap option from the css loader, it does not if I activate it.

I think I might have failed somewhere on the absolute path point, do you have any ideas?

Here is my config file :

module.exports = {
  devtool: 'source-map',
  entry: [
    'webpack/hot/dev-server',
    'webpack-dev-server/client?http://localhost:8080',
    path.resolve(__dirname, 'elements/main.js'),
  ],
  output: {
    path: 'dist',
    publicPath: '/',  // Prefix for all the statics urls
    filename: 'bundle.js',
  },
  resolve: {
    root: path.resolve(__dirname),
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader?presets[]=es2015',
      },
      { test: /\.css$/,  loaders: ['style', 'css'] },
      { test: /\.scss$/, loaders: ['style', 'css?sourceMap', 'sass?sourceMap'] },
      { test: /\.sass$/, loaders: ['style', 'css?sourceMap', 'sass?sourceMap&indentedSyntax=true'] },
      { test: /\.jade$/, loaders: ['ngtemplate', 'html', 'jade-html'] },
      { test: /\.(png|gif|jp(e)?g)$/, loader: 'url-loader?limit=8192' },
      { test: /\.(ttf|eot|svg|woff(2))(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=50000' },
    ],
  },
};

On a more general idea, I could not find a working example of what I'm trying to do. I would be very interested if you can redirect me to that.

like image 272
Raphaël Boucher Avatar asked Nov 09 '22 01:11

Raphaël Boucher


1 Answers

The publicPath can be used to fix this, until a cleaner solution appears.

See https://github.com/webpack/css-loader/issues/29

like image 96
Raphaël Boucher Avatar answered Nov 14 '22 23:11

Raphaël Boucher