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 | |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [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 | configurationApp: ["./pluginConfiguration.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 | |
| 80 | plugins: [ |
| 81 | new webpack.DllReferencePlugin({ |
| 82 | context: path.resolve(__dirname, "../../framework/src"), |
| 83 | manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")), |
| 84 | sourceType: "umd2" |
| 85 | }), |
| 86 | new webpack.DllReferencePlugin({ |
| 87 | context: path.resolve(__dirname, "../../framework/src"), |
| 88 | manifest: require(path.resolve(frameworkPath, "app-manifest.json")), |
| 89 | sourceType: "umd2" |
| 90 | }), |
Aijana Schumann | 1a86811 | 2022-02-01 13:18:42 +0100 | [diff] [blame^] | 91 | ...(env === "release" ? [ |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 92 | new webpack.DefinePlugin({ |
| 93 | "process.env": { |
| 94 | NODE_ENV: "'production'", |
| 95 | VERSION: JSON.stringify(require("./package.json").version) |
| 96 | } |
| 97 | }), |
| 98 | ] : [ |
| 99 | new webpack.DefinePlugin({ |
| 100 | "process.env": { |
| 101 | NODE_ENV: "'development'", |
| 102 | VERSION: JSON.stringify(require("./package.json").version) |
| 103 | } |
| 104 | }), |
| 105 | new CopyWebpackPlugin([{ |
| 106 | from: 'index.html', |
| 107 | to: distPath |
| 108 | }]), |
Aijana Schumann | 1a86811 | 2022-02-01 13:18:42 +0100 | [diff] [blame^] | 109 | ]) |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 110 | ], |
| 111 | |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 112 | watchOptions: { |
| 113 | ignored: /node_modules/ |
| 114 | }, |
| 115 | |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 116 | devServer: { |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 117 | contentBase: frameworkPath, |
| 118 | |
| 119 | compress: true, |
| 120 | headers: { |
| 121 | "Access-Control-Allow-Origin": "*" |
| 122 | }, |
| 123 | host: "0.0.0.0", |
| 124 | port: 3100, |
| 125 | disableHostCheck: true, |
| 126 | historyApiFallback: true, |
| 127 | inline: true, |
| 128 | hot: false, |
| 129 | quiet: false, |
| 130 | stats: { |
| 131 | colors: true |
| 132 | }, |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 133 | before: function(app, server, compiler) { |
| 134 | app.get('/oauth/policies',(_, res) => res.json(policies)); |
| 135 | }, |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 136 | proxy: { |
Aijana Schumann | e3ad1d3 | 2020-12-04 17:40:42 +0100 | [diff] [blame] | 137 | "/about": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 138 | target: "http://localhost:18181", |
Aijana Schumann | e3ad1d3 | 2020-12-04 17:40:42 +0100 | [diff] [blame] | 139 | secure: false |
| 140 | }, |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 141 | "/yang-schema/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 142 | target: "http://localhost:18181", |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 143 | secure: false |
| 144 | }, |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 145 | "/oauth/": { |
| 146 | target: "http://localhost:18181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 147 | secure: false |
| 148 | }, |
| 149 | "/database/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 150 | target: "http://localhost:18181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 151 | secure: false |
| 152 | }, |
| 153 | "/restconf/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 154 | target: "http://localhost:18181", |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 155 | secure: false |
| 156 | }, |
| 157 | "/rests/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 158 | target: "http://localhost:18181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 159 | secure: false |
| 160 | }, |
| 161 | "/help/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 162 | target: "http://localhost:18181", |
Aijana Schumann | e3ad1d3 | 2020-12-04 17:40:42 +0100 | [diff] [blame] | 163 | secure: false |
| 164 | }, |
| 165 | "/about/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 166 | target: "http://localhost:18181", |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 167 | secure: false |
| 168 | }, |
| 169 | "/tree/": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 170 | target: "http://localhost:18181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 171 | secure: false |
| 172 | }, |
| 173 | "/websocket": { |
Aijana Schumann | 8515052 | 2021-02-15 18:22:28 +0100 | [diff] [blame] | 174 | target: "http://localhost:18181", |
| 175 | ws: true, |
| 176 | changeOrigin: true, |
| 177 | secure: false |
| 178 | }, |
| 179 | "/apidoc": { |
| 180 | target: "http://localhost:18181", |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 181 | ws: true, |
Aijana Schumann | 3d02271 | 2020-08-12 12:28:06 +0200 | [diff] [blame] | 182 | changeOrigin: true, |
herbert | e6d0d67 | 2019-12-14 01:05:47 +0100 | [diff] [blame] | 183 | secure: false |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | }]; |
| 188 | } |