herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Webpack 4 configuration file |
| 3 | * see https://webpack.js.org/configuration/ |
| 4 | * see https://webpack.js.org/configuration/dev-server/ |
| 5 | */ |
| 6 | |
| 7 | "use strict"; |
| 8 | |
| 9 | const path = require("path"); |
| 10 | const webpack = require("webpack"); |
| 11 | const CopyWebpackPlugin = require("copy-webpack-plugin"); |
| 12 | const TerserPlugin = require('terser-webpack-plugin'); |
| 13 | |
Michael DÜrre | 21e4a94 | 2021-04-08 07:27:18 +0200 | [diff] [blame] | 14 | const policies = require('./policies.json'); |
| 15 | |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 16 | // const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname()); |
| 17 | |
| 18 | module.exports = (env) => { |
| 19 | const distPath = path.resolve(__dirname, env === "release" ? "." : "../..", "dist"); |
| 20 | const frameworkPath = path.resolve(__dirname, env === "release" ? "../../framework" : "../..", "dist"); |
| 21 | return [{ |
| 22 | name: "App", |
| 23 | |
| 24 | mode: "none", //disable default behavior |
| 25 | |
| 26 | target: "web", |
| 27 | |
| 28 | context: path.resolve(__dirname, "src"), |
| 29 | |
| 30 | entry: { |
| 31 | connectApp: ["./pluginConnect.tsx"] |
| 32 | }, |
| 33 | |
| 34 | devtool: env === "release" ? false : "source-map", |
| 35 | |
| 36 | resolve: { |
| 37 | extensions: [".ts", ".tsx", ".js", ".jsx"] |
| 38 | }, |
| 39 | |
| 40 | output: { |
| 41 | path: distPath, |
| 42 | filename: "[name].js", |
| 43 | library: "[name]", |
| 44 | libraryTarget: "umd2", |
| 45 | chunkFilename: "[name].js" |
| 46 | }, |
| 47 | module: { |
| 48 | rules: [{ |
| 49 | test: /\.tsx?$/, |
| 50 | exclude: /node_modules/, |
| 51 | use: [{ |
| 52 | loader: "babel-loader" |
| 53 | }, { |
| 54 | loader: "ts-loader" |
| 55 | }] |
| 56 | }, { |
| 57 | test: /\.jsx?$/, |
| 58 | exclude: /node_modules/, |
| 59 | use: [{ |
| 60 | loader: "babel-loader" |
| 61 | }] |
| 62 | }] |
| 63 | }, |
| 64 | |
| 65 | optimization: { |
| 66 | noEmitOnErrors: true, |
| 67 | namedModules: env !== "release", |
| 68 | minimize: env === "release", |
| 69 | minimizer: env !== "release" ? [] : [new TerserPlugin({ |
| 70 | terserOptions: { |
| 71 | warnings: false, // false, true, "verbose" |
| 72 | compress: { |
| 73 | drop_console: true, |
| 74 | drop_debugger: true, |
| 75 | } |
| 76 | } |
| 77 | })], |
| 78 | }, |
| 79 | plugins: [ |
| 80 | new webpack.DllReferencePlugin({ |
| 81 | context: path.resolve(__dirname, "../../framework/src"), |
| 82 | manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")), |
| 83 | sourceType: "umd2" |
| 84 | }), |
| 85 | new webpack.DllReferencePlugin({ |
| 86 | context: path.resolve(__dirname, "../../framework/src"), |
| 87 | manifest: require(path.resolve(frameworkPath, "app-manifest.json")), |
| 88 | sourceType: "umd2" |
| 89 | }), |
| 90 | ...(env === "release") ? [ |
| 91 | new webpack.DefinePlugin({ |
| 92 | "process.env": { |
| 93 | NODE_ENV: "'production'", |
| 94 | VERSION: JSON.stringify(require("./package.json").version) |
| 95 | } |
| 96 | }), |
| 97 | ] : [ |
| 98 | new webpack.DefinePlugin({ |
| 99 | "process.env": { |
| 100 | NODE_ENV: "'development'", |
| 101 | VERSION: JSON.stringify(require("./package.json").version) |
| 102 | } |
| 103 | }), |
| 104 | new CopyWebpackPlugin([{ |
| 105 | from: 'index.html', |
| 106 | to: distPath |
| 107 | }]), |
| 108 | ] |
| 109 | ], |
| 110 | |
| 111 | devServer: { |
| 112 | public: "http://localhost:3100", |
| 113 | contentBase: frameworkPath, |
| 114 | |
| 115 | compress: true, |
| 116 | headers: { |
| 117 | "Access-Control-Allow-Origin": "*" |
| 118 | }, |
| 119 | host: "0.0.0.0", |
| 120 | port: 3100, |
| 121 | disableHostCheck: true, |
| 122 | historyApiFallback: true, |
| 123 | inline: true, |
| 124 | hot: false, |
| 125 | quiet: false, |
| 126 | stats: { |
| 127 | colors: true |
| 128 | }, |
Michael DÜrre | 21e4a94 | 2021-04-08 07:27:18 +0200 | [diff] [blame] | 129 | before: function(app, server, compiler) { |
| 130 | app.get('/oauth/policies',(_, res) => res.json(policies)); |
| 131 | }, |
| 132 | proxy: { |
| 133 | "/about": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 134 | target: "http://sdnr:8181", |
Michael DÜrre | 21e4a94 | 2021-04-08 07:27:18 +0200 | [diff] [blame] | 135 | secure: false |
| 136 | }, |
| 137 | "/yang-schema/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 138 | target: "http://sdnr:8181", |
Michael DÜrre | 21e4a94 | 2021-04-08 07:27:18 +0200 | [diff] [blame] | 139 | secure: false |
| 140 | }, |
| 141 | "/oauth/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 142 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 143 | secure: false |
| 144 | }, |
| 145 | "/database/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 146 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 147 | secure: false |
| 148 | }, |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 149 | "/restconf/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 150 | target: "http://sdnr:8181", |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 151 | secure: false |
| 152 | }, |
| 153 | "/rests/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 154 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 155 | secure: false |
| 156 | }, |
| 157 | "/help/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 158 | target: "http://sdnr:8181", |
Michael DÜrre | 21e4a94 | 2021-04-08 07:27:18 +0200 | [diff] [blame] | 159 | secure: false |
| 160 | }, |
| 161 | "/about/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 162 | target: "http://sdnr:8181", |
Michael DÜrre | 21e4a94 | 2021-04-08 07:27:18 +0200 | [diff] [blame] | 163 | secure: false |
| 164 | }, |
| 165 | "/tree/": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 166 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 167 | secure: false |
| 168 | }, |
| 169 | "/websocket": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 170 | target: "http://sdnr:8181", |
Michael DÜrre | 21e4a94 | 2021-04-08 07:27:18 +0200 | [diff] [blame] | 171 | ws: true, |
| 172 | changeOrigin: true, |
| 173 | secure: false |
| 174 | }, |
| 175 | "/apidoc": { |
Aijana Schumann | 152cb38 | 2021-12-06 15:09:15 +0100 | [diff] [blame] | 176 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 177 | ws: true, |
| 178 | changeOrigin: true, |
| 179 | secure: false |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | }]; |
| 184 | } |