Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use webpack-dev-server multiple entries point

Tags:

I would like to use the webpack-dev-server to host multiple entry points at one PORT. My current config is below:

entry: {     //Application specific code.     main: [         `webpack-dev-server/client?http://${config.HOST}:${config.PORT}`,          'webpack/hot/only-dev-server',         './app/base.js',         './app/main.js'     ],      login: [         `webpack-dev-server/client?http://${config.HOST}:${config.PORT}`,          'webpack/hot/only-dev-server',         './app/base.js',         './app/login.js'     ], }, output: {     path: assetsPath,     publicPath: `http://${config.HOST}:${config.PORT}/public/dist/`,     chunkFilename: "[name].js",     filename: '[name].js', }, 

But seems like it doesn't work for me right now. Any help?

like image 747
Hao Avatar asked Aug 05 '15 23:08

Hao


People also ask

Can webpack have multiple entry points?

Webpack is a powerful tool to build an SPA, because: It manages modules and their dependencies and transforms static assets to build bundles. It creates the same build bundles in development and production for consistency. It controls multiple application entry points or sections, and provides common bundles among them ...

How do you define an entry point in webpack?

Single Entry (Shorthand) Syntaxmodule. exports = { entry: { main: './path/to/my/entry/file. js', }, }; We can also pass an array of file paths to the entry property which creates what is known as a "multi-main entry".

Does webpack use multiple cores?

The file compression plug-in uglyfy-webpack-plugin on the official webpack page supports building with multiple CPU cores. This plug-in is supposed to be included in webpack by default in v1. 0.0, but now it needs to be manually installed via npm.


1 Answers

This is an example of a working multiple entrypoint webpack config. Let me know if it helps. I use webpack.optimize.CommonsChunkPlugin('common.js'), to generate a common.js file with the common js parts automatically.

var path = require('path'); var webpack = require('webpack'); var WebpackErrorNotificationPlugin = require('webpack-error-notification')   var buildEntryPoint = function(entryPoint){   return [     'webpack-dev-server/client?http://localhost:3000',     'webpack/hot/only-dev-server',     entryPoint   ] }  module.exports = {   devtool: 'eval',   entry: {     search: buildEntryPoint('./src/index'),     generic: buildEntryPoint('./src/index-generic')   },   output: {     path: path.join(__dirname, 'dist'),     filename: '[name].js',     publicPath: '/static/'   },   plugins: [     new webpack.optimize.CommonsChunkPlugin('common.js'),     new webpack.HotModuleReplacementPlugin(),     new webpack.DefinePlugin({       __CLIENT__: true,       __SERVER__: false,       __DEV__: true,       __DEVTOOLS__: true  // <-- Toggle redux-devtools     })   ],   resolve: {     alias: {       'redbox-react': path.join(__dirname, '..', '..', 'src')     },     extensions: ['', '.js']   },   module: {     loaders: [{       test: /\.js$/,       loaders: ['react-hot', 'babel'],       include: path.join(__dirname, 'src')     }]   } }; 
like image 140
Jurgo Boemo Avatar answered Oct 05 '22 00:10

Jurgo Boemo