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