Pass relative path using `resourcePath` to data option
I'm wondering how I can get the current sass file path (resourcePath in the loader src), to the data option to use in my sass file.
My use case is i'm trying to pass path.relative(...) from the sass file to the images folder, so I won't have to write url(../../../../dist/images/foo.jpg) in scss files. Ideally it might look something like this:
...
sassLoader: {
includePaths: [
path.resolve(__dirname, 'src/scss')
, path.resolve(__dirname, 'craft/templates/components')
],
outputStyle: ISPROD ? 'compressed' : 'expanded'
, data: `
$image-path: ${path.relative(resourcePath, 'src/images/')}; // no good :(
$env: ${process.env.NODE_ENV};
`
},
...
This way, no matter how deep a sass file might be in the folder structure, it'll have a relative path to the images folder - and hopefully url()'s can then be properly parsed by file/url loaders!
You can try webpack's resolve.root option. Just set the dist folder as resolve.root and you should be able to just write url(images/foo.jpg).
I won't add any environment variables because this makes everything even a lot more hackier. The data option is already hacky enough.
Sweet thanks.