Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack production config can be optimized to trim down image size and build time #88

Open
ghassanmas opened this issue Nov 22, 2022 · 2 comments
Milestone

Comments

@ghassanmas
Copy link
Member

ghassanmas commented Nov 22, 2022

The webpack production default configuration which comes with frontend-build includes settings that we might not need for production, which when disabled shall reduce the bundle size and slightly decrease the build time.

Add to that we can also enable webpack cache for making subsequent builds faster, though it would be tricky because we would essentialy depend on docker build cache of webpack cache, so cache in cache.

Changes which I envision:

const { merge } = require('webpack-merge');
const fs = require('fs');
const path = require('path');

// Here we just check if the MFE has it's own production, so we don't overwrite just like we do for dev
const baseProdConfig = (
  fs.existsSync('./webpack.prod.config.js')
    ? require('./webpack.prod.config.js')
    : require('@edx/frontend-build/config/webpack.prod.config.js')
);


// Creating a flag to opt out from cache, though this cache would be saved not on the acutal image but on docker build cache 
// So I am not sure about the usefulness (In affecting the final image size) of it, probably we can create a flag of all those settings. 
{% if not MFE_REMOVE_WEBPACK_BUILD_CACHE  %}
// This shall boost rebuild time for subsequent builds.
// Ref docs: https://webpack.js.org/configuration/cache/#cachecachedirectory
baseProdConfig.cache= {
    type: 'filesystem',
    cacheDirectory: path.resolve(__dirname,'.cache'), 
},
{% endif %}

// Disable Unnecessary Plgugins
// Those (NewRelicPlugin, and HtmlWebpackNewRelicPlugin)  plugins are not needed specially that Relic is not supported with tutor 
// For BundleAnalyzerPlugin this definilty not required for production unless opreator would want to investage the productoin build
baseProdConfig.plugins = baseProdConfig.plugins
.filter(plugin => (plugin.constructor.name !== 'NewRelicPlugin'))
.filter(plugin => (plugin.constructor.name !== 'HtmlWebpackNewRelicPlugin'))
.filter(plugin => (plugin.constructor.name !== 'BundleAnalyzerPlugin'));

// Don't generate/incldue .map files _Reduces dist to ~-70%_
// The .map files can be utilized in development mode Or with relic, those files are needed to know if an error to be thrown what was the file it was fired from. 
// Again it will be useful for development mode or/and with Relic. In deveopment mode browser dev tool might request those files in order to make error messages more readable/useful. 
baseProdConfig.devtool = false;

module.exports = baseProdConfig;
@arbrandes arbrandes mentioned this issue Nov 22, 2022
17 tasks
@regisb regisb changed the title Add useful defaults for webpack production config Webpack production config can be customized to trim down image size and build time Nov 28, 2022
@regisb regisb changed the title Webpack production config can be customized to trim down image size and build time Webpack production config can be optimized to trim down image size and build time Nov 28, 2022
@arbrandes arbrandes added this to the Palm.1 milestone Dec 7, 2022
@johnvente
Copy link

johnvente commented Jun 20, 2023

Hi @ghassanmas ! I would like to contribute with this 👀

@ziafazal
Copy link

ziafazal commented Jan 2, 2024

Hi @ghassanmas what is the status of this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

4 participants