diff --git a/config/webpack.config.backend.js b/config/webpack.config.backend.js index 3a8ebd0..4c65e86 100644 --- a/config/webpack.config.backend.js +++ b/config/webpack.config.backend.js @@ -11,7 +11,7 @@ const env = getClientEnvironment(); // This is the backend configuration. It builds applications that target // Node and will not run in a browser. -module.exports = (outputPath) => ({ +module.exports = { // Don't attempt to continue if there are any errors. bail: true, // Target Node instead of the browser. @@ -19,7 +19,7 @@ module.exports = (outputPath) => ({ entry: paths.backendEntryPoints, externals: [nodeExternals()], output: { - path: outputPath, + path: paths.backendBuild, // Generated JS file names (with nested folders). // There will be one main bundle, and one file per asynchronous chunk. // We don't currently advertise code splitting but Webpack supports it. @@ -62,4 +62,4 @@ module.exports = (outputPath) => ({ new RemoveBuildDirectoryPlugin(), new webpack.DefinePlugin(env.individuallyStringified), ], -}); +}; diff --git a/scripts/backend.js b/scripts/backend.js index f1f1402..c9b1674 100644 --- a/scripts/backend.js +++ b/scripts/backend.js @@ -11,12 +11,12 @@ require("../src/tools/entry"); // Ensure environment variables are read. require("../config/env"); +const cloneDeep = require("lodash.clonedeep"); const path = require("path"); const chalk = require("chalk"); const fs = require("fs-extra"); const tmp = require("tmp"); const webpack = require("webpack"); -const config = require("../config/webpack.config.backend"); const paths = require("../config/paths"); const checkRequiredFiles = require("react-dev-utils/checkRequiredFiles"); const formatWebpackMessages = require("react-dev-utils/formatWebpackMessages"); @@ -27,12 +27,8 @@ const printBuildError = require("react-dev-utils/printBuildError"); const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; -const outputPath = process.argv.some((s) => s === "--dry-run" || s === "-n") - ? tmp.dirSync({unsafeCleanup: true, prefix: "sourcecred-"}).name - : paths.backendBuild; - build().then( - ({stats, warnings}) => { + ({stats, outputPath, warnings}) => { if (warnings.length) { console.log(chalk.yellow("Compiled with warnings.\n")); console.log(warnings.join("\n\n")); @@ -64,7 +60,16 @@ build().then( function build() { console.log("Building backend applications..."); - let compiler = webpack(config(outputPath)); + const config = cloneDeep(require("../config/webpack.config.backend")); + if (process.argv.some((s) => s === "--dry-run" || s === "-n")) { + config.output.path = tmp.dirSync({ + unsafeCleanup: true, + prefix: "sourcecred-", + }).name; + } + const outputPath = config.output.path; + + let compiler = webpack(config); return new Promise((resolve, reject) => { compiler.run((err, stats) => { if (err) { @@ -95,6 +100,7 @@ function build() { } return resolve({ stats, + outputPath, warnings: messages.warnings, }); });