mirror of
https://github.com/status-im/sourcecred.git
synced 2025-01-24 19:39:00 +00:00
4e8c89abfe
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
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
// @no-flow
|
|
|
|
const webpack = require("webpack");
|
|
const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin");
|
|
const RemoveBuildDirectoryPlugin = require("./RemoveBuildDirectoryPlugin");
|
|
const paths = require("./paths");
|
|
const nodeExternals = require("webpack-node-externals");
|
|
const getClientEnvironment = require("./env");
|
|
|
|
const env = getClientEnvironment();
|
|
|
|
// This is the backend configuration. It builds applications that target
|
|
// Node and will not run in a browser.
|
|
module.exports = {
|
|
// Don't attempt to continue if there are any errors.
|
|
bail: true,
|
|
// Target Node instead of the browser.
|
|
target: "node",
|
|
entry: paths.backendEntryPoints,
|
|
externals: [nodeExternals()],
|
|
output: {
|
|
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.
|
|
filename: "[name].js",
|
|
chunkFilename: "[name].[chunkhash:8].chunk.js",
|
|
libraryTarget: "umd",
|
|
},
|
|
resolve: {
|
|
extensions: [".js", ".json"],
|
|
plugins: [
|
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
|
// This often causes confusion because we only process files within src/ with babel.
|
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
|
],
|
|
},
|
|
module: {
|
|
strictExportPresence: true,
|
|
rules: [
|
|
{
|
|
// "oneOf" will traverse all following loaders until one will
|
|
// match the requirements. If no loader matches, it will fail.
|
|
oneOf: [
|
|
// Process JS with Babel.
|
|
{
|
|
test: /\.(js|jsx|mjs)$/,
|
|
include: paths.appSrc,
|
|
loader: require.resolve("babel-loader"),
|
|
options: {
|
|
compact: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
plugins: [
|
|
new RemoveBuildDirectoryPlugin(),
|
|
new webpack.DefinePlugin(env.individuallyStringified),
|
|
],
|
|
};
|