forked from microsoft/MHA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
155 lines (145 loc) · 5.15 KB
/
webpack.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const path = require('path');
const devCerts = require("office-addin-dev-certs");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const webpack = require('webpack');
async function getHttpsOptions() {
const httpsOptions = await devCerts.getHttpsServerOptions();
return { ca: httpsOptions.ca, key: httpsOptions.key, cert: httpsOptions.cert };
}
// Simple stupid hash to reduce commit ID to something short
const getHash = function (str) {
var hash = 42;
if (str.length) { for (var i = 0; i < str.length; i++) { hash = Math.abs((hash << 5) - hash + str.charCodeAt(i)); } }
return hash.toString(16);
};
var commitID = process.env.SCM_COMMIT_ID;
if (!commitID) commitID = "test";
const version = getHash(commitID);
console.log("commitID: " + commitID);
console.log("version: " + version);
var aikey = process.env.APPINSIGHTS_INSTRUMENTATIONKEY;
if (typeof (aikey) === "undefined" || aikey === "") aikey = "unknown";
console.log("aikey: " + aikey);
const buildTime = new Date().toUTCString();
console.log("buildTime: " + buildTime);
const pages =
[
{ "name": "unittests", "script": "unittests" },
{ "name": "mha", "script": "StandAlone" },
{ "name": "parentframe", "script": "uiToggle" },
{ "name": "newDesktopFrame", "script": "DesktopPane" },
{ "name": "classicDesktopFrame", "script": "Default" },
{ "name": "newMobilePaneIosFrame", "script": "MobilePane-ios" },
{ "name": "privacy", "script": "privacy" },
// Redirection/static pages
{ "name": "Default" },
{ "name": "DefaultPhone" },
{ "name": "DefaultTablet" },
{ "name": "DesktopPane" },
{ "name": "MobilePane" },
{ "name": "Functions" },
];
function generateEntry() {
return pages.reduce((config, page) => {
if (typeof (page.script) === "undefined") return config;
config[page.script] = `./src/Scripts/${page.script}.ts`;
return config;
}, {});
}
function generateHtmlWebpackPlugins() {
return pages.map(function (page) {
return new HtmlWebpackPlugin({
inject: true,
template: `./src/Pages/${page.name}.html`,
filename: `${page.name}.html`,
chunks: [page.script]
})
});
}
module.exports = async (env, options) => {
const config = {
entry: generateEntry(),
plugins: [
new MiniCssExtractPlugin({
filename: version + '/[name].css'
}),
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(version),
__AIKEY__: JSON.stringify(aikey),
__BUILDTIME__: JSON.stringify(buildTime)
}),
new FileManagerPlugin({
events: {
onEnd: {
copy: [
{ source: './src/Resources/*.gif', destination: './Resources/' },
{ source: './src/Resources/*.jpg', destination: './Resources/' }
]
}
}
}),
new ForkTsCheckerWebpackPlugin(),
].concat(generateHtmlWebpackPlugins()),
mode: 'development',
devtool: 'source-map',
target: ['web', 'es5'],
module: {
rules: [
{ test: /fabric(\.min)?\.js$/, use: 'exports-loader?exports=fabric' },
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
logLevel: "info"
}
}
],
exclude: /node_modules/,
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"],
},
],
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
},
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: version + '/[name].js',
path: path.resolve(__dirname, 'Pages'),
publicPath: '/Pages/',
clean: true,
},
devServer: {
headers: {
"Access-Control-Allow-Origin": "*",
},
static: __dirname,
server: {
type: 'https',
options: env.WEBPACK_BUILD || options.https !== undefined ? options.https : await getHttpsOptions(),
},
port: process.env.npm_package_config_dev_server_port || 44336,
},
};
return config;
};