-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.dev.js
72 lines (69 loc) · 2.19 KB
/
webpack.dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const {merge} = require('webpack-merge');
const common = require('./webpack.common.js');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const path = require('path');
require('dotenv').config({ path: './.env' });
const getAEMBasicAuth = () => {
if (process.env.AEM_USERNAME && process.env.AEM_PASSWORD) {
const credentialsString = process.env.AEM_USERNAME + ":" + process.env.AEM_PASSWORD
return 'Basic ' + Buffer.from(credentialsString).toString('base64');
} else {
return "";
}
}
const aemProxyReq = (proxyReq) => {
console.log("inside proxy req");
if (process.env.AEM_URL && proxyReq.getHeader("origin")) {
console.log("setting new origin header");
proxyReq.setHeader("origin", process.env.AEM_URL);
}
const authValue = getAEMBasicAuth()
if (authValue) {
console.log("setting authorization header");
proxyReq.setHeader("authorization", authValue);
}
};
module.exports =
merge(common, {
mode: 'development',
devtool: 'source-map',
performance: {hints: 'warning'},
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
client: {
overlay: false
},
open: true,
hot: true,
compress: true,
port: 3000,
proxy: {
'/api': {
target: process.env.FORM_API,
pathRewrite: { '^/api': '' },
},
'/adobe': {
target: process.env.AEM_URL,
secure: false,
changeOrigin: true,
onProxyReq: aemProxyReq
},
'/content': {
target: process.env.AEM_URL,
secure: false,
changeOrigin: true,
onProxyReq: aemProxyReq
}
}
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
generateStatsFile: true,
openAnalyzer: false,
})
],
});