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'); |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 4 | const CleanWebpackPlugin = require('clean-webpack-plugin'); |
| 5 | const { DefinePlugin, HotModuleReplacementPlugin } = require('webpack'); |
andre.schmid | b0982c1 | 2020-04-30 16:56:36 +0100 | [diff] [blame] | 6 | const HtmlWebpackPlugin = require('html-webpack-plugin'); |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 7 | const devConfig = require('./tools/getDevConfig'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 8 | const proxyServer = require('./proxy-server'); |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 9 | const fs = require('fs'); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 11 | let devPort = process.env.PORT || devConfig.port; |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 12 | let publicPath = 'http://localhost:' + devPort + '/onboarding/'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 13 | |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 14 | module.exports = (env, argv) => { |
| 15 | let DEV = argv.mode && argv.mode === 'development'; |
| 16 | let language = null; |
| 17 | if ( |
| 18 | env === undefined || |
| 19 | env.language === undefined || |
| 20 | env.language === '' |
| 21 | ) { |
| 22 | console.log('Setting language to default "en".'); |
| 23 | language = 'en'; |
| 24 | } else { |
| 25 | language = env.language; |
| 26 | console.log('Setting language to "' + env.language + '".'); |
| 27 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 29 | var webpackConfig = { |
| 30 | entry: { |
| 31 | 'punch-outs': ['sdc-app/punch-outs.js'] |
| 32 | }, |
| 33 | cache: true, |
| 34 | devtool: DEV ? 'eval-source-map' : undefined, |
| 35 | performance: { hints: false }, |
| 36 | resolve: { |
| 37 | modules: [path.resolve('.'), path.join(__dirname, 'node_modules')], |
| 38 | alias: { |
| 39 | i18nJson: 'nfvo-utils/i18n/' + language + '.json', |
| 40 | 'nfvo-utils': 'src/nfvo-utils', |
| 41 | 'nfvo-components': 'src/nfvo-components', |
| 42 | 'sdc-app': 'src/sdc-app', |
| 43 | // TODO - this is needed for heatValidation standalone. Can be deprecated down the line |
| 44 | 'react-select/dist/': 'node_modules' + '/react-select/dist/' |
| 45 | } |
| 46 | }, |
| 47 | output: { |
| 48 | path: path.join(__dirname, 'dist'), |
andre.schmid | b0982c1 | 2020-04-30 16:56:36 +0100 | [diff] [blame] | 49 | publicPath: DEV ? publicPath : './', |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 50 | filename: DEV ? '[name].js' : '[name]_' + language + '.js' |
| 51 | }, |
| 52 | module: { |
| 53 | rules: [ |
| 54 | { |
| 55 | enforce: 'pre', |
| 56 | test: /\.(js|jsx)$/, |
| 57 | include: path.resolve(__dirname, 'src'), |
| 58 | use: [{ loader: 'eslint-loader' }] |
| 59 | }, |
| 60 | { |
| 61 | test: /\.(js|jsx)$/, |
| 62 | include: path.resolve(__dirname, 'src'), |
| 63 | use: [{ loader: 'babel-loader' }] |
| 64 | }, |
| 65 | { |
| 66 | test: /\.(js|jsx)$/, |
| 67 | loader: 'source-map-loader', |
| 68 | include: path.resolve(__dirname, 'src'), |
| 69 | enforce: 'pre' |
| 70 | }, |
| 71 | { |
| 72 | test: /\.(css|scss)$/, |
| 73 | use: [ |
| 74 | { |
| 75 | loader: 'style-loader' |
| 76 | }, |
| 77 | { |
| 78 | loader: 'css-loader' |
| 79 | }, |
| 80 | { |
| 81 | loader: 'sass-loader', |
| 82 | options: { |
| 83 | output: { path: path.join(__dirname, 'dist') } |
| 84 | } |
| 85 | } |
| 86 | ], |
| 87 | include: [ |
| 88 | /resources/, |
| 89 | path.join( |
| 90 | __dirname, |
| 91 | 'node_modules/dox-sequence-diagram-ui/' |
| 92 | ), |
| 93 | path.join(__dirname, 'node_modules/react-datepicker/'), |
| 94 | path.join(__dirname, 'node_modules/react-select/'), |
Arielk | a51eac0 | 2019-07-07 12:56:11 +0300 | [diff] [blame] | 95 | path.join(__dirname, 'node_modules/onap-ui-common/'), |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 96 | path.join(__dirname, 'node_modules/react-checkbox-tree/') |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 97 | ] |
| 98 | }, |
| 99 | { |
| 100 | test: /\.(svg)(\?.*)?$/, |
| 101 | loader: 'url-loader', |
| 102 | options: { |
| 103 | limit: 16384, |
| 104 | mimetype: 'image/svg+xml' |
| 105 | }, |
| 106 | include: [ |
| 107 | path.join( |
| 108 | __dirname, |
| 109 | 'node_modules/dox-sequence-diagram-ui/' |
| 110 | ), |
Arielk | a51eac0 | 2019-07-07 12:56:11 +0300 | [diff] [blame] | 111 | path.join(__dirname, 'node_modules/onap-ui-common/') |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 112 | ] |
Malek | e6c3c72 | 2018-10-16 16:44:41 +0300 | [diff] [blame] | 113 | }, |
| 114 | { |
| 115 | test: /\.worker\.js$/, |
| 116 | use: { loader: 'worker-loader' } |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 117 | } |
| 118 | ] |
| 119 | }, |
| 120 | plugins: DEV |
| 121 | ? [ |
| 122 | new CleanWebpackPlugin(['dist'], { watch: false }), |
| 123 | new DefinePlugin({ |
| 124 | DEBUG: DEV === true, |
| 125 | DEV: DEV === true |
| 126 | }), |
| 127 | new HotModuleReplacementPlugin() |
| 128 | ] |
| 129 | : [ |
| 130 | new DefinePlugin({ |
| 131 | DEBUG: DEV === true, |
| 132 | DEV: DEV === true |
andre.schmid | b0982c1 | 2020-04-30 16:56:36 +0100 | [diff] [blame] | 133 | }), |
| 134 | new HtmlWebpackPlugin({ |
| 135 | filename: 'index.html', |
| 136 | template: __dirname + '/src/index.html' |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 137 | }) |
| 138 | ] |
| 139 | }; |
| 140 | if (DEV) { |
Malek | e6c3c72 | 2018-10-16 16:44:41 +0300 | [diff] [blame] | 141 | webpackConfig.output.globalObject = 'this'; |
Einav Weiss Keidar | f2c4723 | 2018-05-30 18:12:02 +0300 | [diff] [blame] | 142 | webpackConfig.entry['punch-outs'].push('react-hot-loader/patch'); |
| 143 | webpackConfig.entry['punch-outs'].push( |
| 144 | 'webpack-dev-server/client?http://localhost:' + devPort |
| 145 | ); |
| 146 | webpackConfig.entry['punch-outs'].push('webpack/hot/only-dev-server'); |
| 147 | webpackConfig.devServer = { |
| 148 | port: devPort, |
| 149 | historyApiFallback: true, |
| 150 | publicPath: publicPath, |
| 151 | contentBase: path.join(__dirname, 'dist'), |
| 152 | inline: true, |
| 153 | hot: true, |
| 154 | stats: { |
| 155 | colors: true, |
| 156 | exclude: [path.join(__dirname, 'node_modules')] |
| 157 | }, |
| 158 | before: proxyServer |
| 159 | }; |
| 160 | } |
| 161 | console.log('Running build for : ' + argv.mode); |
| 162 | return webpackConfig; |
| 163 | }; |