From de5542de6a597c17fb06660e79e911885e9788d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Fri, 4 May 2018 16:31:39 -0700 Subject: [PATCH] Exclude node modules from backend build (#211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setup following directions from [webpack-node-externals] [webpack-node-externals]: https://www.npmjs.com/package/webpack-node-externals This unblocks #210. Test plan: `yarn backend` still succeeds, and the binary scripts still work. The resultant binaries are much smaller, as seen below (note build time is the same). before: ``` ❯ yarn backend yarn run v1.5.1 $ node scripts/backend.js Building backend applications... Compiled successfully. File sizes after gzip: 231.37 KB bin/printCombinedGraph.js 199.5 KB bin/fetchAndPrintGithubRepo.js 46.41 KB bin/cloneAndPrintGitGraph.js 21.48 KB bin/createExampleRepo.js 17.71 KB bin/loadAndPrintGitRepository.js Build completed; results in 'bin'. Done in 4.46s. ``` after: ``` ❯ yarn backend yarn run v1.5.1 $ node scripts/backend.js Building backend applications... Compiled successfully. File sizes after gzip: 27.78 KB bin/printCombinedGraph.js 12.73 KB bin/cloneAndPrintGitGraph.js 12.41 KB bin/fetchAndPrintGithubRepo.js 6.03 KB bin/loadAndPrintGitRepository.js 5.52 KB bin/createExampleRepo.js Build completed; results in 'bin'. Done in 4.28s. ``` --- config/webpack.config.backend.js | 3 ++- package.json | 3 ++- yarn.lock | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config/webpack.config.backend.js b/config/webpack.config.backend.js index 65ca032..da68a2d 100644 --- a/config/webpack.config.backend.js +++ b/config/webpack.config.backend.js @@ -2,6 +2,7 @@ const webpack = require("webpack"); const eslintFormatter = require("react-dev-utils/eslintFormatter"); const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin"); const paths = require("./paths"); +const nodeExternals = require("webpack-node-externals"); // This is the backend configuration. It builds applications that target // Node and will not run in a browser. @@ -11,6 +12,7 @@ module.exports = { // Target Node instead of the browser. target: "node", entry: paths.backendEntryPoints, + externals: [nodeExternals()], output: { path: paths.backendBuild, // Generated JS file names (with nested folders). @@ -65,7 +67,6 @@ module.exports = { ], }, ], - exprContextCritical: false, }, plugins: [ new webpack.DefinePlugin({ diff --git a/package.json b/package.json index 41aa02b..9be3060 100644 --- a/package.json +++ b/package.json @@ -119,6 +119,7 @@ "enzyme-adapter-react-16": "^1.1.1", "enzyme-to-json": "^3.3.3", "mkdirp": "^0.5.1", - "tmp": "^0.0.33" + "tmp": "^0.0.33", + "webpack-node-externals": "^1.7.2" } } diff --git a/yarn.lock b/yarn.lock index 88e5a8e..694b4f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6941,6 +6941,10 @@ webpack-manifest-plugin@1.3.2: fs-extra "^0.30.0" lodash ">=3.5 <5" +webpack-node-externals@^1.7.2: + version "1.7.2" + resolved "https://registry.yarnpkg.com/webpack-node-externals/-/webpack-node-externals-1.7.2.tgz#6e1ee79ac67c070402ba700ef033a9b8d52ac4e3" + webpack-sources@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.1.0.tgz#a101ebae59d6507354d71d8013950a3a8b7a5a54"