Skip to content

Commit

Permalink
feat(availity-workflow): add option to allow user to modify the webpa…
Browse files Browse the repository at this point in the history
…ck config

Adds modifyWebpackConfig option to workflow.js. When it is a function it will be called with the current webpack config and a reference to the workflow settings
modifyWebpackConfig can be used to modify or replace the webpack config by returning the desiered final webpack config

Fixes #134, Fixes #146
  • Loading branch information
TheSharpieOne committed Mar 12, 2018
1 parent 5166519 commit 872dad2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 7 additions & 1 deletion packages/availity-workflow-angular/karma.conf.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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(),

Expand Down
8 changes: 7 additions & 1 deletion packages/availity-workflow-angular/karma.conf.sauce.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
8 changes: 7 additions & 1 deletion packages/availity-workflow/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();

Expand Down
6 changes: 6 additions & 0 deletions packages/availity-workflow/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 872dad2

Please sign in to comment.