Skip to content

Instantly share code, notes, and snippets.

@lcube45
Created May 11, 2022 07:26
Show Gist options
  • Save lcube45/4053f13b55ccf585297adc5dcbaf9ff7 to your computer and use it in GitHub Desktop.
Save lcube45/4053f13b55ccf585297adc5dcbaf9ff7 to your computer and use it in GitHub Desktop.
Webpack basic SASS setup
// 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