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.

96 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
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. },
  41. },
  42. },
  43. plugins: [
  44. new webpack.DefinePlugin({
  45. 'process.env.ASSET_PATH': resolve ("/assets/"),
  46. 'process.env': require('../config/dev.env')
  47. }),
  48. new webpack.HotModuleReplacementPlugin(),
  49. new webpack.NoEmitOnErrorsPlugin(),
  50. // https://github.com/ampedandwired/html-webpack-plugin
  51. new HtmlWebpackPlugin({
  52. template: 'index.html',
  53. inject: true,
  54. favicon: resolve('favicon.ico'),
  55. title: 'mdp-arc',
  56. }),
  57. // copy custom static assets
  58. new CopyWebpackPlugin( {
  59. patterns: [
  60. { from: path.resolve(__dirname, '../static'), to: config.build.assetsSubDirectory },
  61. ]
  62. })
  63. ]
  64. })
  65. module.exports = new Promise((resolve, reject) => {
  66. portfinder.basePort = process.env.PORT || config.dev.port
  67. portfinder.getPort((err, port) => {
  68. if (err) {
  69. reject(err)
  70. } else {
  71. // publish the new Port, necessary for e2e tests
  72. process.env.PORT = port
  73. // add port to devServer config
  74. devWebpackConfig.devServer.port = port
  75. // Add FriendlyErrorsPlugin
  76. devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
  77. compilationSuccessInfo: {
  78. messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
  79. },
  80. onErrors: config.dev.notifyOnErrors
  81. ? utils.createNotifierCallback()
  82. : undefined
  83. }))
  84. resolve(devWebpackConfig)
  85. }
  86. })
  87. })