Ei kuvausta

webpack.dev.conf.js 2.7KB

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