I have an app structure like this:
/src
/app.js
/styles.css
/images
/img.png
The app.js file content is:
const styles = require('./styles.css');
console.log(styles) // => here I want to have a url to the css file under the public folder
The src/styles.css file content is as follows:
.element {
background: url(./images/img.png);
}
So, the js file requires the css file. And css file requires png file.
I want all the files to be exported to the public folder:
public/app.js
const styles = 'styles.css' // => path to public/styles.css
console.log(styles)
pubic/styles.css
.element {
background: url(img.png); /* path to public image file */
}
public/img.png (source image copy)
The filenames are not important. The public folder output is what important. Css file is exported as a separate file, it contains the proper path to the image. The JS file knows the path of the public css file.
If there was no image present, the file-loader could be used to import css file. But in my case css file has first to be processed by css-loader in order to resolve the url() path.
Applying css-loader before the file-loader breaks things because returns JS code instead of CSS.
Is there a way to build a pipe to achieve the wanted result?