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 | connectApp: ["./pluginConnect.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 | plugins: [ |
| 78 | new webpack.DllReferencePlugin({ |
| 79 | context: path.resolve(__dirname, "../../framework/src"), |
| 80 | manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")), |
| 81 | sourceType: "umd2" |
| 82 | }), |
| 83 | new webpack.DllReferencePlugin({ |
| 84 | context: path.resolve(__dirname, "../../framework/src"), |
| 85 | manifest: require(path.resolve(frameworkPath, "app-manifest.json")), |
| 86 | sourceType: "umd2" |
| 87 | }), |
| 88 | ...(env === "release") ? [ |
| 89 | new webpack.DefinePlugin({ |
| 90 | "process.env": { |
| 91 | NODE_ENV: "'production'", |
| 92 | VERSION: JSON.stringify(require("./package.json").version) |
| 93 | } |
| 94 | }), |
| 95 | ] : [ |
| 96 | new webpack.DefinePlugin({ |
| 97 | "process.env": { |
| 98 | NODE_ENV: "'development'", |
| 99 | VERSION: JSON.stringify(require("./package.json").version) |
| 100 | } |
| 101 | }), |
| 102 | new CopyWebpackPlugin([{ |
| 103 | from: 'index.html', |
| 104 | to: distPath |
| 105 | }]), |
| 106 | ] |
| 107 | ], |
| 108 | |
| 109 | devServer: { |
| 110 | public: "http://localhost:3100", |
| 111 | contentBase: frameworkPath, |
| 112 | |
| 113 | compress: true, |
| 114 | headers: { |
| 115 | "Access-Control-Allow-Origin": "*" |
| 116 | }, |
| 117 | host: "0.0.0.0", |
| 118 | port: 3100, |
| 119 | disableHostCheck: true, |
| 120 | historyApiFallback: true, |
| 121 | inline: true, |
| 122 | hot: false, |
| 123 | quiet: false, |
| 124 | stats: { |
| 125 | colors: true |
| 126 | }, |
| 127 | proxy: { |
| 128 | "/oauth2/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 129 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 130 | secure: false |
| 131 | }, |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 132 | |
| 133 | "/oauth/": { |
| 134 | target: "http://sdnr:8181", |
| 135 | secure: false |
| 136 | }, |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 137 | "/database/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 138 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 139 | secure: false |
| 140 | }, |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 141 | "/restconf/": { |
| 142 | target: "http://sdnr:8181", |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 143 | secure: false |
| 144 | }, |
| 145 | "/rests/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 146 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 147 | secure: false |
| 148 | }, |
| 149 | "/help/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 150 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 151 | secure: false |
| 152 | }, |
| 153 | "/websocket": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 154 | target: "http://sdnr:8181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 155 | ws: true, |
| 156 | changeOrigin: true, |
| 157 | secure: false |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | }]; |
| 162 | } |