mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-05 17:24:24 +00:00
backend: export a normal Webpack config object (#779)
Summary:
Previously, our `webpack.config.backend.js` file actually exported a
function that could be used to make a Webpack configuration object.
(This is not to be confused with the late `makeWebpackConfig.js`, which
actually exported a configuration object!)
In addition to being confusing nomenclature, this was a sneaky trap for
CLI users. Invoking `webpack --config config/webpack.config.backend.js`
would actually work, but do the wrong thing: Webpack _allows_ your
configuration object to be a function, but with different semantics. In
particular, the result was that Webpack would emit the build output into
your current directory instead of into `bin/`.
This commit fixes that by making `webpack.config.backend.js` export the
Webpack configuration object for the backend JavaScript applications.
The logic to change the path is now handled by the caller, by
overwriting `config.output.path`; this is exactly [the same approach
that the Webpack CLI takes when given an `--output-path`][1], so it’s
okay with me.
[1]: 368e2640e6/bin/convert-argv.js (L406-L409)
Test Plan:
Run `yarn backend` and `yarn backend --dry-run`. Note that each runs
with appropriate output (both emitted files and console logs).
wchargin-branch: backend-webpack-config-object
This commit is contained in:
parent
2779770af5
commit
4e8c89abfe
@ -11,7 +11,7 @@ const env = getClientEnvironment();
|
|||||||
|
|
||||||
// This is the backend configuration. It builds applications that target
|
// This is the backend configuration. It builds applications that target
|
||||||
// Node and will not run in a browser.
|
// Node and will not run in a browser.
|
||||||
module.exports = (outputPath) => ({
|
module.exports = {
|
||||||
// Don't attempt to continue if there are any errors.
|
// Don't attempt to continue if there are any errors.
|
||||||
bail: true,
|
bail: true,
|
||||||
// Target Node instead of the browser.
|
// Target Node instead of the browser.
|
||||||
@ -19,7 +19,7 @@ module.exports = (outputPath) => ({
|
|||||||
entry: paths.backendEntryPoints,
|
entry: paths.backendEntryPoints,
|
||||||
externals: [nodeExternals()],
|
externals: [nodeExternals()],
|
||||||
output: {
|
output: {
|
||||||
path: outputPath,
|
path: paths.backendBuild,
|
||||||
// Generated JS file names (with nested folders).
|
// Generated JS file names (with nested folders).
|
||||||
// There will be one main bundle, and one file per asynchronous chunk.
|
// There will be one main bundle, and one file per asynchronous chunk.
|
||||||
// We don't currently advertise code splitting but Webpack supports it.
|
// We don't currently advertise code splitting but Webpack supports it.
|
||||||
@ -62,4 +62,4 @@ module.exports = (outputPath) => ({
|
|||||||
new RemoveBuildDirectoryPlugin(),
|
new RemoveBuildDirectoryPlugin(),
|
||||||
new webpack.DefinePlugin(env.individuallyStringified),
|
new webpack.DefinePlugin(env.individuallyStringified),
|
||||||
],
|
],
|
||||||
});
|
};
|
||||||
|
@ -11,12 +11,12 @@ require("../src/tools/entry");
|
|||||||
// Ensure environment variables are read.
|
// Ensure environment variables are read.
|
||||||
require("../config/env");
|
require("../config/env");
|
||||||
|
|
||||||
|
const cloneDeep = require("lodash.clonedeep");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const chalk = require("chalk");
|
const chalk = require("chalk");
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const tmp = require("tmp");
|
const tmp = require("tmp");
|
||||||
const webpack = require("webpack");
|
const webpack = require("webpack");
|
||||||
const config = require("../config/webpack.config.backend");
|
|
||||||
const paths = require("../config/paths");
|
const paths = require("../config/paths");
|
||||||
const checkRequiredFiles = require("react-dev-utils/checkRequiredFiles");
|
const checkRequiredFiles = require("react-dev-utils/checkRequiredFiles");
|
||||||
const formatWebpackMessages = require("react-dev-utils/formatWebpackMessages");
|
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_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 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(
|
build().then(
|
||||||
({stats, warnings}) => {
|
({stats, outputPath, warnings}) => {
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
console.log(chalk.yellow("Compiled with warnings.\n"));
|
console.log(chalk.yellow("Compiled with warnings.\n"));
|
||||||
console.log(warnings.join("\n\n"));
|
console.log(warnings.join("\n\n"));
|
||||||
@ -64,7 +60,16 @@ build().then(
|
|||||||
function build() {
|
function build() {
|
||||||
console.log("Building backend applications...");
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
compiler.run((err, stats) => {
|
compiler.run((err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -95,6 +100,7 @@ function build() {
|
|||||||
}
|
}
|
||||||
return resolve({
|
return resolve({
|
||||||
stats,
|
stats,
|
||||||
|
outputPath,
|
||||||
warnings: messages.warnings,
|
warnings: messages.warnings,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user