new-webpack: functionize (#564)

Summary:
This will enable us to differentiate the production and development
behavior where necessary (primarily, only running minification in prod).

Best reviewed with `git show -w`.

Test Plan:
The diff with `git show -w` and the fact that `yarn flow` passes should
be sufficient. If you really want to be thorough, run Webpack with this
config file and `NODE_ENV` set to `production`.

wchargin-branch: webpack-functionize
This commit is contained in:
William Chargin 2018-07-30 16:22:55 -07:00 committed by GitHub
parent e2a94c2aa8
commit 7bf0ed3c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 242 additions and 227 deletions

View File

@ -30,7 +30,8 @@ if (env.stringified["process.env"].NODE_ENV !== '"production"') {
// This is the production configuration.
// It compiles slowly and is focused on producing a fast and minimal bundle.
// The development configuration is different and lives in a separate file.
module.exports = {
function makeConfig(_unused_mode /*: "production" | "development" */) {
return {
// Don't attempt to continue if there are any errors.
bail: true,
// We generate sourcemaps in production. This is slow but gives good results.
@ -39,7 +40,10 @@ module.exports = {
// In production, we only want to load the polyfills and the app code.
entry: {
main: [require.resolve("./polyfills"), paths.appIndexJs],
ssr: [require.resolve("./polyfills"), paths.appServerSideRenderingIndexJs],
ssr: [
require.resolve("./polyfills"),
paths.appServerSideRenderingIndexJs,
],
},
output: {
// The build folder.
@ -260,4 +264,15 @@ module.exports = {
tls: "empty",
child_process: "empty",
},
};
};
}
function getMode() {
const mode = process.env.NODE_ENV;
if (mode !== "production" && mode !== "development") {
throw new Error("unknown mode: " + String(mode));
}
return mode;
}
module.exports = makeConfig(getMode());