22

我想使用 webpack-dev-server 在一个 PORT 上托管多个入口点。我当前的配置如下:

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',
},

但似乎它现在对我不起作用。有什么帮助吗?

4

2 回答 2

6

这是一个工作多入口点 webpack 配置的示例。让我知道它是否有帮助。我用来webpack.optimize.CommonsChunkPlugin('common.js'), 自动生成一个带有通用 js 部分的 common.js 文件。

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')
    }]
  }
};
于 2016-04-15T10:18:26.160 回答
5

响应有点晚,但我遇到了类似的问题,并通过多个HtmlWebPackPlugin插件条目解决。

module.exports = {
  entry: {
    root: ['./src/index.js'],
    labelling: ['./src/labelling.js'],
  },
  output: {
    filename: '[name].js'
  },
...
  plugins: [
    new HtmlWebPackPlugin({
      template: "./src/index.html",
      filename: "./index.html",
      chunks: ["root"]
    }),
    new HtmlWebPackPlugin({
      template: "./src/labelling.html",
      filename: "./labelling.html",
      chunks: ["labelling"]
    })
  ],
...

参考:https ://github.com/jantimon/html-webpack-plugin/issues/218

于 2020-02-27T05:12:15.950 回答