Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

101 wiersze
2.8 KiB

  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 FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  10. const portfinder = require('portfinder')
  11. function resolve(dir) {
  12. return path.join(__dirname, '..', dir)
  13. }
  14. const HOST = process.env.HOST
  15. const PORT = process.env.PORT && Number(process.env.PORT)
  16. const devWebpackConfig = merge(baseWebpackConfig, {
  17. mode: 'development',
  18. output: {
  19. path: config.build.assetsRoot,
  20. filename: '[name].js',
  21. publicPath: config.dev.assetsPublicPath
  22. },
  23. module: {
  24. rules: utils.styleLoaders({
  25. sourceMap: config.dev.cssSourceMap,
  26. usePostCSS: true
  27. })
  28. },
  29. // cheap-module-eval-source-map is faster for development
  30. devtool: config.dev.devtool,
  31. // these devServer options should be customized in /config/index.js
  32. devServer: {
  33. clientLogLevel: 'warning',
  34. historyApiFallback: true,
  35. hot: true,
  36. compress: true,
  37. host: HOST || config.dev.host,
  38. port: PORT || config.dev.port,
  39. open: config.dev.autoOpenBrowser,
  40. overlay: config.dev.errorOverlay
  41. ? { warnings: false, errors: true }
  42. : false,
  43. publicPath: config.dev.assetsPublicPath,
  44. proxy: config.dev.proxyTable,
  45. quiet: true, // necessary for FriendlyErrorsPlugin
  46. watchOptions: {
  47. poll: config.dev.poll
  48. }
  49. },
  50. plugins: [
  51. new webpack.DefinePlugin({
  52. 'process.env': require('../config/dev.env')
  53. }),
  54. new webpack.HotModuleReplacementPlugin(),
  55. // https://github.com/ampedandwired/html-webpack-plugin
  56. new HtmlWebpackPlugin({
  57. filename: 'index.html',
  58. template: 'index.html',
  59. inject: true,
  60. favicon: resolve('static/favicon.ico'),
  61. title: 'vue-admin-template'
  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(
  77. new FriendlyErrorsPlugin({
  78. compilationSuccessInfo: {
  79. messages: [
  80. `Your application is running here: http://${
  81. devWebpackConfig.devServer.host
  82. }:${port}`
  83. ]
  84. },
  85. onErrors: config.dev.notifyOnErrors
  86. ? utils.createNotifierCallback()
  87. : undefined
  88. })
  89. )
  90. resolve(devWebpackConfig)
  91. }
  92. })
  93. })