herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 1 | /**
|
| 2 | * ============LICENSE_START========================================================================
|
| 3 | * ONAP : ccsdk feature sdnr wt odlux
|
| 4 | * =================================================================================================
|
| 5 | * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
|
| 6 | * =================================================================================================
|
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
| 8 | * in compliance with the License. You may obtain a copy of the License at
|
| 9 | *
|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 11 | *
|
| 12 | * Unless required by applicable law or agreed to in writing, software distributed under the License
|
| 13 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
| 14 | * or implied. See the License for the specific language governing permissions and limitations under
|
| 15 | * the License.
|
| 16 | * ============LICENSE_END==========================================================================
|
| 17 | */
|
| 18 | /**
|
| 19 | * Webpack 4 configuration file
|
| 20 | * see https://webpack.js.org/configuration/
|
| 21 | * see https://webpack.js.org/configuration/dev-server/
|
| 22 | */
|
| 23 |
|
| 24 | "use strict";
|
| 25 |
|
| 26 | const path = require("path");
|
| 27 | const webpack = require("webpack");
|
| 28 | const CopyWebpackPlugin = require("copy-webpack-plugin");
|
| 29 | const requirejsPlugin = require('requirejs-webpack-plugin');
|
| 30 | const TerserPlugin = require('terser-webpack-plugin');
|
| 31 |
|
| 32 | // const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
|
| 33 |
|
| 34 | module.exports = (env) => {
|
| 35 | const distPath = path.resolve(__dirname, env === "release" ? "." : "..", "dist");
|
| 36 | const frameworkPath = path.resolve(__dirname, env === "release" ? "." : "..", "dist");
|
| 37 | return [{
|
| 38 | name: "Client",
|
| 39 | mode: "none", //disable default behavior
|
| 40 | target: "web",
|
| 41 |
|
| 42 | context: path.resolve(__dirname, "src"),
|
| 43 |
|
| 44 | entry: {
|
| 45 | app: [
|
| 46 | "./app.tsx",
|
| 47 | "./services",
|
| 48 | "./components/material-table",
|
| 49 | "./components/material-ui",
|
| 50 | "./utilities/elasticSearch",
|
| 51 | "./models"],
|
| 52 | },
|
| 53 |
|
| 54 | devtool: env === "release" ? false : "source-map",
|
| 55 |
|
| 56 | resolve: {
|
| 57 | extensions: [".ts", ".tsx", ".js", ".jsx"]
|
| 58 | },
|
| 59 |
|
| 60 | output: {
|
| 61 | path: distPath,
|
| 62 | library: "[name]", // related to webpack.DllPlugin::name
|
| 63 | libraryTarget: "umd2",
|
| 64 | filename: "[name].js",
|
| 65 | chunkFilename: "[name].js"
|
| 66 | },
|
| 67 |
|
| 68 | module: {
|
| 69 | rules: [{
|
| 70 | test: /\.tsx?$/,
|
| 71 | exclude: /node_modules/,
|
| 72 | use: [{
|
| 73 | loader: "babel-loader"
|
| 74 | }, {
|
| 75 | loader: "ts-loader"
|
| 76 | }]
|
| 77 | }, {
|
| 78 | test: /\.jsx?$/,
|
| 79 | exclude: /node_modules/,
|
| 80 | use: [{
|
| 81 | loader: "babel-loader"
|
| 82 | }]
|
| 83 | }, {
|
| 84 | test: /\.(png|gif|jpg|svg)$/,
|
| 85 | use: [{
|
| 86 | loader: 'url-loader',
|
| 87 | options: {
|
| 88 | limit: 10000,
|
| 89 | name: './images/[hash].[ext]'
|
| 90 | }
|
| 91 | }]
|
| 92 | }]
|
| 93 | },
|
| 94 |
|
| 95 | optimization: {
|
| 96 | noEmitOnErrors: true,
|
| 97 | namedModules: env !== "release",
|
| 98 | minimize: env === "release",
|
| 99 | minimizer: env !== "release" ? [] : [new TerserPlugin({
|
| 100 | terserOptions: {
|
| 101 | mangle: {
|
| 102 | reserved: ["./app.tsx"]
|
| 103 | },
|
| 104 | warnings: false, // false, true, "verbose"
|
| 105 | compress: {
|
| 106 | drop_console: true,
|
| 107 | drop_debugger: true,
|
| 108 | }
|
| 109 | }
|
| 110 | })],
|
| 111 | },
|
| 112 |
|
| 113 | plugins: [
|
| 114 | new CopyWebpackPlugin([{
|
| 115 | from: '../../node_modules/requirejs/require.js',
|
| 116 | to: '.'
|
| 117 | }, {
|
| 118 | from: './favicon.ico',
|
| 119 | to: '.'
|
| 120 | }, {
|
| 121 | from: env === "release" ? './index.html' : 'index.dev.html',
|
| 122 | to: './index.html'
|
| 123 | }]),
|
| 124 | new requirejsPlugin({
|
| 125 | path: distPath,
|
| 126 | filename: 'config.js',
|
| 127 | baseUrl: '',
|
| 128 | pathUrl: '',
|
| 129 | processOutput: function (assets) {
|
| 130 | return 'require.config(' + JSON.stringify(assets, null, 2) + ')';
|
| 131 | }
|
| 132 | }),
|
| 133 | // new HtmlWebpackPlugin({
|
| 134 | // filename: "index.html",
|
| 135 | // template: "./index.html",
|
| 136 | // inject: "head"
|
| 137 | // }),
|
| 138 | // new HtmlWebpackIncludeAssetsPlugin({
|
| 139 | // assets: ['vendor.js'],
|
| 140 | // append: false
|
| 141 | // }),
|
| 142 | new webpack.DllReferencePlugin({
|
| 143 | context: path.resolve(__dirname, "src"),
|
| 144 | manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
|
| 145 | sourceType: "umd2"
|
| 146 | }),
|
| 147 | new webpack.DllPlugin({
|
| 148 | context: path.resolve(__dirname, "src"),
|
| 149 | name: "[name]",
|
| 150 | path: path.resolve(distPath, "[name]-manifest.json")
|
| 151 | }),
|
| 152 | ...(env === "release") ? [
|
| 153 | new webpack.DefinePlugin({
|
| 154 | "process.env": {
|
| 155 | NODE_ENV: "'production'",
|
| 156 | VERSION: JSON.stringify(require("./package.json").version)
|
| 157 | }
|
| 158 | }),
|
| 159 | ] : [
|
| 160 | new webpack.HotModuleReplacementPlugin(),
|
| 161 | new webpack.DefinePlugin({
|
| 162 | "process.env": {
|
| 163 | NODE_ENV: "'development'",
|
| 164 | VERSION: JSON.stringify(require("./package.json").version)
|
| 165 | }
|
| 166 | }),
|
| 167 | new webpack.WatchIgnorePlugin([
|
| 168 | /css\.d\.ts$/,
|
| 169 | /less\.d\.ts$/
|
| 170 | ])
|
| 171 | ]
|
| 172 | ],
|
| 173 |
|
| 174 | devServer: {
|
| 175 | public: "http://localhost:3100",
|
| 176 | contentBase: distPath,
|
| 177 |
|
| 178 | compress: true,
|
| 179 | headers: {
|
| 180 | "Access-Control-Allow-Origin": "*"
|
| 181 | },
|
| 182 | host: "0.0.0.0",
|
| 183 | port: 3100,
|
| 184 | disableHostCheck: true,
|
| 185 | historyApiFallback: true,
|
| 186 | inline: true,
|
| 187 | hot: false,
|
| 188 | quiet: false,
|
| 189 | stats: {
|
| 190 | colors: true
|
| 191 | },
|
| 192 | proxy: {
|
Aijana Schumann | d0fc432 | 2020-02-12 09:08:39 +0100 | [diff] [blame^] | 193 | "/oauth2/": {
|
| 194 | target: "http://localhost:48181",
|
herbert | 05ef023 | 2020-02-01 16:00:00 +0100 | [diff] [blame] | 195 | secure: false
|
| 196 | },
|
Aijana Schumann | d0fc432 | 2020-02-12 09:08:39 +0100 | [diff] [blame^] | 197 | "/database/": {
|
| 198 | target: "http://localhost:48181",
|
| 199 | secure: false
|
| 200 | },
|
| 201 | "/restconf/": {
|
| 202 | target: "http://localhost:48181",
|
| 203 | secure: false
|
| 204 | },
|
| 205 | "/help/": {
|
| 206 | target: "http://localhost:48181",
|
| 207 | secure: false
|
| 208 | },
|
| 209 | "/websocket": {
|
| 210 | target: "http://localhost:48181",
|
| 211 | ws: true,
|
| 212 | changeOrigin: true,
|
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 213 | secure: false
|
| 214 | }
|
| 215 | }
|
| 216 | }
|
| 217 |
|
| 218 | }];
|
| 219 | }
|
| 220 |
|
| 221 |
|