blob: a007714a2ed6b1387184f5d6ae135f7e2704dc3b [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001'use strict';
2
AviZi280f8012017-06-09 02:39:56 +03003const path = require('path');
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +03004const CleanWebpackPlugin = require('clean-webpack-plugin');
5const { DefinePlugin, HotModuleReplacementPlugin } = require('webpack');
andre.schmidb0982c12020-04-30 16:56:36 +01006const HtmlWebpackPlugin = require('html-webpack-plugin');
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +03007const devConfig = require('./tools/getDevConfig');
AviZi280f8012017-06-09 02:39:56 +03008const proxyServer = require('./proxy-server');
Michael Landoefa037d2017-02-19 12:57:33 +02009
andre.schmid634f5612022-09-15 16:15:13 +010010const devPort = process.env.PORT || devConfig.port;
11const publicPath = 'http://localhost:' + devPort + '/onboarding/';
Michael Landoefa037d2017-02-19 12:57:33 +020012
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030013module.exports = (env, argv) => {
andre.schmid634f5612022-09-15 16:15:13 +010014 const IS_DEV = argv.mode && argv.mode === 'development';
15 let language;
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030016 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 }
AviZi280f8012017-06-09 02:39:56 +030027
andre.schmid634f5612022-09-15 16:15:13 +010028 const webpackConfig = {
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030029 entry: {
30 'punch-outs': ['sdc-app/punch-outs.js']
31 },
32 cache: true,
andre.schmid634f5612022-09-15 16:15:13 +010033 devtool: IS_DEV ? 'eval-source-map' : undefined,
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030034 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.schmid634f5612022-09-15 16:15:13 +010048 publicPath: IS_DEV ? publicPath : './',
49 filename: IS_DEV ? '[name].js' : '[name]_' + language + '.js'
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030050 },
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.schmid634f5612022-09-15 16:15:13 +010088 path.join(__dirname, IS_DEV ? '../dox-sequence-diagram-ui/' : 'node_modules/dox-sequence-diagram-ui/'),
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030089 path.join(__dirname, 'node_modules/react-datepicker/'),
90 path.join(__dirname, 'node_modules/react-select/'),
Arielka51eac02019-07-07 12:56:11 +030091 path.join(__dirname, 'node_modules/onap-ui-common/'),
Vodafone804ec682019-03-18 15:46:53 +053092 path.join(__dirname, 'node_modules/react-checkbox-tree/')
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030093 ]
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 ),
Arielka51eac02019-07-07 12:56:11 +0300107 path.join(__dirname, 'node_modules/onap-ui-common/')
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300108 ]
Maleke6c3c722018-10-16 16:44:41 +0300109 },
110 {
111 test: /\.worker\.js$/,
112 use: { loader: 'worker-loader' }
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300113 }
114 ]
115 },
andre.schmid634f5612022-09-15 16:15:13 +0100116 plugins: IS_DEV
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300117 ? [
118 new CleanWebpackPlugin(['dist'], { watch: false }),
119 new DefinePlugin({
andre.schmid634f5612022-09-15 16:15:13 +0100120 DEBUG: true,
121 DEV: true
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300122 }),
123 new HotModuleReplacementPlugin()
124 ]
125 : [
126 new DefinePlugin({
andre.schmid634f5612022-09-15 16:15:13 +0100127 DEBUG: false,
128 DEV: false,
andre.schmidb0982c12020-04-30 16:56:36 +0100129 }),
130 new HtmlWebpackPlugin({
131 filename: 'index.html',
132 template: __dirname + '/src/index.html'
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300133 })
134 ]
135 };
andre.schmid634f5612022-09-15 16:15:13 +0100136 if (IS_DEV) {
Maleke6c3c722018-10-16 16:44:41 +0300137 webpackConfig.output.globalObject = 'this';
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300138 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.schmid634f5612022-09-15 16:15:13 +0100157 console.log('Running build for: ' + argv.mode);
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300158 return webpackConfig;
159};