Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | const path = require('path'); |
| 4 | const webpack = require('webpack'); |
| 5 | const proxyServer = require('./proxy-server'); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 6 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | let localDevConfig = {}; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 8 | try { |
| 9 | localDevConfig = require('./devConfig'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | } catch (e) {} |
| 11 | let devConfig = Object.assign({}, require('./devConfig.defaults'), localDevConfig); |
| 12 | let devPort = process.env.PORT || devConfig.port; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 13 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 14 | let webpackCommon = require('./webpack.common'); |
| 15 | |
| 16 | function getEntrySources(sources) { |
| 17 | for (let i in sources) { |
| 18 | if (sources.hasOwnProperty(i)) { |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 19 | sources[i].push('react-hot-loader/patch'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 20 | sources[i].push('webpack-dev-server/client?http://localhost:' + devPort); |
| 21 | sources[i].push('webpack/hot/only-dev-server'); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | } |
| 24 | return sources; |
| 25 | } |
| 26 | |
| 27 | let webpackDevConfig = Object.assign({}, webpackCommon, { |
| 28 | entry: getEntrySources(devConfig.bundles), |
| 29 | devtool: 'eval-source-map', |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 30 | output: { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 31 | path: path.join(__dirname, 'dist'), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 32 | publicPath: `http://localhost:${devPort}/onboarding/`, |
| 33 | filename: '[name].js' |
| 34 | }, |
| 35 | devServer: { |
| 36 | port: devPort, |
| 37 | historyApiFallback: true, |
| 38 | publicPath: `http://localhost:${devPort}/onboarding/`, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 39 | contentBase: path.join(__dirname, 'dist'), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | inline: true, |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 41 | hot: true, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 42 | stats: { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | colors: true, |
| 44 | exclude: ['node_modules'] |
| 45 | }, |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 46 | before: proxyServer |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 47 | }, |
| 48 | plugins: [ |
| 49 | new webpack.DefinePlugin({ |
| 50 | DEV: true, |
| 51 | DEBUG: true |
| 52 | }), |
| 53 | new webpack.HotModuleReplacementPlugin(), |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | new webpack.LoaderOptionsPlugin({ |
| 55 | options: { |
| 56 | eslint: { |
| 57 | configFile: './.eslintrc', |
| 58 | emitError: true, |
| 59 | emitWarning: true |
| 60 | }, |
| 61 | context: '/' |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 62 | } |
| 63 | }) |
| 64 | ] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 65 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 66 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 67 | module.exports = webpackDevConfig; |