The problem is file-loader will always inject the same URL to the both HTML and CSS files.
I have got the flowing project structure
Webpack File-loader configuration
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: "assets/images",
publicPath: '../images'
}
}
]
}
When I use publicPath: '../images' It will inject flowing URL to the HTML and CSS file
HTML
<img src='../images/team-1@2x.png'/>
CSS
background-image: url(../images/test-image.jpg);
both URLs are the same but it's ok for the CSS file.
When I use publicPath: './assets/images' It will inject flowing URL to the HTML and CSS file
HTML
<img src='./assets/images/team-1@2x.png' />
CSS
background-image: url(./assets/images/test-image.jpg);
both URLs are the same but it's ok for the HTML file.
Actually what I want to achieve is File loader will inject different URL to the HTML and CSS files.
Look like this
HTML
<img src='./assets/images/team-1@2x.png' />
CSS
background-image: url(../images/test-image.jpg);
How can I configure Webpack for getting exactly above result