webpack.dev.conf.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 HOST = process.env.HOST
  13. const PORT = process.env.PORT && Number(process.env.PORT)
  14. const devWebpackConfig = merge(baseWebpackConfig, {
  15. module: {
  16. rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
  17. },
  18. // cheap-module-eval-source-map is faster for development
  19. devtool: config.dev.devtool,
  20. // these devServer options should be customized in /config/index.js
  21. devServer: {
  22. clientLogLevel: 'warning',
  23. historyApiFallback: {
  24. rewrites: [
  25. { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
  26. ],
  27. },
  28. hot: true,
  29. contentBase: false, // since we use CopyWebpackPlugin.
  30. compress: true,
  31. host: HOST || config.dev.host,
  32. port: PORT || config.dev.port,
  33. open: config.dev.autoOpenBrowser,
  34. overlay: config.dev.errorOverlay
  35. ? { warnings: false, errors: true }
  36. : false,
  37. publicPath: config.dev.assetsPublicPath,
  38. proxy: config.dev.proxyTable,
  39. quiet: true, // necessary for FriendlyErrorsPlugin
  40. watchOptions: {
  41. poll: config.dev.poll,
  42. },
  43. proxy: {
  44. '/auction': {
  45. target : 'http://localhost:4000'
  46. },
  47. '/information': {
  48. target : 'http://localhost:4000'
  49. },
  50. '/users': {
  51. target : 'http://localhost:4000'
  52. },
  53. '/register': {
  54. target : 'http://localhost:4000'
  55. },
  56. '/login': {
  57. target : 'http://localhost:4000'
  58. },
  59. '/logout': {
  60. target : 'http://localhost:4000'
  61. },
  62. '/infos': {
  63. target : 'http://localhost:4000'
  64. },
  65. '/laws': {
  66. target : 'http://localhost:4000'
  67. },
  68. '/previews': {
  69. target : 'http://localhost:4000'
  70. },
  71. '/knowledges': {
  72. target : 'http://localhost:4000'
  73. },
  74. '/infodetail': {
  75. target : 'http://localhost:4000'
  76. },
  77. '/userdetails': {
  78. target : 'http://localhost:4000'
  79. },
  80. '/addinfo': {
  81. target : 'http://localhost:4000'
  82. },
  83. '/addpreview': {
  84. target : 'http://localhost:4000'
  85. },
  86. '/previewlist': {
  87. target : 'http://localhost:4000'
  88. },
  89. '/previewdetail': {
  90. target : 'http://localhost:4000'
  91. },
  92. '/previewCount': {
  93. target : 'http://localhost:4000'
  94. },
  95. '/ChangePwd': {
  96. target : 'http://localhost:4000'
  97. },
  98. '/edit': {
  99. target : 'http://localhost:4000'
  100. },
  101. '/uploads': {
  102. target : 'http://localhost:4000'
  103. },
  104. '/userinfo': {
  105. target : 'http://localhost:4000'
  106. },
  107. '/userpreview': {
  108. target : 'http://localhost:4000'
  109. },
  110. '/infodel': {
  111. target : 'http://localhost:4000'
  112. },
  113. '/infomodify': {
  114. target : 'http://localhost:4000'
  115. },
  116. '/searchfor': {
  117. target : 'http://localhost:4000'
  118. },
  119. '/pv': {
  120. target : 'http://localhost:4000'
  121. },
  122. '/knowledge': {
  123. target : 'http://localhost:4000'
  124. },
  125. '/law': {
  126. target : 'http://localhost:4000'
  127. }
  128. },
  129. },
  130. plugins: [
  131. new webpack.DefinePlugin({
  132. 'process.env': require('../config/dev.env')
  133. }),
  134. new webpack.HotModuleReplacementPlugin(),
  135. new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
  136. new webpack.NoEmitOnErrorsPlugin(),
  137. // https://github.com/ampedandwired/html-webpack-plugin
  138. new HtmlWebpackPlugin({
  139. filename: 'index.html',
  140. template: 'index.html',
  141. inject: true
  142. }),
  143. // copy custom static assets
  144. new CopyWebpackPlugin([
  145. {
  146. from: path.resolve(__dirname, '../static'),
  147. to: config.dev.assetsSubDirectory,
  148. ignore: ['.*']
  149. }
  150. ])
  151. ]
  152. })
  153. module.exports = new Promise((resolve, reject) => {
  154. portfinder.basePort = process.env.PORT || config.dev.port
  155. portfinder.getPort((err, port) => {
  156. if (err) {
  157. reject(err)
  158. } else {
  159. // publish the new Port, necessary for e2e tests
  160. process.env.PORT = port
  161. // add port to devServer config
  162. devWebpackConfig.devServer.port = port
  163. // Add FriendlyErrorsPlugin
  164. devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
  165. compilationSuccessInfo: {
  166. messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
  167. },
  168. onErrors: config.dev.notifyOnErrors
  169. ? utils.createNotifierCallback()
  170. : undefined
  171. }))
  172. resolve(devWebpackConfig)
  173. }
  174. })
  175. })