Webpack多页面应用程序服务

我有一个反应项目,但我分成两部分(pipe理员,前)。 我想通过一个webpack devserver服务这两个不同的端口。

当我运行“npm run start”时,可能会有两个部分在不同的端口工作

我用webpackbuild立,输出在dist目录里

  • admin.html
  • 的index.html
  • admin.js
  • index.js
  • common.js

如果我打开本地主机:8081 – >必须返回index.html(包括index.js和common.js)

如果我打开本地主机:8082 – >必须返回admin.html(包括admin.js,common.js)

webpackconfiguration:

entry: options.production ? { interview: ["./app/src/pages/interview/main.js"], admin: ["./app/src/pages/dashboard/main.js"] } : { interview: [ 'webpack-dev-server/client?http://' + options.ip + ':8081', "./app/src/pages/interview/main.js", 'webpack/hot/only-dev-server'], admin: ['webpack-dev-server/client?http://' + options.ip + ':8082', 'webpack/hot/only-dev-server', "./app/src/pages/dashboard/main.js"] }, output: { path: options.production ? './dist' : './build', publicPath: options.production ? '' : 'http://' + options.ip + ':8081/', filename: options.production ? '[name].app.[hash].min.js' : '[name].app.js', }, plugins: options.production ? [ //new DashboardPlugin(), // Important to keep React file size down new CommonsChunkPlugin("commons.chunk.js"), new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('production'), }, }), new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({ minimize: true, beautify: false, comments: false, compress: { warnings: false, }, mangle: { // Don't mangle $ except: ['$', '_', '*', '$super', 'exports', 'require'], // Don't care about IE8 screw_ie8: true, // Don't mangle function names keep_fnames: true } }), //new ExtractTextPlugin('app.[hash].css'), new HtmlWebpackPlugin({ template: './conf/tmpl.html', production: true, filename: "index.html", excludeChunks: ['admin'] }), new HtmlWebpackPlugin({ template: './conf/tmpl.html', production: true, filename: "admin.html", excludeChunks: ['interview'] }), new webpack.DefinePlugin({ //export all environment variables //todo check that if this is really working 'process.env': { DENEME: JSON.stringify("mesut"), APPCONFIG: JSON.stringify(confParams) } }) ] : [ new CommonsChunkPlugin("commons.chunk.js"), new HtmlWebpackPlugin({ template: './conf/tmpl.html', filename: "index.html", excludeChunks: ['admin'] }), new HtmlWebpackPlugin({ template: './conf/tmpl.html', filename: "admin.html", excludeChunks: ['interview'] }), new webpack.DefinePlugin({ //export all environment variables //todo check that if this is really working 'process.env': { DENEME: JSON.stringify("mesut"), APPCONFIG: JSON.stringify(confParams) } }) ],