I am using webpack to compile my scss files which works fine when initially running npx webpack
or npx webpack --watch
.
When using npx webpack --watch
, only my declared SCSS file (app.scss) in my index.js is watched and hot loads fine.
My @import[ed] SCSS files from app.scss aren’t being watched, however if I make changes to these imports then save app.scss, it recompiles everything.
Is there a way to make it so that my imported files are also watched
index.js
import 'src/styles/app.scss';
app.scss
@import '../settings/**/*.scss';
@import '../components/**/*.scss';
webpack.config.js:
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const globImporter = require('node-sass-glob-importer');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
module.exports = {
entry: './index.js',
output: {
filename: 'scripts/index.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: "sass-loader",
options: {
sassOptions: {
importer: globImporter()
},
sourceMap: true,
}
}
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'styles/app.css',
}),
],
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin(),
]
},
watch: true,
mode: 'development'
};
If it’s any help, I’m running:
- Running Win 11 Home 22631.3737
- Node v20.13.1
- PHP 8.1.25 (cli) (built: Oct 25 2023 08:06:57)
- npm 10.5.2
and package.json:
"devDependencies": {
"@babel/core": "^7.24.6",
"@babel/preset-env": "^7.24.6",
"babel-loader": "^9.1.3",
"browser-sync": "^3.0.2",
"browser-sync-webpack-plugin": "^2.3.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^6.11.0",
"css-minimizer-webpack-plugin": "^7.0.0",
"html-webpack-plugin": "^5.6.0",
"mini-css-extract-plugin": "^2.9.0",
"node-sass": "^9.0.0",
"node-sass-glob-importer": "^3.0.2",
"open": "^7.0.0",
"postcss-loader": "^8.1.1",
"sass": "^1.49.11",
"sass-loader": "^13.3.3",
"style-loader": "^4.0.0",
"webpack": "^5.92.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
},
Been scratching my head for a while.. many thanks!