Skip to content

Commit

Permalink
Move webpack config for sass to a separate directory
Browse files Browse the repository at this point in the history
Sass files will be compiled into CSS files into the same folder (/static/css/) as it was done with libsass and setuptools.
The resulting files in /static/css will have same layout and names as with the previous solution, except for /static/css/foundation folder. It is dropped completely since it was empty when built with setuptools. This is expected since /sass/foundation folder contains only Sass partials.
  • Loading branch information
podliashanyk committed Mar 5, 2024
1 parent 1e59707 commit 40e790c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions frontend/webpack.sass.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const path = require('path');
const glob = require('glob');

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');

const isProduction = process.env.NODE_ENV === 'production';

const stylesHandler = MiniCssExtractPlugin.loader;

const config = {
entry: {
nav: path.resolve(__dirname, '../python/nav/web/sass/nav.scss'),
...glob.sync('../python/nav/web/sass/nav/**.scss').filter(v => !path.parse(v).name.startsWith('_')).reduce(function (obj, el) {
obj[`nav/${path.parse(el).name}`] = el;
return obj
}, {}),
'font-awesome/font-awesome': path.resolve(__dirname, '../python/nav/web/sass/font-awesome/font-awesome.scss'),
},
output: {
path: path.join(__dirname, '../python/nav/web/static/css'),
clean: true,
},
devServer: {
open: true,
host: 'localhost',
},
plugins: [
new MiniCssExtractPlugin(),
new RemoveEmptyScriptsPlugin(),
],
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [stylesHandler, 'css-loader', 'sass-loader'],
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: 'asset'
},
],
},
};

module.exports = () => {
if (isProduction) {
config.mode = 'production';


} else {
config.mode = 'development';
}
return config;
};

0 comments on commit 40e790c

Please sign in to comment.