Created
May 11, 2022 07:26
-
-
Save lcube45/4053f13b55ccf585297adc5dcbaf9ff7 to your computer and use it in GitHub Desktop.
Webpack basic SASS setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set compiled css filename | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
// clean dist folder before each build | |
const { CleanWebpackPlugin } = require('clean-webpack-plugin') | |
// remove unwanted index.js generated by webpack | |
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries') | |
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development' | |
const toCompile = { | |
import: "./scss/styles.scss", | |
}; | |
const destFolder = '/dist'; | |
module.exports = { | |
context: __dirname, | |
mode: mode, | |
entry: toCompile, | |
output: { | |
path: __dirname + destFolder | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.s[ac]ss$/i, | |
use: [ | |
MiniCssExtractPlugin.loader, | |
{ | |
loader: 'css-loader', | |
options: { | |
sourceMap: true | |
} | |
}, | |
{ | |
loader: "sass-loader", | |
options: { | |
// Prefer `dart-sass` | |
implementation: require("sass"), | |
sourceMap: true, | |
}, | |
} | |
], | |
}, | |
], | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin({filename: "[name].min.css"}), | |
new CleanWebpackPlugin(), | |
new FixStyleOnlyEntriesPlugin(), | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment