45
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
/* eslint-disable */
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const webpack = require("webpack");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
|
||||
/** Lecture minimale de .env (sans dépendance) ; les variables d'environnement priment. */
|
||||
function loadEnv() {
|
||||
const env = {};
|
||||
const file = path.resolve(__dirname, ".env");
|
||||
if (fs.existsSync(file)) {
|
||||
for (const line of fs.readFileSync(file, "utf8").split(/\r?\n/)) {
|
||||
const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (m) env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
||||
}
|
||||
}
|
||||
return { ...env, ...process.env };
|
||||
}
|
||||
|
||||
module.exports = async (_env, argv) => {
|
||||
const e = loadEnv();
|
||||
const baseUrl = (e.ADDIN_BASE_URL || "https://signature.beziers-mediterranee.fr/addin").replace(/\/$/, "");
|
||||
const origin = new URL(baseUrl).origin;
|
||||
const config = {
|
||||
tenantId: e.ENTRA_TENANT_ID || "",
|
||||
clientId: e.ADDIN_CLIENT_ID || "",
|
||||
apiBaseUrl: e.API_BASE_URL || origin,
|
||||
apiScope: e.API_SCOPE || "",
|
||||
portalUrl: e.PORTAL_URL || `${origin}/me`,
|
||||
};
|
||||
if (argv.mode === "production" && (!config.tenantId || !config.clientId || !config.apiScope)) {
|
||||
console.warn("\n[ATTENTION] ENTRA_TENANT_ID, ADDIN_CLIENT_ID ou API_SCOPE vide : renseignez addin/.env\n");
|
||||
}
|
||||
|
||||
// Serveur de dev HTTPS (npm run dev-server) : certificat localhost approuvé par office-addin-dev-certs,
|
||||
// /api et /img relayés vers le Laravel local pour éviter le contenu mixte.
|
||||
let devServer;
|
||||
if (process.env.WEBPACK_SERVE) {
|
||||
const devCerts = require("office-addin-dev-certs");
|
||||
const https = await devCerts.getHttpsServerOptions();
|
||||
const backend = e.DEV_BACKEND_URL || "http://127.0.0.1:8000";
|
||||
devServer = {
|
||||
port: Number(new URL(baseUrl).port || 3000),
|
||||
server: { type: "https", options: { ca: https.ca, key: https.key, cert: https.cert } },
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
static: false,
|
||||
devMiddleware: { publicPath: new URL(baseUrl).pathname.replace(/\/?$/, "/") },
|
||||
proxy: [{ context: ["/api", "/img"], target: backend, changeOrigin: true }],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
devServer,
|
||||
entry: {
|
||||
launchevent: "./src/launchevent/launchevent.ts",
|
||||
taskpane: "./src/taskpane/taskpane.ts",
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "[name].js",
|
||||
clean: true,
|
||||
},
|
||||
resolve: { extensions: [".ts", ".js"] },
|
||||
module: { rules: [{ test: /\.ts$/, use: "ts-loader", exclude: /node_modules/ }] },
|
||||
devtool: argv.mode === "production" ? false : "source-map",
|
||||
performance: { hints: false },
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({ __ADDIN_CONFIG__: JSON.stringify(config) }),
|
||||
new HtmlWebpackPlugin({
|
||||
filename: "commands.html",
|
||||
template: "./src/launchevent/commands.html",
|
||||
chunks: ["launchevent"],
|
||||
scriptLoading: "blocking",
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
filename: "taskpane.html",
|
||||
template: "./src/taskpane/taskpane.html",
|
||||
chunks: ["taskpane"],
|
||||
}),
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{ from: "assets", to: "assets" },
|
||||
{
|
||||
from: "manifest.xml",
|
||||
to: "manifest.xml",
|
||||
transform: (content) =>
|
||||
content
|
||||
.toString()
|
||||
.replace(/\{\{BASE_URL\}\}/g, baseUrl)
|
||||
.replace(/\{\{ORIGIN\}\}/g, origin)
|
||||
.replace(/\{\{SUPPORT_URL\}\}/g, e.SUPPORT_URL || `${origin}/aide`),
|
||||
},
|
||||
],
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user