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.

92 lines
2.7 KiB

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