You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.8 KiB

5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
2 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
  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 CopyWebpackPlugin = require('copy-webpack-plugin')
  10. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  11. const portfinder = require('portfinder')
  12. function resolve (dir) {
  13. return path.join(__dirname, '..', dir)
  14. }
  15. const HOST = process.env.HOST
  16. const PORT = process.env.PORT && Number(process.env.PORT)
  17. const devWebpackConfig = merge(baseWebpackConfig, {
  18. mode:'development',
  19. module: {
  20. //rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
  21. },
  22. // cheap-module-eval-source-map is faster for development
  23. devtool: config.dev.devtool,
  24. // these devServer options should be customized in /config/index.js
  25. devServer: {
  26. //解决内网穿透
  27. historyApiFallback: true,
  28. allowedHosts: "all",
  29. historyApiFallback: true,
  30. hot: true,
  31. compress: true,
  32. host: HOST || config.dev.host,
  33. port: PORT || config.dev.port,
  34. open: config.dev.autoOpenBrowser,
  35. proxy: config.dev.proxyTable,
  36. client: {
  37. overlay: {
  38. errors: config.dev.errorOverlay,
  39. warnings: false,
  40. runtimeErrors:false,
  41. },
  42. },
  43. },
  44. plugins: [
  45. new webpack.DefinePlugin({
  46. 'process.env.ASSET_PATH': resolve ("/assets/"),
  47. 'process.env': require('../config/dev.env')
  48. }),
  49. new webpack.HotModuleReplacementPlugin(),
  50. new webpack.NoEmitOnErrorsPlugin(),
  51. // https://github.com/ampedandwired/html-webpack-plugin
  52. new HtmlWebpackPlugin({
  53. template: 'index.html',
  54. inject: true,
  55. favicon: resolve('favicon.ico'),
  56. title: 'mdp-arc',
  57. }),
  58. // copy custom static assets
  59. new CopyWebpackPlugin( {
  60. patterns: [
  61. { from: path.resolve(__dirname, '../static'), to: config.build.assetsSubDirectory },
  62. ]
  63. })
  64. ]
  65. })
  66. module.exports = new Promise((resolve, reject) => {
  67. portfinder.basePort = process.env.PORT || config.dev.port
  68. portfinder.getPort((err, port) => {
  69. if (err) {
  70. reject(err)
  71. } else {
  72. // publish the new Port, necessary for e2e tests
  73. process.env.PORT = port
  74. // add port to devServer config
  75. devWebpackConfig.devServer.port = port
  76. // Add FriendlyErrorsPlugin
  77. devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
  78. compilationSuccessInfo: {
  79. messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
  80. },
  81. onErrors: config.dev.notifyOnErrors
  82. ? utils.createNotifierCallback()
  83. : undefined
  84. }))
  85. resolve(devWebpackConfig)
  86. }
  87. })
  88. })