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