8

I need all iamges to be relative to the stylesheet local. If I add root=. , which I though prepended to url(/path/) then I need to add a file-loader and the path is wrong anyway.

If I write relative path directly in the CSS then I also need to use a fileloader. If I write non-relative path in CSS then there is no change in CSS paths but images cannot be loaded since they must be relative to the stylesheet location, there is no other way for them to be loaded properly. I also use ExtractTextPlugin to have separate files for CSS but paths are wrong anyway, with or without ExtractTextPlugin.

Andreas
  • 327
  • 2
  • 6

1 Answers1

12

Figured it out. Needed to add ?name=[path][name].[ext] to the file-loader.

{ test: /\.jpg$/, loader: "file-loader?name=[path][name].[ext]" }
Andreas
  • 327
  • 2
  • 6
  • 2
    Can you please post your webpack config. I am in the similar situation and I need to see the relevant options of the config, to get it work. Thank you :) – redhead Apr 25 '16 at 08:29
  • It worked for me, no idea how. webpack is just black magic ! I'm also using an absolute public path : `output: { path: APP, filename: 'bundle.js', publicPath: '/shop' }` – cnlevy May 05 '16 at 07:03
  • @Andreas - What did you pass in the css file? – Monkviper Jul 27 '16 at 18:54