From 0296041ce8004759683d792b63d743f3329936d2 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 12 Aug 2019 23:12:34 +0000 Subject: [PATCH] fix: build sourcemaps in production (#2466) --- package.json | 2 +- src/core/build/createWebpackConfig.ts | 29 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 258a9f6d4..6f3faabe0 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ ], "description": "A better commenting experience from Mozilla, The Washington Post, and The New York Times.", "scripts": { - "build": "NODE_ENV=production WEBPACK_DISABLE_SOURCEMAPS=1 npm-run-all generate --parallel lint:client build:client build:server", + "build": "NODE_ENV=production npm-run-all generate --parallel lint:client build:client build:server", "build:development": "NODE_ENV=development npm-run-all generate --parallel lint:client build:client build:server", "build:client": "ts-node --transpile-only ./scripts/build.ts", "build:server": "gulp server", diff --git a/src/core/build/createWebpackConfig.ts b/src/core/build/createWebpackConfig.ts index fbd64a9de..3b4cca27e 100644 --- a/src/core/build/createWebpackConfig.ts +++ b/src/core/build/createWebpackConfig.ts @@ -1,4 +1,5 @@ import OptimizeCssnanoPlugin from "@intervolga/optimize-cssnano-plugin"; +import bunyan from "bunyan"; import CaseSensitivePathsPlugin from "case-sensitive-paths-webpack-plugin"; import CompressionPlugin from "compression-webpack-plugin"; import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin"; @@ -30,6 +31,12 @@ import paths from "./paths"; const filterPlugins = (plugins: Array): Plugin[] => plugins.filter(identity) as Plugin[]; +// Create the build logger. +const logger = bunyan.createLogger({ + name: "coral", + level: "debug", +}); + interface CreateWebpackOptions { appendPlugins?: any[]; watch?: boolean; @@ -41,6 +48,8 @@ export default function createWebpackConfig( config: Config, { appendPlugins = [], watch = false }: CreateWebpackOptions = {} ): Configuration[] { + logger.debug({ config: config.toString() }, "loaded configuration"); + const maxCores = config.get("maxCores"); const env = createClientEnv(config); const disableSourcemaps = config.get("disableSourcemaps"); @@ -144,6 +153,16 @@ export default function createWebpackConfig( ), ]; + const devtool = disableSourcemaps + ? false + : isProduction + ? // We generate sourcemaps in production. This is slow but gives good results. + // You can exclude the *.map files from the build during deployment. + "source-map" + : // You may want 'eval' instead if you prefer to see the compiled output in DevTools. + // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343. + "cheap-module-source-map"; + const baseConfig: Configuration = { stats: { // https://github.com/TypeStrong/ts-loader#transpileonly-boolean-defaultfalse @@ -192,15 +211,7 @@ export default function createWebpackConfig( }), ], }, - devtool: disableSourcemaps - ? false - : isProduction - ? // We generate sourcemaps in production. This is slow but gives good results. - // You can exclude the *.map files from the build during deployment. - "source-map" - : // You may want 'eval' instead if you prefer to see the compiled output in DevTools. - // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343. - "cheap-module-source-map", + devtool, // These are the "entry points" to our application. // This means they will be the "root" imports that are included in JS bundle. // The first two entry points enable "hot" CSS and auto-refreshes for JS.