修改入口和出口配置

在 webpack.config.js 中修改入口与出品配置

  1. entry: {
  2. main: './src/main.js',
  3. other: './src/other.js'
  4. },
  5. output: {
  6. path: path.join(__dirname, './dist/'),
  7. // 多入口无法对应一个固定的出口,所以修改 filename 为[name]变量
  8. filename: '[name].js',
  9. publicPath: '/'
  10. },
  11. plugins: [
  12. // 如果用了 html 插件,需要手动配置多入口对应的html 文件,将指定其对应的输出文件
  13. new HtmlWebpackPlugin({
  14. template: './src/main.html',
  15. filename: 'main.html',
  16. chunks: ['main'] // 可以写多个值,决定引入哪几个 js, 值由 entry 的key值决定
  17. }),
  18. new HtmlWebpackPlugin({
  19. template: './other.html',
  20. filename: 'other.html',
  21. chunks: ['other']
  22. })
  23. ]

修改入口对象,支持多个 js 入口,同时修改output 输出的文件名为 '[name].js' 表示自己入口文件名作为输出文件名,但是 html-webpacl-plugin 不支持此功能,所以需要再 new 一个插件,用于生成两个 html 页面,实现多页应用。