This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdev-mode.js
94 lines (84 loc) · 3.06 KB
/
dev-mode.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
const express = require('express');
const webpack = require('webpack');
const middleware = require('webpack-dev-middleware');
const fs = require("fs");
const path = require("path");
const SERVER_PORT = 3124;
const PUBLIC_PATH = `http://127.0.0.1:${SERVER_PORT}/`;
const providerString = process.argv.find((value => value.startsWith('--provider=')));
const isDir = (fp) => {
try {
return fs.statSync(fp).isDirectory();
} catch(e) {
return false;
}
};
if(providerString === undefined){
console.error('Expecting --provider=<Name>');
process.exit(1);
} else {
const provider = providerString.split("=")[1].trim();
console.log(`Running dev mode for ${provider}`);
if (isDir(path.resolve(__dirname, 'providers/' + provider))) {
//good to go...
const compiler = webpack({
mode: 'development',
entry: {
main: './providers/' + provider + '/src/Main.ts',
},
output: {
path: '/tmp',
filename: '[name].js',
chunkFilename: '[name].chunk.js',
publicPath: PUBLIC_PATH,
jsonpFunction: '_s8_' + provider.toLowerCase() + '_loader',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json']
},
devtool: 'inline-source-map',
watch: false,
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env',{
useBuiltIns: "usage",
targets: "> 0.25%, last 2 versions, not dead, ie 11",
corejs: "3.15.1",
debug: true
}]
,'@babel/preset-typescript'],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread'
]
}
},
]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader',
},
],
}
});
const instance = middleware(compiler);
const app = express();
app.use(instance);
app.listen(SERVER_PORT, () => {
console.log(`Server @ ${PUBLIC_PATH}`);
});
} else {
console.error(`Unable to find provider '${provider}'`);
process.exit(1);
}
}