diff --git a/README.md b/README.md index d6874362..cd6e059c 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,24 @@ headers: { RemoteUser: 'janedoe' } ``` + +#### `modifyWebpackConfig` +A function which, when provided, can be used to enhance/override or replace the webpack configuration used. The function will be invoked with the current webpack configuration object and a reference to the workflow settings. + +**Ex:** +```js +modifyWebpackConfig: (webpackConfig, settings) => { + // Add Subresource Integrity (SRI) security feature + webpackConfig.output = { crossOriginLoading: 'anonymous' }; + // Note: SriPlugin would be imported in your workflow.js to be referenced here + webpackConfig.plugins.push(new SriPlugin({ + hashFuncNames: ['sha256', 'sha384'], + // only enable it for non-development builds + enabled: !settings.isDevelopment(), + })); + return webpackConfig; +} +``` ## FAQ ### How to setup a development environment to match the deployment environment? diff --git a/packages/availity-workflow-angular/karma.conf.js b/packages/availity-workflow-angular/karma.conf.js index fa4bf319..3f412984 100644 --- a/packages/availity-workflow-angular/karma.conf.js +++ b/packages/availity-workflow-angular/karma.conf.js @@ -1,6 +1,6 @@ const settings = require('availity-workflow-settings'); -const webpackConfig = require('./webpack.config.test'); +let webpackConfig = require('./webpack.config.test'); if (settings.isCoverage()) { webpackConfig.module.rules.push({ @@ -13,6 +13,12 @@ if (settings.isCoverage()) { }); } +const { modifyWebpackConfig } = settings.config(); + +if (typeof modifyWebpackConfig === 'function') { + webpackConfig = modifyWebpackConfig(webpackConfig, settings) || webpackConfig; +} + const karmaConfig = { basePath: settings.app(), diff --git a/packages/availity-workflow-angular/karma.conf.sauce.js b/packages/availity-workflow-angular/karma.conf.sauce.js index ba23f3e1..b026730d 100644 --- a/packages/availity-workflow-angular/karma.conf.sauce.js +++ b/packages/availity-workflow-angular/karma.conf.sauce.js @@ -1,6 +1,12 @@ const settings = require('availity-workflow-settings'); -const webpackConfig = require('./webpack.config.test'); +let webpackConfig = require('./webpack.config.test'); + +const { modifyWebpackConfig } = settings.config(); + +if (typeof modifyWebpackConfig === 'function') { + webpackConfig = modifyWebpackConfig(webpackConfig, settings) || webpackConfig; +} const karmaConfig = { basePath: settings.app(), diff --git a/packages/availity-workflow/scripts/build.js b/packages/availity-workflow/scripts/build.js index 3bd34d1e..ed9f7768 100644 --- a/packages/availity-workflow/scripts/build.js +++ b/packages/availity-workflow/scripts/build.js @@ -21,7 +21,7 @@ function bundle(config) { // Check arguement or CLI arg or default to false const shouldProfile = (config && config.profile) || argv.profile || false; - const webpackConfig = shouldProfile ? plugin('webpack.config.profile') : plugin('webpack.config.production'); + let webpackConfig = shouldProfile ? plugin('webpack.config.profile') : plugin('webpack.config.production'); Logger.info('Started compiling'); const spinner = ora('Running webpack'); @@ -45,6 +45,12 @@ function bundle(config) { }) ); + const { modifyWebpackConfig } = settings.config(); + + if (typeof modifyWebpackConfig === 'function') { + webpackConfig = modifyWebpackConfig(webpackConfig, settings) || webpackConfig; + } + webpack(webpackConfig).run((err, stats) => { spinner.stop(); diff --git a/packages/availity-workflow/scripts/start.js b/packages/availity-workflow/scripts/start.js index 03a9e227..91f3bfc9 100644 --- a/packages/availity-workflow/scripts/start.js +++ b/packages/availity-workflow/scripts/start.js @@ -107,6 +107,12 @@ function web() { }) ); + const { modifyWebpackConfig } = settings.config(); + + if (typeof modifyWebpackConfig === 'function') { + webpackConfig = modifyWebpackConfig(webpackConfig, settings) || webpackConfig; + } + const compiler = webpack(webpackConfig); compiler.plugin('invalid', () => {