From 21b7f16b1e4f25999d5dd8bef3c3096e5b298967 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 9 Aug 2017 19:22:20 -0700 Subject: [PATCH] added webpack-dev-middleware for recompiling on source changes --- package-lock.json | 53 +++++++++++++++++++++++++++++++++++++++-------- package.json | 10 +++++---- server/server.js | 11 ++++++++++ webpack.config.js | 3 ++- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 91c49587..e9730980 100644 --- a/package-lock.json +++ b/package-lock.json @@ -285,9 +285,9 @@ } }, "aws-sdk": { - "version": "2.94.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.94.0.tgz", - "integrity": "sha1-cEPePvjCTLarS/I18I2H2EFz4XQ=", + "version": "2.95.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.95.0.tgz", + "integrity": "sha1-JuIdsUlEOx8GOUnch5hPDRdwDmo=", "requires": { "buffer": "4.9.1", "crypto-browserify": "1.0.9", @@ -2047,6 +2047,16 @@ "sha.js": "2.4.8" } }, + "cross-env": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.0.5.tgz", + "integrity": "sha1-Q4PTZNlmCHPdGFs5ivO/717//vM=", + "dev": true, + "requires": { + "cross-spawn": "5.1.0", + "is-windows": "1.0.1" + } + }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -5129,6 +5139,12 @@ "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=", "dev": true }, + "is-windows": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.1.tgz", + "integrity": "sha1-MQ23D3QtJZoWo2kgK1GvhCMzENk=", + "dev": true + }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -8523,9 +8539,9 @@ } }, "redis": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/redis/-/redis-2.7.1.tgz", - "integrity": "sha1-fVb3h1uYsgQQtxU58dh47Vjr9Go=", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz", + "integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==", "requires": { "double-ended-queue": "2.1.0-0", "redis-commands": "1.3.1", @@ -9819,6 +9835,12 @@ } } }, + "time-stamp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/time-stamp/-/time-stamp-2.0.0.tgz", + "integrity": "sha1-lcakRTDhW6jW9KPsuMOj+sRto1c=", + "dev": true + }, "timed-out": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz", @@ -10131,9 +10153,9 @@ } }, "webpack": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-3.4.1.tgz", - "integrity": "sha1-TD9PP7MYFVpNsMtqNv8FxWl0GPQ=", + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-3.5.2.tgz", + "integrity": "sha1-qWAQZuI688gPO/l1j9eUypd48lE=", "dev": true, "requires": { "acorn": "5.1.1", @@ -10258,6 +10280,19 @@ } } }, + "webpack-dev-middleware": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-1.12.0.tgz", + "integrity": "sha1-007++y7dp+HTtdvgcolRMhllFwk=", + "dev": true, + "requires": { + "memory-fs": "0.4.1", + "mime": "1.3.4", + "path-is-absolute": "1.0.1", + "range-parser": "1.2.0", + "time-stamp": "2.0.0" + } + }, "webpack-sources": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.0.1.tgz", diff --git a/package.json b/package.json index 1cb6fe56..e0e8789c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "1.1.0", "author": "Mozilla (https://mozilla.org)", "dependencies": { - "aws-sdk": "^2.89.0", + "aws-sdk": "^2.95.0", "body-parser": "^1.17.2", "connect-busboy": "0.0.2", "convict": "^3.0.0", @@ -13,7 +13,7 @@ "helmet": "^3.8.0", "mozlog": "^2.1.1", "raven": "^2.1.0", - "redis": "^2.7.1" + "redis": "^2.8.0" }, "devDependencies": { "asmcrypto.js": "0.0.11", @@ -25,6 +25,7 @@ "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", "browserify": "^14.4.0", + "cross-env": "^5.0.5", "css-mqpacker": "^6.0.1", "cssnano": "^3.10.0", "eslint": "^4.3.0", @@ -49,7 +50,8 @@ "supertest": "^3.0.0", "testpilot-ga": "^0.3.0", "webcrypto-liner": "^0.1.25", - "webpack": "^3.4.1" + "webpack": "^3.5.2", + "webpack-dev-middleware": "^1.12.0" }, "engines": { "node": ">=8.2.0" @@ -113,7 +115,7 @@ "lint-locales:dev": "npm run lint-locales", "lint-locales:prod": "npm run lint-locales -- --production", "start": "node server/server", - "test": "npm-run-all test:*", + "test": "cross-env NODE_ENV=test npm-run-all test:*", "test:unit": "mocha test/unit", "test:server": "mocha test/server", "test--browser": "browserify test/frontend/frontend.bundle.js -o test/frontend/bundle.js -d && node test/frontend/driver.js" diff --git a/server/server.js b/server/server.js index ed430c47..5d2ceb1a 100644 --- a/server/server.js +++ b/server/server.js @@ -38,6 +38,17 @@ function prodLangs() { const availableLanguages = conf.l10n_dev ? allLangs() : prodLangs(); +if (conf.env === 'development') { + const webpack = require('webpack'); + const webpackDevMiddleware = require('webpack-dev-middleware'); + const config = require('../webpack.config.js'); + config.devtool = 'inline-source-map'; + const compiler = webpack(config); + app.use(webpackDevMiddleware(compiler, { + publicPath: config.output.publicPath + })); +} + app.engine( 'handlebars', exphbs({ diff --git a/webpack.config.js b/webpack.config.js index 434925a5..8641852e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,8 @@ module.exports = { }, output: { filename: '[name].js', - path: path.resolve(__dirname, 'public') + path: path.resolve(__dirname, 'public'), + publicPath: '/' }, module: { loaders: [