Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

webpack.dev.conf.js 2.4 KiB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict'
  2. const utils = require('./utils')
  3. const webpack = require('webpack')
  4. const config = require('../config')
  5. const merge = require('webpack-merge')
  6. const baseWebpackConfig = require('./webpack.base.conf')
  7. const HtmlWebpackPlugin = require('html-webpack-plugin')
  8. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  9. const portfinder = require('portfinder')
  10. const devWebpackConfig = merge(baseWebpackConfig, {
  11. module: {
  12. rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
  13. },
  14. // cheap-module-eval-source-map is faster for development
  15. devtool: config.dev.devtool,
  16. // these devServer options should be customized in /config/index.js
  17. devServer: {
  18. clientLogLevel: 'warning',
  19. historyApiFallback: true,
  20. hot: true,
  21. compress: true,
  22. host: process.env.HOST || config.dev.host,
  23. port: process.env.PORT || config.dev.port,
  24. open: config.dev.autoOpenBrowser,
  25. overlay: config.dev.errorOverlay ? {
  26. warnings: false,
  27. errors: true,
  28. } : false,
  29. publicPath: config.dev.assetsPublicPath,
  30. proxy: config.dev.proxyTable,
  31. quiet: true, // necessary for FriendlyErrorsPlugin
  32. watchOptions: {
  33. poll: config.dev.poll,
  34. }
  35. },
  36. plugins: [
  37. new webpack.DefinePlugin({
  38. 'process.env': require('../config/dev.env')
  39. }),
  40. new webpack.HotModuleReplacementPlugin(),
  41. new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
  42. new webpack.NoEmitOnErrorsPlugin(),
  43. // https://github.com/ampedandwired/html-webpack-plugin
  44. new HtmlWebpackPlugin({
  45. filename: 'index.html',
  46. template: 'index.html',
  47. inject: true
  48. }),
  49. ]
  50. })
  51. module.exports = new Promise((resolve, reject) => {
  52. portfinder.basePort = process.env.PORT || config.dev.port
  53. portfinder.getPort((err, port) => {
  54. if (err) {
  55. reject(err)
  56. } else {
  57. // publish the new Port, necessary for e2e tests
  58. process.env.PORT = port
  59. // add port to devServer config
  60. devWebpackConfig.devServer.port = port
  61. // Add FriendlyErrorsPlugin
  62. devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
  63. compilationSuccessInfo: {
  64. messages: [`Your application is running here: http://${config.dev.host}:${port}`],
  65. },
  66. onErrors: config.dev.notifyOnErrors
  67. ? utils.createNotifierCallback()
  68. : undefined
  69. }))
  70. resolve(devWebpackConfig)
  71. }
  72. })
  73. })