Skip to content

Commit

Permalink
Make custom webpack config more flexible
Browse files Browse the repository at this point in the history
By adopting a scheme borrowed from next.js, where a function is defined
that can alter the default config.

https://github.com/zeit/next.js#customizing-webpack-config
  • Loading branch information
trotzig committed Sep 28, 2017
1 parent 163ea53 commit 280f30f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
5 changes: 5 additions & 0 deletions src/DEFAULTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ export const hooks = {
console.log(result);
}
}
export function customizeWebpackConfig(config) {
// provide a default no-op for this config option so that we can assume it's
// always there.
return config;
}
42 changes: 19 additions & 23 deletions src/createWebpackBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@ import webpack from 'webpack';

const OUTFILE = 'enduire.js';

export default function createWebpackBundle(entry, { webpackLoaders }) {
export default function createWebpackBundle(entry, { customizeWebpackConfig }) {
const config = customizeWebpackConfig({
entry,
resolve: {
extensions: ['*', '.js', '.jsx', '.json'],
},
output: {
filename: OUTFILE,
path: os.tmpdir(),
},
});

return new Promise((resolve, reject) => {
webpack(
{
entry,
resolve: {
extensions: ['*', '.js', '.jsx', '.json'],
},
output: {
filename: OUTFILE,
path: os.tmpdir(),
},
module: {
rules: webpackLoaders,
},
},
(err, stats) => {
if (err) {
reject(err);
return;
}
resolve(path.join(os.tmpdir(), OUTFILE));
},
);
webpack(config, (err, stats) => {
if (err) {
reject(err);
return;
}
resolve(path.join(os.tmpdir(), OUTFILE));
});
});
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'babel-polyfill';

import RemoteBrowserTarget from './RemoteBrowserTarget';
import fetchReport from './fetchReport';
import uploadReport from './uploadReport';
Expand Down
4 changes: 2 additions & 2 deletions src/reactDOMRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async function reactDOMRunner({
apiKey,
apiSecret,
setupScript,
webpackLoaders,
customizeWebpackConfig,
stylesheets,
include,
targets,
Expand All @@ -18,7 +18,7 @@ export default async function reactDOMRunner({
const entryFile = await createDynamicEntryPoint({ setupScript, include });

console.log('Producing bundle...');
const bundleFile = await createWebpackBundle(entryFile, { webpackLoaders });
const bundleFile = await createWebpackBundle(entryFile, { customizeWebpackConfig });

const cssBlocks = await Promise.all(stylesheets.map(loadCSSFile));

Expand Down
7 changes: 0 additions & 7 deletions src/runForSha.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import constructReport from './constructReport';
import createDynamicEntryPoint from './createDynamicEntryPoint';
import createWebpackBundle from './createWebpackBundle';
import fetchReport from './fetchReport';
import loadCSSFile from './loadCSSFile';
import loadUserConfig from './loadUserConfig';
import processSnapsInBundle from './processSnapsInBundle';
import uploadReport from './uploadReport';

export default async function runForSha(sha, {
Expand Down

0 comments on commit 280f30f

Please sign in to comment.