I'm trying to use webpack for the first time and I would like to use SASS instead of CSS but I can't resolve a problem with my sass-loader.
my webpack.common.js:
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'js/main.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: ['style-loader', 'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('autoprefixer')()
]
}
},
'sass-loader']
},
{
test: /\.(jpg|jpeg|gif|png)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 102400,
name: '[name].[ext]',
outputPath: 'images'
}
}
]
},
{
test: /\.(woff(2)?|ttf|eof|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts'
}
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
]
}
]
}
}
I've already install sass-loader and node-sass package with npm and I load my webpack.common.js file in a webpack.dev.js file :
const merge = require('webpack-merge');
const common = require('./webpack.common');
const path = require('path');
module.exports = merge(common, {
mode: 'development',
devServer: {
port: 3000,
contentBase: path.join(__dirname, 'dist'),
watchOptions: {
ignored: /node_modules/
}
}
});
Honestly I don't think the problem is caused by this file. To run my app I use npm run dev.
Atleast, there is my sass file (in src/styles/styles.scss):
@import '~bootstrap/scss/bootstrap.scss';
@import '~@fortawesome/fontawesome-free/css/all.css';
body {
background-color: #eee;
}
Do you know how can I resolve this problem ? I know this question was asked a lot of time, I searched on github and stackoverflow before post but I didn't succeed to make my app work.
Thank you in advance.