2

I want to use multiple entry point of webpack using express js instances in react boilerplate for two different application with sharable codebase

I have two html and two js files

vendor.html for vendor.js and settings.html for settings.js.

One Server.js with two instances of express

`Server.js

const appVendor = express();
const appSetting = express();

setup(appVendor, {
 domain: 'Vendor',
 outputPath: resolve(process.cwd(), 'build_vendor'),
 publicPath: '/',
});

setup(appSetting, {
  domain: 'Setting',
  outputPath: resolve(process.cwd(), 'build_setting'),
  publicPath: '/',
});


 // Start your Vendor app.
appVendor.listen('3000', host, (err) => {
  if (err) {
    return logger.error(err.message);
  }
 console.log('Server listing to port ', 3000);
});

// Start your Setting app.
appSetting.listen('5000', host, (err) => {
 if (err) {
   return logger.error(err.message);
 }
 console.log('Server listing to port ', 5000);
 });

webpack.dev.babel.js

const plugins = [
 new webpack.HotModuleReplacementPlugin(), 
 new webpack.NoEmitOnErrorsPlugin(),
 new HtmlWebpackPlugin({
   template: 'app/indexVendor.html',
   chunk: ['vendor'],
 }),
 new HtmlWebpackPlugin({
   template: 'app/indexSetting.html',
   chunk: ['setting'],
 }),
 new CircularDependencyPlugin({
   exclude: /a\.js|node_modules/, 
   failOnError: false,
}),
];

 if (dllPlugin) {
   glob.sync(`${dllPlugin.path}/*.dll.js`).forEach((dllPath) => {
   plugins.push(new AddAssetHtmlPlugin({
    filepath: dllPath,
    includeSourcemap: false,
  }));
 });
 }
 module.exports = require('./webpack.base.babel')({
   entry: {
   vendor: [
    'eventsource-polyfill',
    'webpack-hot-middleware/client?reload=true',
    path.join(process.cwd(), 'app/appVendor.js'), 
   ],
   setting: [
     'eventsource-polyfill',
     'webpack-hot-middleware/client?reload=true',
     path.join(process.cwd(), 'app/appSetting.js'),
  ],
  },
  output: {
  // path: path.resolve(__dirname, 'build'),
   filename: '[name].js',
   chunkFilename: '[name].chunk.js',
  },
  // Add development plugins
   plugins: dependencyHandlers().concat(plugins), 

  // Emit a source map for easier debugging
  // See https://webpack.js.org/configuration/devtool/#devtool
  devtool: 'eval-source-map',

 performance: {
  hints: false,
 },
});

How can i communication server.js(IP and port) with webpack multiple entry point

Rohit Dubey
  • 313
  • 2
  • 7

0 Answers0