Problem: as webpack will not understand relative path if image is not there.
Soltuion:
1. use absolute path
2. use options and set url to false
3. use raw loder as it will loder url as string
Here are the example use cases.
module:{
rules:[
{
test: /\.s[ac]ss$/,
use: ExtractTextPlugin.extract({
//use: ['css-loader', ‘sass-loader’] ,
use:[
{
loader: ‘css-loader’,
options: {url: false}
},
‘sass-loader’
]
})
}
]
}
Example with raw-loader
module: {
rules:[
test: /\.s[ac]ss$/,
use: ExtractTextPlugin.extract({
use: ['raw-loader', ‘sass-loader’],
fallback: ‘style-loader’
})
]
}
also install raw-loader
npm install raw-loader --save-dev
Want to use relative path then you should specify image urls too and use file-loader
it will move file and rename with some hash you can specify your own renaming options.
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: ‘file-loader’,
options: {
name: ‘images/[name].[hash].[ext]’
}
}
Remember when using “options” field you have to use “loader” field instead of “use” field
So rule of the thumb is when using relative path make sure image exits there otherwise use absolute path.