Skip to content

Commit

Permalink
FW-6217 Minify JS on prod (#679)
Browse files Browse the repository at this point in the history
* Modified webpack config to reduce bundle size, split CSS into a separate file in prod

* Added conditional for css style loaders in dev vs prod

* removed CSS minimizer, and added chunkFilename

* removed extra packages

* removed unused imports
  • Loading branch information
sahil97 authored Nov 14, 2024
1 parent 1703071 commit dade1e6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"eslint-plugin-testcafe": "^0.2.1",
"husky": "^9.1.6",
"lint-staged": "^15.2.9",
"mini-css-extract-plugin": "^2.9.2",
"mochawesome": "^7.1.3",
"prettier": "^2.8.8",
"testcafe": "^3.6.2",
Expand Down
15 changes: 14 additions & 1 deletion webpack/webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const path = require('path')
const alias = require('./webpack.alias')

const is_prod = process.env.NODE_ENV == 'production'

module.exports = (env, definitions) => ({
cache: {
compression: 'gzip',
Expand All @@ -24,6 +27,7 @@ module.exports = (env, definitions) => ({
},
output: {
filename: '[name].[contenthash].js',
chunkFilename: '[name].[contenthash].js',
path: alias.dist,
},
module: {
Expand All @@ -41,7 +45,11 @@ module.exports = (env, definitions) => ({
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader', 'postcss-loader'],
use: [
is_prod ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'postcss-loader',
],
},
{
test: /\.(png|svg|jpg|jpeg|gif|webp)$/i,
Expand All @@ -62,6 +70,11 @@ module.exports = (env, definitions) => ({
),
...definitions,
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].css',
ignoreOrder: false,
}),
new HtmlWebpackPlugin({
template: './public/index.html',
templateParameters: {
Expand Down

0 comments on commit dade1e6

Please sign in to comment.