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)) { |
| 19 | sources[i].push('webpack-dev-server/client?http://localhost:' + devPort); |
| 20 | sources[i].push('webpack/hot/only-dev-server'); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 21 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 22 | } |
| 23 | return sources; |
| 24 | } |
| 25 | |
| 26 | let webpackDevConfig = Object.assign({}, webpackCommon, { |
| 27 | entry: getEntrySources(devConfig.bundles), |
| 28 | devtool: 'eval-source-map', |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 29 | output: { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 30 | path: path.join(__dirname, 'dist'), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 31 | publicPath: `http://localhost:${devPort}/onboarding/`, |
| 32 | filename: '[name].js' |
| 33 | }, |
| 34 | devServer: { |
| 35 | port: devPort, |
| 36 | historyApiFallback: true, |
| 37 | publicPath: `http://localhost:${devPort}/onboarding/`, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 38 | contentBase: path.join(__dirname, 'dist'), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | hot: true, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | inline: true, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 41 | stats: { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 42 | colors: true, |
| 43 | exclude: ['node_modules'] |
| 44 | }, |
| 45 | setup: proxyServer |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 46 | }, |
| 47 | plugins: [ |
| 48 | new webpack.DefinePlugin({ |
| 49 | DEV: true, |
| 50 | DEBUG: true |
| 51 | }), |
| 52 | new webpack.HotModuleReplacementPlugin(), |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | new webpack.LoaderOptionsPlugin({ |
| 54 | options: { |
| 55 | eslint: { |
| 56 | configFile: './.eslintrc', |
| 57 | emitError: true, |
| 58 | emitWarning: true |
| 59 | }, |
| 60 | context: '/' |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 61 | } |
| 62 | }) |
| 63 | ] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 64 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 65 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 66 | module.exports = webpackDevConfig; |