blob: be2e75efdb1323a3e376d36cc8124ffbaf3cb365 [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');
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +03009const fs = require('fs');
Michael Landoefa037d2017-02-19 12:57:33 +020010
AviZi280f8012017-06-09 02:39:56 +030011let devPort = process.env.PORT || devConfig.port;
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030012let publicPath = 'http://localhost:' + devPort + '/onboarding/';
Michael Landoefa037d2017-02-19 12:57:33 +020013
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030014module.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 }
AviZi280f8012017-06-09 02:39:56 +030028
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030029 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.schmidb0982c12020-04-30 16:56:36 +010049 publicPath: DEV ? publicPath : './',
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030050 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/,
andre.schmidead5c382021-08-06 16:04:50 +010089 path.join(__dirname, DEV ? '../dox-sequence-diagram-ui/' : 'node_modules/dox-sequence-diagram-ui/'),
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030090 path.join(__dirname, 'node_modules/react-datepicker/'),
91 path.join(__dirname, 'node_modules/react-select/'),
Arielka51eac02019-07-07 12:56:11 +030092 path.join(__dirname, 'node_modules/onap-ui-common/'),
Vodafone804ec682019-03-18 15:46:53 +053093 path.join(__dirname, 'node_modules/react-checkbox-tree/')
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +030094 ]
95 },
96 {
97 test: /\.(svg)(\?.*)?$/,
98 loader: 'url-loader',
99 options: {
100 limit: 16384,
101 mimetype: 'image/svg+xml'
102 },
103 include: [
104 path.join(
105 __dirname,
106 'node_modules/dox-sequence-diagram-ui/'
107 ),
Arielka51eac02019-07-07 12:56:11 +0300108 path.join(__dirname, 'node_modules/onap-ui-common/')
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300109 ]
Maleke6c3c722018-10-16 16:44:41 +0300110 },
111 {
112 test: /\.worker\.js$/,
113 use: { loader: 'worker-loader' }
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300114 }
115 ]
116 },
117 plugins: DEV
118 ? [
119 new CleanWebpackPlugin(['dist'], { watch: false }),
120 new DefinePlugin({
121 DEBUG: DEV === true,
122 DEV: DEV === true
123 }),
124 new HotModuleReplacementPlugin()
125 ]
126 : [
127 new DefinePlugin({
128 DEBUG: DEV === true,
129 DEV: DEV === true
andre.schmidb0982c12020-04-30 16:56:36 +0100130 }),
131 new HtmlWebpackPlugin({
132 filename: 'index.html',
133 template: __dirname + '/src/index.html'
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300134 })
135 ]
136 };
137 if (DEV) {
Maleke6c3c722018-10-16 16:44:41 +0300138 webpackConfig.output.globalObject = 'this';
Einav Weiss Keidarf2c47232018-05-30 18:12:02 +0300139 webpackConfig.entry['punch-outs'].push('react-hot-loader/patch');
140 webpackConfig.entry['punch-outs'].push(
141 'webpack-dev-server/client?http://localhost:' + devPort
142 );
143 webpackConfig.entry['punch-outs'].push('webpack/hot/only-dev-server');
144 webpackConfig.devServer = {
145 port: devPort,
146 historyApiFallback: true,
147 publicPath: publicPath,
148 contentBase: path.join(__dirname, 'dist'),
149 inline: true,
150 hot: true,
151 stats: {
152 colors: true,
153 exclude: [path.join(__dirname, 'node_modules')]
154 },
155 before: proxyServer
156 };
157 }
158 console.log('Running build for : ' + argv.mode);
159 return webpackConfig;
160};