2018-09-05 19:03:30 +00:00
|
|
|
// @flow
|
2018-08-31 22:20:15 +00:00
|
|
|
|
2018-09-05 19:10:19 +00:00
|
|
|
// Do this as the first thing so that any code reading it knows the right env.
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || "development";
|
|
|
|
process.env.BABEL_ENV = process.env.NODE_ENV;
|
|
|
|
process.env.SOURCECRED_BACKEND = "true";
|
|
|
|
|
2018-03-19 05:43:23 +00:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin");
|
2018-09-05 18:25:52 +00:00
|
|
|
const RemoveBuildDirectoryPlugin = require("./RemoveBuildDirectoryPlugin");
|
2018-03-19 05:43:23 +00:00
|
|
|
const paths = require("./paths");
|
2018-05-04 23:31:39 +00:00
|
|
|
const nodeExternals = require("webpack-node-externals");
|
2018-08-31 22:20:15 +00:00
|
|
|
const getClientEnvironment = require("./env");
|
|
|
|
|
|
|
|
const env = getClientEnvironment();
|
2018-03-19 05:43:23 +00:00
|
|
|
|
|
|
|
// This is the backend configuration. It builds applications that target
|
|
|
|
// Node and will not run in a browser.
|
2018-09-05 18:58:20 +00:00
|
|
|
module.exports = {
|
2018-03-19 05:43:23 +00:00
|
|
|
// Don't attempt to continue if there are any errors.
|
|
|
|
bail: true,
|
|
|
|
// Target Node instead of the browser.
|
|
|
|
target: "node",
|
|
|
|
entry: paths.backendEntryPoints,
|
2018-05-04 23:31:39 +00:00
|
|
|
externals: [nodeExternals()],
|
2018-03-19 05:43:23 +00:00
|
|
|
output: {
|
2018-09-05 18:58:20 +00:00
|
|
|
path: paths.backendBuild,
|
2018-03-19 05:43:23 +00:00
|
|
|
// 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",
|
2018-05-05 02:28:37 +00:00
|
|
|
libraryTarget: "umd",
|
2018-03-19 05:43:23 +00:00
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-09-05 18:25:52 +00:00
|
|
|
plugins: [
|
|
|
|
new RemoveBuildDirectoryPlugin(),
|
|
|
|
new webpack.DefinePlugin(env.individuallyStringified),
|
|
|
|
],
|
2018-09-05 18:58:20 +00:00
|
|
|
};
|