webpack.dev.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const WebpackMerge = require('webpack-merge');
  4. const baseConfig = require('./webpack.base.js');
  5. module.exports = WebpackMerge.merge(baseConfig, {
  6. mode: 'development',
  7. //开发环境下默认启用cache,在内存中对已经构建的部分进行缓存
  8. //避免其他模块修改,但是该模块未修改时候,重新构建,能够更快的进行增量构建
  9. //属于空间换时间的做法
  10. cache: true,
  11. // 代码入口
  12. entry: {
  13. // 注册界面
  14. main: './src/main.js',
  15. },
  16. output: {
  17. path: path.resolve(__dirname, '../dist'),
  18. publicPath: '/',
  19. filename: 'app-client-[name].js',
  20. chunkFilename: 'app-client-chunk-[name].js',
  21. },
  22. watchOptions: {
  23. ignored: ['**/node_modules', '/bat/', '/dist/', '/public/', '/static/', '/test/'],
  24. poll: 2000,
  25. },
  26. devServer: {
  27. port: 8082,
  28. compress: false,
  29. static: [
  30. {
  31. directory: path.join(__dirname, 'client-base-v3/static'),
  32. publicPath: '/static',
  33. },
  34. {
  35. directory: path.join(__dirname, 'client-base-v3/public'),
  36. publicPath: '/',
  37. },
  38. ],
  39. // historyApiFallback: true,
  40. // historyApiFallback: {
  41. // rewrites: [
  42. // { from: /.*/, to: path.posix.join('/', 'index.html') },
  43. // ],
  44. // },
  45. headers: {
  46. 'Access-Control-Allow-Origin': '*',
  47. // eslint-disable-next-line max-len
  48. //'Content-Security-Policy': 'upgrade-insecure-requests; default-src \'none\'; base-uri \'self\'; frame-ancestors \'none\'; script-src \'self\' \'nonce-11111\'; connect-src \'self\'; form-action \'self\'; frame-src \'self\'; img-src \'self\'; font-src \'self\'; style-src \'self\' \'nonce-11111\'; manifest-src \'none\'; worker-src \'self\'; media-src \'self\'; object-src \'self\';',
  49. },
  50. proxy: {
  51. '/api': {
  52. target: 'http://localhost:83/',
  53. ws: false,
  54. changeOrigin: true,
  55. secure: true,
  56. },
  57. '/static': {
  58. target: 'http://localhost:83/',
  59. ws: false,
  60. changeOrigin: true,
  61. secure: true,
  62. },
  63. '/content': {
  64. target: 'http://localhost:83/',
  65. ws: false,
  66. changeOrigin: true,
  67. secure: true,
  68. },
  69. '/dashboard': {
  70. target: 'http://localhost:83/',
  71. ws: false,
  72. changeOrigin: true,
  73. secure: true,
  74. },
  75. '/mock': {
  76. target: 'http://localhost:83/',
  77. ws: false,
  78. changeOrigin: true,
  79. secure: true,
  80. },
  81. '/authApi': {
  82. target: 'http://localhost:83/',
  83. ws: false,
  84. changeOrigin: true,
  85. secure: true,
  86. },
  87. '/Dictionary': {
  88. target: 'http://localhost:83/',
  89. ws: false,
  90. changeOrigin: true,
  91. secure: true,
  92. },
  93. '/Files': {
  94. target: 'http://localhost:83/',
  95. ws: false,
  96. changeOrigin: true,
  97. secure: true,
  98. },
  99. '/WebSocket': {
  100. target: 'http://localhost:83/',
  101. ws: true,
  102. changeOrigin: true,
  103. },
  104. '/TrainVideo': {
  105. target: 'http://localhost:83/',
  106. ws: true,
  107. changeOrigin: true,
  108. },
  109. '/gateway-api': {
  110. target: 'http://localhost:83/',
  111. ws: true,
  112. changeOrigin: true,
  113. secure: true,
  114. },
  115. },
  116. },
  117. devtool: 'source-map',
  118. plugins: (module.exports.plugins || []).concat([
  119. new HtmlWebpackPlugin({
  120. title: 'Prodog',
  121. template: './public/index.html', // 源模板文件
  122. filename: './index.html', // 输出文件【注意:这里的根路径是module.exports.output.path】
  123. chunks: ['main'],
  124. }),
  125. ]),
  126. });