webpack.dev.conf.en.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. 'use strict'
  2. const utils = require('./utils')
  3. const webpack = require('webpack')
  4. const config = require('../config')
  5. const merge = require('webpack-merge')
  6. const path = require('path')
  7. const baseWebpackConfig = require('./webpack.base.conf')
  8. const CopyWebpackPlugin = require('copy-webpack-plugin')
  9. const HtmlWebpackPlugin = require('html-webpack-plugin')
  10. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  11. const portfinder = require('portfinder')
  12. const wepackDevServer = require('./wepack.dev.server')
  13. // const HOST = '192.168.0.172'
  14. const HOST = '0.0.0.0'
  15. const PORT = process.env.PORT && Number(process.env.PORT)
  16. const devWebpackConfig = merge(baseWebpackConfig, {
  17. module: {
  18. rules: utils.styleLoaders({
  19. sourceMap: config.dev.cssSourceMap,
  20. usePostCSS: true
  21. })
  22. },
  23. // cheap-module-eval-source-map is faster for development
  24. devtool: config.dev.devtool,
  25. // these devServer options should be customized in /config/index.js
  26. devServer: {
  27. clientLogLevel: 'warning',
  28. historyApiFallback: {
  29. rewrites: [{
  30. from: /.*/,
  31. to: path.posix.join(config.dev.assetsPublicPath, 'index.html')
  32. }]
  33. },
  34. hot: true,
  35. contentBase: false, // since we use CopyWebpackPlugin.
  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. ? {
  42. warnings: false,
  43. errors: true
  44. }
  45. : false,
  46. publicPath: config.dev.assetsPublicPath,
  47. proxy: config.dev.proxyTable,
  48. quiet: true, // necessary for FriendlyErrorsPlugin
  49. watchOptions: {
  50. poll: config.dev.poll
  51. },
  52. proxy: {
  53. '/api': {
  54. target: 'https://test.4dkankan.com',
  55. changeOrigin: true
  56. }
  57. },
  58. setup: wepackDevServer
  59. },
  60. plugins: [
  61. new webpack.DefinePlugin({
  62. 'process.env': require('../config/dev.env.en')
  63. }),
  64. new webpack.HotModuleReplacementPlugin(),
  65. new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
  66. new webpack.NoEmitOnErrorsPlugin(),
  67. // https://github.com/ampedandwired/html-webpack-plugin
  68. new HtmlWebpackPlugin({
  69. filename: 'index.html',
  70. template: 'index.html',
  71. inject: true
  72. }),
  73. // copy custom static assets
  74. new CopyWebpackPlugin([{
  75. from: path.resolve(__dirname, '../static'),
  76. to: config.dev.assetsSubDirectory,
  77. ignore: ['.*']
  78. }])
  79. ]
  80. })
  81. module.exports = new Promise((resolve, reject) => {
  82. portfinder.basePort = process.env.PORT || config.dev.port
  83. portfinder.getPort((err, port) => {
  84. if (err) {
  85. reject(err)
  86. } else {
  87. // publish the new Port, necessary for e2e tests
  88. process.env.PORT = port
  89. // add port to devServer config
  90. devWebpackConfig.devServer.port = port
  91. // Add FriendlyErrorsPlugin
  92. devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
  93. compilationSuccessInfo: {
  94. messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`]
  95. },
  96. onErrors: config.dev.notifyOnErrors
  97. ? utils.createNotifierCallback()
  98. : undefined
  99. }))
  100. resolve(devWebpackConfig)
  101. }
  102. })
  103. })