blob: 5461c14f29005aa30d08ba7d89440ac482257542 [file] [log] [blame]
herberte6d0d672019-12-14 01:05:47 +01001/**
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
9const path = require("path");
10const webpack = require("webpack");
11const CopyWebpackPlugin = require("copy-webpack-plugin");
12const TerserPlugin = require('terser-webpack-plugin');
13
Aijana Schumann85150522021-02-15 18:22:28 +010014const policies = require('./policies.json');
15
herberte6d0d672019-12-14 01:05:47 +010016// const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
17
18module.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 Schumann1a868112022-02-01 13:18:42 +010091 ...(env === "release" ? [
herberte6d0d672019-12-14 01:05:47 +010092 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 Schumann1a868112022-02-01 13:18:42 +0100109 ])
herberte6d0d672019-12-14 01:05:47 +0100110 ],
111
Aijana Schumann3d022712020-08-12 12:28:06 +0200112 watchOptions: {
113 ignored: /node_modules/
114 },
115
herberte6d0d672019-12-14 01:05:47 +0100116 devServer: {
herberte6d0d672019-12-14 01:05:47 +0100117 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 Schumann85150522021-02-15 18:22:28 +0100133 before: function(app, server, compiler) {
134 app.get('/oauth/policies',(_, res) => res.json(policies));
135 },
Aijana Schumann3d022712020-08-12 12:28:06 +0200136 proxy: {
Aijana Schumanne3ad1d32020-12-04 17:40:42 +0100137 "/about": {
Aijana Schumann85150522021-02-15 18:22:28 +0100138 target: "http://localhost:18181",
Aijana Schumanne3ad1d32020-12-04 17:40:42 +0100139 secure: false
140 },
herberte6d0d672019-12-14 01:05:47 +0100141 "/yang-schema/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100142 target: "http://localhost:18181",
Aijana Schumann3d022712020-08-12 12:28:06 +0200143 secure: false
144 },
Aijana Schumann85150522021-02-15 18:22:28 +0100145 "/oauth/": {
146 target: "http://localhost:18181",
herberte6d0d672019-12-14 01:05:47 +0100147 secure: false
148 },
149 "/database/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100150 target: "http://localhost:18181",
herberte6d0d672019-12-14 01:05:47 +0100151 secure: false
152 },
153 "/restconf/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100154 target: "http://localhost:18181",
Aijana Schumann3d022712020-08-12 12:28:06 +0200155 secure: false
156 },
157 "/rests/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100158 target: "http://localhost:18181",
herberte6d0d672019-12-14 01:05:47 +0100159 secure: false
160 },
161 "/help/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100162 target: "http://localhost:18181",
Aijana Schumanne3ad1d32020-12-04 17:40:42 +0100163 secure: false
164 },
165 "/about/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100166 target: "http://localhost:18181",
Aijana Schumann3d022712020-08-12 12:28:06 +0200167 secure: false
168 },
169 "/tree/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100170 target: "http://localhost:18181",
herberte6d0d672019-12-14 01:05:47 +0100171 secure: false
172 },
173 "/websocket": {
Aijana Schumann85150522021-02-15 18:22:28 +0100174 target: "http://localhost:18181",
175 ws: true,
176 changeOrigin: true,
177 secure: false
178 },
179 "/apidoc": {
180 target: "http://localhost:18181",
herberte6d0d672019-12-14 01:05:47 +0100181 ws: true,
Aijana Schumann3d022712020-08-12 12:28:06 +0200182 changeOrigin: true,
herberte6d0d672019-12-14 01:05:47 +0100183 secure: false
184 }
185 }
186 }
187 }];
188}