Skip to content

Commit

Permalink
feat: create useful defautl for webpack build prod
Browse files Browse the repository at this point in the history
 This change override webpack prod, to do:

- Add/Enable cache to reduce build time for subsequenct builds
- Remove plugins that are not necessary for prod
- Disbale dev-tools i.e. .map files
  • Loading branch information
ghassanmas committed Nov 12, 2022
1 parent 8c7767c commit a7e1941
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions tutormfe/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"HOST": "apps.{{ LMS_HOST }}",
"COMMON_VERSION": "{{ OPENEDX_COMMON_VERSION }}",
"CADDY_DOCKER_IMAGE": "{{ DOCKER_IMAGE_CADDY }}",
"REMOVE_WEBPACK_BUILD_CACHE": False,
"ACCOUNT_MFE_APP": {
"name": "account",
"repository": "https://github.com/openedx/frontend-app-account",
Expand Down
7 changes: 5 additions & 2 deletions tutormfe/templates/mfe/build/mfe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ RUN touch /openedx/env/production.override \
&& echo "{{ key }}='{{ value }}'" >> /openedx/env/production.override \
{%- endfor %}
&& echo "done setting production overrides"
RUN bash -c "set -a && source /openedx/env/production && source /openedx/env/production.override && APP_ID={{ app["name"] }} npm run build"

COPY ./webpack.prod.tutor.config.js ./webpack.prod.tutor.config.js
RUN bash -c "set -a && source /openedx/env/production && source /openedx/env/production.override && APP_ID={{ app["name"] }} npm run build -- --config ./webpack.prod.tutor.config.js"
{% if MFE_REMOVE_WEBPACK_BUILD_CACHE %}
RUN rm -rf .cache
{% endif %}
{% endfor %}

####### final production image with all static assets
Expand Down
29 changes: 29 additions & 0 deletions tutormfe/templates/mfe/build/mfe/webpack.prod.tutor.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { merge } = require('webpack-merge');
const fs = require('fs');
const path = require('path');

const baseProdConfig = (
fs.existsSync('./webpack.prod.config.js')
? require('./webpack.prod.config.js')
: require('@edx/frontend-build/config/webpack.prod.config.js')
);

{% 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
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%_
baseProdConfig.devtool = false;

module.exports = baseProdConfig;

0 comments on commit a7e1941

Please sign in to comment.