From a214c88e43412111daf38e9f890f210c62608438 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Sun, 18 Jun 2017 22:55:12 -0700 Subject: [PATCH 1/2] archetype-react-app: [major] turn off NodeSourcePlugin for prod build --- .../config/webpack/partial/index.js | 4 ++- .../config/webpack/partial/node.js | 32 +++++++++++++++++++ .../config/webpack/profile.base.js | 3 +- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 packages/electrode-archetype-react-app-dev/config/webpack/partial/node.js diff --git a/packages/electrode-archetype-react-app-dev/config/webpack/partial/index.js b/packages/electrode-archetype-react-app-dev/config/webpack/partial/index.js index bb08fdfe0..0837d5240 100644 --- a/packages/electrode-archetype-react-app-dev/config/webpack/partial/index.js +++ b/packages/electrode-archetype-react-app-dev/config/webpack/partial/index.js @@ -11,6 +11,7 @@ const assert = require("assert"); const orders = [ "_base-options", "_entry", + "_node", "_output", "_resolve", "_resolve-loader", @@ -39,7 +40,8 @@ const orders = [ "_hot", "_html-reporter", "_simple-progress", - "_sourcemaps-inline" + "_sourcemaps-inline", + "_node" ]; const files = Fs.readdirSync(__dirname) diff --git a/packages/electrode-archetype-react-app-dev/config/webpack/partial/node.js b/packages/electrode-archetype-react-app-dev/config/webpack/partial/node.js new file mode 100644 index 000000000..56bc0574f --- /dev/null +++ b/packages/electrode-archetype-react-app-dev/config/webpack/partial/node.js @@ -0,0 +1,32 @@ +"use strict"; + +const archetype = require("electrode-archetype-react-app/config/archetype"); +const webpack = require("webpack"); +const FunctionModulePlugin = require("webpack/lib/FunctionModulePlugin"); +const logger = require("electrode-archetype-react-app/lib/logger"); + +module.exports = function(options) { + const config = options.currentConfig; + + if ( + process.env.NODE_ENV === "production" && + config.target === undefined && + archetype.webpack.enableNodeSourcePlugin !== true + ) { + logger.info("Disabling NodeSourcePlugin for production"); + // disable NodeSourcePlugin by setting a custom target, and then apply the + // plugins the original web target would've applied. + // will be much easier once webapck with node: false option is released + const output = config.output; + config.target = () => undefined; + config.plugins = [ + new webpack.JsonpTemplatePlugin(output), + new FunctionModulePlugin(output), + new webpack.LoaderTargetPlugin("web") + ].concat(config.plugins); + } else { + logger.info("Not disabling NodeSourcePlugin. NODE_ENV:", process.env.NODE_ENV); + } + + return {}; +}; diff --git a/packages/electrode-archetype-react-app-dev/config/webpack/profile.base.js b/packages/electrode-archetype-react-app-dev/config/webpack/profile.base.js index 93e5b8749..9fd19ca0f 100644 --- a/packages/electrode-archetype-react-app-dev/config/webpack/profile.base.js +++ b/packages/electrode-archetype-react-app-dev/config/webpack/profile.base.js @@ -14,7 +14,8 @@ const profile = { _images: { order: 2300 }, _stats: { order: 2400 }, _isomorphic: { order: 2500 }, - _pwa: { order: 2600 } + _pwa: { order: 2600 }, + _node: { order: 30000 } } }; From 63ccba4ccf84e7c4c8e5b72486ef79d3f11bbb86 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Sun, 18 Jun 2017 23:30:54 -0700 Subject: [PATCH 2/2] universal-react-node: remove isomorphic-fetch --- .../universal-react-node/src/client/components/record-form.jsx | 2 -- .../universal-react-node/src/client/components/record-store.jsx | 2 -- samples/universal-react-node/src/client/middleware.js | 2 -- 3 files changed, 6 deletions(-) diff --git a/samples/universal-react-node/src/client/components/record-form.jsx b/samples/universal-react-node/src/client/components/record-form.jsx index f7b7ae561..e80c17516 100644 --- a/samples/universal-react-node/src/client/components/record-form.jsx +++ b/samples/universal-react-node/src/client/components/record-form.jsx @@ -1,6 +1,4 @@ import React from "react"; -import "es6-promise"; -import "isomorphic-fetch"; const HTTP_BAD_REQUEST = 400; const HTTP_OK = 200; diff --git a/samples/universal-react-node/src/client/components/record-store.jsx b/samples/universal-react-node/src/client/components/record-store.jsx index deec29974..039855b50 100644 --- a/samples/universal-react-node/src/client/components/record-store.jsx +++ b/samples/universal-react-node/src/client/components/record-store.jsx @@ -1,6 +1,4 @@ import React from "react"; -import "es6-promise"; -import "isomorphic-fetch"; import RecordForm from "./record-form"; const HTTP_BAD_REQUEST = 400; diff --git a/samples/universal-react-node/src/client/middleware.js b/samples/universal-react-node/src/client/middleware.js index a21647fde..49d666fd9 100644 --- a/samples/universal-react-node/src/client/middleware.js +++ b/samples/universal-react-node/src/client/middleware.js @@ -1,5 +1,3 @@ -import "es6-promise"; -import "isomorphic-fetch"; const HTTP_BAD_REQUEST = 400; const HTTP_OK = 200; let token;