Coder Social home page Coder Social logo

Comments (5)

jdillick avatar jdillick commented on September 20, 2024

This is probably possible without changing .core today using src/app/server/middleware.js.

from reactium.

jdillick avatar jdillick commented on September 20, 2024

Essentially the approach would be to change the webpack and hmr middlewares according to your needs.

src/app/server/middleware.js:

const webpack = require('webpack');
const gulpConfig = require('reactium-core/gulp.config');
const webpackConfig = require('reactium-core/webpack.config')(gulpConfig);
const wpMiddlware = require('webpack-dev-middleware');
const wpHotMiddlware = require('webpack-hot-middleware');
let port = gulpConfig.port.proxy;
let pvar = op.get(process.env, 'PORT_VAR', false);
if (pvar) {
  port = op.get(process.env, pvar, port);
} else {
  port = op.get(process.env, 'APP_PORT', port);
  port = op.get(process.env, 'PORT', port);
}
port = Number(port);
const publicPath = `http://localhost:${port}/`;
let compiler;

// Update the webpack configuration to be used for node/express wepback middleware in local dev.
if (process.env.NODE_ENV === 'development') {
    webpackConfig.entry.main.unshift( `webpack-hot-middleware/client?path=/__webpack_hmr&quiet=true`);
    webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
    webpackConfig.output.publicPath = publicPath;
    compiler = webpack(webpackConfig);
}

module.exports = expressMiddlewares => expressMiddlewares.map(mw => {
  if (process.env.NODE_ENV !== 'development') return mw;
  
  switch(mw.name) {
    case 'webpack':
      return {
          name: 'webpack',
          use: wpMiddlware(compiler, {
              serverSideRender: true,
              path: '/',
              publicPath,
          }),
      };

    case 'hmr':
      return {
          name: 'hmr',
          use: wpHotMiddlware(compiler, {
              reload: true,
          }),
      };
    
    default: 
      return mw;
  }
});

from reactium.

jdillick avatar jdillick commented on September 20, 2024

Didn't test the above, but that'd be the general approach.

from reactium.

jamsterdam29 avatar jamsterdam29 commented on September 20, 2024

Thats for development mode, correct? In production we aren't using express, in fact the server directory is in the ignore loader list to prevent bundling express.

from reactium.

jdillick avatar jdillick commented on September 20, 2024

The part of core you are referencing is only used in local development, to allow webpack to serve live development updates to the browser. The webpack override is used for both. In other words, when you are doing a static build (or node/express production for that matter), that code is not in play.

Your updates to webpack override for the static build should work fine.

from reactium.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.