-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
159 lines (152 loc) · 4.66 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
156
157
158
159
/*
=========================================================
* © 2024 Ronan LE MEILLAT for SCTG Development
=========================================================
*/
/* eslint-disable no-undef */
import devCerts from "office-addin-dev-certs";
import CopyWebpackPlugin from "copy-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import WebpackShellPluginNext from "webpack-shell-plugin-next";
import webpack from "webpack";
import fs from "fs";
import path from "path";
import { simpleGit } from "simple-git";
import { format } from "prettier";
const urlDev = "https://localhost:3000/";
async function generateVersionFile() {
const git = simpleGit();
const commit = await git.revparse(["HEAD"]);
const commitDate = await git.show(["-s", "--format=%ci", commit]);
const versionInfo = { commit, date: commitDate.replaceAll("\n", "") };
const versionInfoText = `export const versionInfo = ${JSON.stringify(versionInfo, null, 2)};`;
const versionInfoTypeScript = await format(versionInfoText, {
parser: "typescript",
plugins: ["eslint-plugin-office-addins"],
});
fs.writeFileSync(path.resolve(".", "src/version.ts"), versionInfoTypeScript);
}
async function getHttpsOptions() {
const httpsOptions = await devCerts.getHttpsServerOptions();
return { ca: httpsOptions.ca, key: httpsOptions.key, cert: httpsOptions.cert };
}
export default async (env, options) => {
const dev = options.mode === "development";
const urlProd =
env.website === "GITHUB_PAGES" ? "https://sctg-development.github.io/ai-outlook/" : "https://outlook.addin.pp.ua/"; // CHANGE THIS TO YOUR PRODUCTION DEPLOYMENT LOCATION
const config = {
devtool: "source-map",
entry: {
polyfill: ["core-js/stable", "regenerator-runtime/runtime"],
vendor: ["react", "react-dom", "core-js", "@fluentui/react-components", "@fluentui/react-icons"],
taskpane: ["./src/aipane/index.tsx", "./src/aipane/index.html"],
},
output: {
filename: "sctg_ai_outlook_[contenthash].js",
clean: true,
},
optimization: {
splitChunks: {
maxSize: 250000,
chunks: "all",
},
},
resolve: {
extensions: [".ts", ".tsx", ".html", ".js"],
fallback: { url: false, fs: false, module: false, ResizeObserver: false },
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-typescript"],
plugins: ["@babel/plugin-syntax-import-attributes"],
},
},
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: ["ts-loader"],
},
{
test: /\.html$/,
exclude: /node_modules/,
use: "html-loader",
},
{
test: /favicon\.ico$/,
type: "asset/resource",
generator: {
filename: "assets/[name][ext][query]",
},
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: "assets/*",
to: "assets/[name][ext][query]",
},
{
from: "manifest*.{json,xml}",
to: "[name]" + "[ext]",
transform(content) {
if (dev) {
return content;
} else {
return content.toString().replace(new RegExp(urlDev, "g"), urlProd);
}
},
},
],
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/aipane/index.html",
chunks: ["polyfill", "vendor", "taskpane"],
}),
new HtmlWebpackPlugin({
filename: "aipane.html",
template: "./src/aipane/index.html",
chunks: ["polyfill", "vendor", "taskpane"],
}),
new webpack.ProvidePlugin({
Promise: ["es6-promise", "Promise"],
}),
new WebpackShellPluginNext({
onBuildStart: {
scripts: [generateVersionFile],
blocking: true,
parallel: false,
},
}),
new webpack.DefinePlugin({
WEBSITE_ENV: JSON.stringify(env.website),
}),
],
devServer: {
hot: true,
headers: {
"Access-Control-Allow-Origin": "*",
},
server: {
type: "https",
options: env.WEBPACK_BUILD || options.https !== undefined ? options.https : await getHttpsOptions(),
},
port: process.env.npm_package_config_dev_server_port || 3000,
historyApiFallback: true,
},
};
return config;
};