forked from okta/okta-signin-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.playground.config.js
105 lines (100 loc) · 2.78 KB
/
webpack.playground.config.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* eslint no-console:0 */
const path = require('path');
const fs = require('fs');
const nodemon = require('nodemon');
const TARGET = path.resolve(__dirname, 'target');
const PLAYGROUND = path.resolve(__dirname, 'playground');
const DEV_SERVER_PORT = 3000;
const MOCK_SERVER_PORT = 3030;
const WIDGET_RC_JS = '.widgetrc.js';
const WIDGET_RC = '.widgetrc';
if (!fs.existsSync(WIDGET_RC_JS) && fs.existsSync(WIDGET_RC)) {
console.error('============================================');
console.error(`Please migrate the ${WIDGET_RC} to ${WIDGET_RC_JS}.`);
/* eslint-disable-next-line @okta/okta/no-exclusive-language */
console.error('For more information, please see https://github.com/okta/okta-signin-widget/blob/master/MIGRATING.md');
console.error('============================================');
process.exit(1);
}
if (!fs.existsSync(WIDGET_RC_JS)) {
// create default WIDGET_RC if it doesn't exist to simplifed the build process
fs.copyFileSync('.widgetrc.sample.js', WIDGET_RC_JS);
}
module.exports = {
target: 'web',
entry: {
'playground.js': [`${PLAYGROUND}/main.js`]
},
output: {
path: `${PLAYGROUND}`,
filename: 'playground.bundle.js',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['@babel/preset-env']
}
},
]
},
watch: true,
devServer: {
contentBase: [
PLAYGROUND,
TARGET,
// webpack-dev-server v2 only watch contentbase on root level
// explicitly list folders to watch for browser auto reload
// sub-folders can be removed when upgrade to webpack-dev-server v3
path.join(TARGET, 'js'),
path.join(TARGET, 'css'),
],
historyApiFallback: true,
headers: {
'Content-Security-Policy': `script-src http://localhost:${DEV_SERVER_PORT}`
},
compress: true,
port: DEV_SERVER_PORT,
watchContentBase: true,
proxy: [{
context: [
'/oauth2/',
'/api/v1/',
'/idp/idx/',
'/login/getimage',
'/sso/idps/',
'/app/UserHome',
'/oauth2/v1/authorize',
'/auth/services/',
],
target: `http://localhost:${MOCK_SERVER_PORT}`
}],
before() {
const script = path.resolve(
__dirname,
'playground',
'mocks',
'server.js'
);
const watch = [
path.resolve(__dirname, 'playground', 'mocks')
];
const env = {
MOCK_SERVER_PORT,
DEV_SERVER_PORT
};
nodemon({ script, watch, env, delay: 50 })
.on('restart', (filesChanged) => {
console.log(
'file changed:',
filesChanged.join(', ')
);
})
.on('crash', console.error);
},
},
};