webpack.config.dev.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. const webpack = require('webpack')
  18. const merge = require('webpack-merge')
  19. const { assetsDir, baseConfig } = require('./config')
  20. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  21. const ProgressPlugin = require('progress-bar-webpack-plugin')
  22. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  23. const portfinder = require('portfinder')
  24. const getEnv = require('env-parse').getEnv
  25. const config = merge.smart(baseConfig, {
  26. devtool: 'eval-source-map',
  27. output: {
  28. filename: 'js/[name].js'
  29. },
  30. devServer: {
  31. hot: true,
  32. contentBase: assetsDir,
  33. publicPath: baseConfig.output.publicPath,
  34. host: getEnv('DEV_HOST', 'localhost'),
  35. port: getEnv('DEV_PORT', 8888),
  36. noInfo: false,
  37. overlay: { warnings: false, errors: true },
  38. historyApiFallback: true,
  39. disableHostCheck: true,
  40. proxy: {
  41. '/dolphinscheduler': {
  42. timeout: 1800000,
  43. target: getEnv('API_BASE', 'http://local.dev:8080/backend'),
  44. changeOrigin: true
  45. }
  46. },
  47. progress: true,
  48. quiet: true,
  49. stats: {
  50. colors: true
  51. },
  52. clientLogLevel: 'warning'
  53. },
  54. plugins: [
  55. new ProgressPlugin(),
  56. new webpack.HotModuleReplacementPlugin(),
  57. new MiniCssExtractPlugin({ filename: 'css/[name].css' })
  58. ],
  59. mode: 'development'
  60. })
  61. module.exports = new Promise((resolve, reject) => {
  62. portfinder.basePort = process.env.PORT || config.devServer.port
  63. portfinder.getPort((err, port) => {
  64. if (err) {
  65. reject(err)
  66. } else {
  67. // publish the new Port, necessary for e2e tests
  68. process.env.PORT = port
  69. // add port to devServer config
  70. config.devServer.port = port
  71. // Add FriendlyErrorsPlugin
  72. config.plugins.push(new FriendlyErrorsPlugin({
  73. compilationSuccessInfo: {
  74. messages: [`Your application is running here: http://${config.devServer.host}:${port}`],
  75. },
  76. onErrors: () => {
  77. const notifier = require('node-notifier')
  78. return (severity, errors) => {
  79. if (severity !== 'error') return
  80. const error = errors[0]
  81. const filename = error.file && error.file.split('!').pop()
  82. notifier.notify({
  83. title: packageConfig.name,
  84. message: severity + ': ' + error.name,
  85. subtitle: filename || ''
  86. })
  87. }
  88. }
  89. }))
  90. resolve(config)
  91. }
  92. })
  93. })