webpack.dev.conf.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 path = require('path')
  7. const baseWebpackConfig = require('./webpack.base.conf')
  8. const CopyWebpackPlugin = require('copy-webpack-plugin')
  9. const HtmlWebpackPlugin = require('html-webpack-plugin')
  10. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  11. const portfinder = require('portfinder')
  12. const wepackDevServer = require('./wepack.dev.server')
  13. const HOST = '192.168.0.77'
  14. // const HOST = '0.0.0.0'
  15. const PORT = process.env.PORT && Number(process.env.PORT)
  16. const devWebpackConfig = merge(baseWebpackConfig, {
  17. module: {
  18. rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
  19. },
  20. // cheap-module-eval-source-map is faster for development
  21. devtool: config.dev.devtool,
  22. // these devServer options should be customized in /config/index.js
  23. devServer: {
  24. clientLogLevel: 'warning',
  25. historyApiFallback: {
  26. rewrites: [
  27. { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }
  28. ]
  29. },
  30. hot: true,
  31. contentBase: false, // since we use CopyWebpackPlugin.
  32. compress: true,
  33. host: HOST || config.dev.host,
  34. port: PORT || config.dev.port,
  35. open: config.dev.autoOpenBrowser,
  36. overlay: config.dev.errorOverlay
  37. ? { warnings: false, errors: true }
  38. : false,
  39. publicPath: config.dev.assetsPublicPath,
  40. proxy: config.dev.proxyTable,
  41. quiet: true, // necessary for FriendlyErrorsPlugin
  42. watchOptions: {
  43. poll: config.dev.poll
  44. },
  45. proxy: {
  46. '/api': {
  47. target: 'https://test.4dkankan.com',
  48. // target: 'https://testusa.4dkankan.com',
  49. // target: 'https://falconvisual.brokersbus.com',
  50. // target: 'http://192.168.0.50:8080',
  51. changeOrigin: true
  52. },
  53. '/www': {
  54. target: 'https://test.4dkankan.com',
  55. changeOrigin: true
  56. },
  57. '/node-upload': {
  58. target: 'http://vrhouse2.4dkankan.com',
  59. changeOrigin: true
  60. }
  61. },
  62. setup: wepackDevServer
  63. },
  64. plugins: [
  65. new webpack.DefinePlugin({
  66. 'process.env': require('../config/dev.env')
  67. }),
  68. new webpack.HotModuleReplacementPlugin(),
  69. new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
  70. new webpack.NoEmitOnErrorsPlugin(),
  71. // https://github.com/ampedandwired/html-webpack-plugin
  72. new HtmlWebpackPlugin({
  73. filename: 'index.html',
  74. template: 'index.html',
  75. inject: true
  76. }),
  77. // copy custom static assets
  78. new CopyWebpackPlugin([
  79. {
  80. from: path.resolve(__dirname, '../static'),
  81. to: config.dev.assetsSubDirectory,
  82. ignore: ['.*']
  83. }
  84. ])
  85. ]
  86. })
  87. module.exports = new Promise((resolve, reject) => {
  88. portfinder.basePort = process.env.PORT || config.dev.port
  89. portfinder.getPort((err, port) => {
  90. if (err) {
  91. reject(err)
  92. } else {
  93. // publish the new Port, necessary for e2e tests
  94. process.env.PORT = port
  95. // add port to devServer config
  96. devWebpackConfig.devServer.port = port
  97. // Add FriendlyErrorsPlugin
  98. devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
  99. compilationSuccessInfo: {
  100. messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`]
  101. },
  102. onErrors: config.dev.notifyOnErrors
  103. ? utils.createNotifierCallback()
  104. : undefined
  105. }))
  106. resolve(devWebpackConfig)
  107. }
  108. })
  109. })