backend: move build dir removal into Webpack (#776)

Summary:
Both the backend and the web builds want to empty the build directory
before starting. This commit makes them use the same codepath, reducing
the amount of work that `scripts/backend.js` does so that we can more
easily remove it (#765).

Test Plan:

```shell
$ touch ./bin/wat
$ yarn backend >/dev/null 2>/dev/null
$ file ./bin/wat
./bin/wat: cannot open `./bin/wat' (No such file or directory)
```

wchargin-branch: backend-empty-backend-build-directory
This commit is contained in:
William Chargin 2018-09-05 11:25:52 -07:00 committed by GitHub
parent f191995c61
commit 8c0bbbc732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -3,6 +3,7 @@
const webpack = require("webpack"); const webpack = require("webpack");
const eslintFormatter = require("react-dev-utils/eslintFormatter"); const eslintFormatter = require("react-dev-utils/eslintFormatter");
const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin"); const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin");
const RemoveBuildDirectoryPlugin = require("./RemoveBuildDirectoryPlugin");
const paths = require("./paths"); const paths = require("./paths");
const nodeExternals = require("webpack-node-externals"); const nodeExternals = require("webpack-node-externals");
const getClientEnvironment = require("./env"); const getClientEnvironment = require("./env");
@ -74,5 +75,8 @@ module.exports = (outputPath) => ({
}, },
], ],
}, },
plugins: [new webpack.DefinePlugin(env.individuallyStringified)], plugins: [
new RemoveBuildDirectoryPlugin(),
new webpack.DefinePlugin(env.individuallyStringified),
],
}); });

View File

@ -44,9 +44,6 @@ const outputPath = process.argv.some((s) => s === "--dry-run" || s === "-n")
// This lets us display how much they changed later. // This lets us display how much they changed later.
measureFileSizesBeforeBuild(outputPath) measureFileSizesBeforeBuild(outputPath)
.then((previousFileSizes) => { .then((previousFileSizes) => {
// Remove all content but keep the directory so that
// if you're in it, you don't end up in Trash
fs.emptyDirSync(outputPath);
// Start the webpack build // Start the webpack build
return build(previousFileSizes); return build(previousFileSizes);
}) })