mon-entreprise/site/vite.config.ts.timestamp-16...

349 lines
42 KiB
JavaScript
Raw Permalink Normal View History

// vite.config.ts
import replace from "file:///home/johan/Projets/mon-entreprise/node_modules/@rollup/plugin-replace/dist/rollup-plugin-replace.cjs.js";
import yaml from "file:///home/johan/Projets/mon-entreprise/node_modules/@rollup/plugin-yaml/dist/index.js";
import legacy from "file:///home/johan/Projets/mon-entreprise/node_modules/@vitejs/plugin-legacy/dist/index.mjs";
import react from "file:///home/johan/Projets/mon-entreprise/node_modules/@vitejs/plugin-react/dist/index.mjs";
import fs from "fs/promises";
import path from "path";
import serveStatic from "file:///home/johan/Projets/mon-entreprise/node_modules/serve-static/index.js";
import { defineConfig, loadEnv } from "file:///home/johan/Projets/mon-entreprise/node_modules/vite/dist/node/index.js";
import { VitePWA } from "file:///home/johan/Projets/mon-entreprise/node_modules/vite-plugin-pwa/dist/index.mjs";
// scripts/runScriptOnFileChange/execOnFileChange.ts
import { getPackageDeps } from "file:///home/johan/Projets/mon-entreprise/node_modules/@rushstack/package-deps-hash/lib/index.js";
import { exec as originalExec } from "child_process";
import { existsSync, lstatSync, readFileSync, writeFileSync } from "fs";
import { relative, resolve } from "path";
import { promisify } from "util";
var exec = promisify(originalExec);
var execOnFileChange = async (config) => {
const path2 = resolve(config.basePath, config.depsPath);
const deps = Object.fromEntries(getPackageDeps(config.basePath));
const depsEntries = Object.entries(deps);
const existingDeps = existsSync(path2) ? JSON.parse(readFileSync(path2, { encoding: "utf8" })) : {};
const existingDepsEntries = Object.entries(existingDeps);
const promises = config.options.map(async (cfg) => {
let fileChanged = null;
const index = cfg.paths.map((val) => {
const isDir = lstatSync(resolve(config.basePath, val)).isDirectory();
const isFile = lstatSync(resolve(config.basePath, val)).isFile();
return {
isDir,
isFile,
absolute: resolve(config.basePath, val),
relative: relative(
resolve(config.basePath),
resolve(config.basePath, val)
)
};
}).findIndex(({ absolute, relative: relative2, isFile, isDir }) => {
if (isFile) {
if (deps[relative2] !== existingDeps[relative2]) {
fileChanged = relative2;
}
return deps[relative2] !== existingDeps[relative2];
} else if (isDir) {
const index2 = depsEntries.findIndex(
([a, b], i) => {
var _a, _b;
return (relative2.length ? a.startsWith(relative2 + "/") : true) && (((_a = existingDepsEntries == null ? void 0 : existingDepsEntries[i]) == null ? void 0 : _a[0]) !== a || ((_b = existingDepsEntries == null ? void 0 : existingDepsEntries[i]) == null ? void 0 : _b[1]) !== b);
}
);
if (index2 > -1) {
fileChanged = depsEntries[index2][0];
}
return index2 > -1;
}
throw new Error("Path is not a directory or a file: " + absolute);
});
if (index > -1) {
const result = await exec(cfg.run);
return {
path: cfg.paths[index],
fileChanged,
run: cfg.run,
result
};
}
return null;
});
const res = await Promise.all(promises);
writeFileSync(path2, JSON.stringify(deps, null, 2));
return res;
};
// scripts/runScriptOnFileChange/index.ts
var runScriptOnFileChange = async () => {
console.log("Search for changed file...");
const results = await execOnFileChange({
basePath: "./",
depsPath: ".deps.json",
options: [
{
paths: [
"./source/pages/Simulateurs/EconomieCollaborative/activit\xE9s.yaml",
"./source/pages/Simulateurs/EconomieCollaborative/activit\xE9s.en.yaml"
],
run: "yarn build:yaml-to-dts"
}
]
});
results.filter((x) => !!x).forEach(({ fileChanged, run, result }) => {
console.log("Changed file detected:", fileChanged);
console.log("Execute:", run, "\n");
if (result.stdout) {
console.log(result.stdout);
}
if (result.stderr) {
console.error(result.stderr);
}
});
};
// vite-pwa-options.ts
var pwaOptions = {
registerType: "prompt",
strategies: "injectManifest",
srcDir: "source",
filename: "sw.ts",
injectManifest: {
maximumFileSizeToCacheInBytes: 3e6,
manifestTransforms: [
(entries) => {
const manifest = entries.filter(
(entry) => !/assets\/.*(-legacy|lazy_)/.test(entry.url) && (entry.url.endsWith(".html") ? /(infrance|mon-entreprise)\.html/.test(entry.url) : true)
);
return { manifest };
}
]
},
includeAssets: ["logo-*.png"],
manifest: {
start_url: "/",
name: "Mon entreprise",
short_name: "Mon entreprise",
description: "L'assistant officiel du cr\xE9ateur d'entreprise",
lang: "fr",
orientation: "portrait-primary",
display: "minimal-ui",
theme_color: "#2975d1",
background_color: "#ffffff",
icons: [
{
src: "/favicon/android-chrome-192x192-shadow.png?v=2.0",
sizes: "192x192",
type: "image/png"
},
{
src: "/favicon/android-chrome-512x512-shadow.png?v=2.0",
sizes: "512x512",
type: "image/png"
}
]
}
};
// vite.config.ts
var __vite_injected_original_import_meta_url = "file:///home/johan/Projets/mon-entreprise/site/vite.config.ts";
var env = (mode) => loadEnv(mode, process.cwd(), "");
var vite_config_default = defineConfig(({ command, mode }) => ({
resolve: {
alias: { "@": path.resolve("./source") },
extensions: [".js", ".ts", ".jsx", ".tsx", ".json"]
},
publicDir: "source/public",
build: {
sourcemap: true,
rollupOptions: {
output: {
chunkFileNames: (chunkInfo) => {
if (chunkInfo.isDynamicEntry) {
return "assets/lazy_[name].[hash].js";
}
return "assets/[name].[hash].js";
}
}
}
},
define: {
BRANCH_NAME: JSON.stringify(getBranch(mode)),
IS_DEVELOPMENT: mode === "development",
IS_STAGING: mode === "production" && !isProductionBranch(mode),
IS_PRODUCTION: mode === "production" && isProductionBranch(mode)
},
plugins: [
{
name: "run-script-on-file-change",
apply: "serve",
buildStart() {
if (mode === "development") {
void runScriptOnFileChange();
}
}
},
command === "build" && replace({
__SENTRY_DEBUG__: false,
preventAssignment: false
}),
react({
babel: {
plugins: [["babel-plugin-styled-components", { pure: true }]]
}
}),
yaml(),
multipleSPA({
defaultSite: "mon-entreprise",
templatePath: "./source/template.html",
sites: {
"mon-entreprise": {
lang: "fr",
entry: "/source/entry-fr.tsx",
title: "mon-entreprise.urssaf.fr : L'assistant officiel du cr\xE9ateur d'entreprise",
description: "Du statut juridique \xE0 la premi\xE8re embauche, en passant par la simulation des cotisations, vous trouverez ici toutes les ressources pour d\xE9marrer votre activit\xE9.",
shareImage: "/source/images/logo-monentreprise.svg",
shareImageAlt: "Logo mon-entreprise, site Urssaf"
},
infrance: {
lang: "en",
entry: "/source/entry-en.tsx",
title: "My company in France: A step-by-step guide to start a business in France",
description: "Find the type of company that suits you and follow the steps to register your company. Discover the French social security system by simulating your hiring costs. Discover the procedures to hire in France and learn the basics of French labour law.",
shareImage: "/logo-mycompany-share.png",
shareImageAlt: "Logo My company in France by Urssaf"
}
}
}),
VitePWA(pwaOptions),
legacy({
targets: ["defaults", "not IE 11"]
})
],
server: {
port: 3e3,
hmr: {
clientPort: typeof env(mode).HMR_CLIENT_PORT !== "undefined" ? parseInt(env(mode).HMR_CLIENT_PORT) : void 0
},
watch: {
ignored: [
"!**/node_modules/publicodes/**",
"!**/node_modules/publicodes-react/**"
]
},
proxy: {
"/api": "http://localhost:3004",
"/twemoji": {
target: "https://twemoji.maxcdn.com",
changeOrigin: true,
rewrite: (path2) => path2.replace(/^\/twemoji/, ""),
timeout: 3 * 1e3
}
}
},
optimizeDeps: {
entries: ["./source/entry-fr.tsx", "./source/entry-en.tsx"],
exclude: ["publicodes-react", "publicodes"],
include: ["publicodes > moo", "publicodes > nearley"]
},
ssr: {
noExternal: [
/react-aria|react-stately|internationalized/,
/markdown-to-jsx/,
/styled-components|emotion/,
/publicodes-react/
]
}
}));
function multipleSPA(options) {
const fillTemplate = async (siteName) => {
const siteData = options.sites[siteName];
const template = await fs.readFile(options.templatePath, "utf-8");
const filledTemplate = template.toString().replace(/\{\{(.+)\}\}/g, (_match, p1) => siteData[p1.trim()]);
return filledTemplate;
};
return {
name: "multiple-spa",
enforce: "pre",
configureServer(vite) {
vite.middlewares.use(
"/simulateur-iframe-integration.js",
serveStatic(new URL("./dist", __vite_injected_original_import_meta_url).pathname, {
index: "simulateur-iframe-integration.js"
})
);
vite.middlewares.use(async (req, res, next) => {
var _a;
const url = (_a = req.originalUrl) == null ? void 0 : _a.replace(/^\/%2F/, "/");
const firstLevelDir = url == null ? void 0 : url.slice(1).split("/")[0];
if (url && /\?.*html-proxy/.test(url)) {
return next();
}
if (url && ["/", "/index.html"].includes(url)) {
res.writeHead(302, { Location: "/" + options.defaultSite }).end();
} else if (firstLevelDir && url && Object.keys(options.sites).map((site) => `/${site}.html`).includes(url)) {
const siteName = firstLevelDir.replace(".html", "");
const content = await vite.transformIndexHtml(
"/" + siteName,
await fillTemplate(siteName)
);
res.end(content);
} else if (firstLevelDir && Object.keys(options.sites).some((name) => firstLevelDir === name)) {
const siteName = firstLevelDir;
const content = await vite.transformIndexHtml(
url,
await fillTemplate(siteName)
);
res.end(content);
} else {
next();
}
});
},
config(config, { command }) {
var _a, _b;
if (command === "build" && !((_a = config.build) == null ? void 0 : _a.ssr)) {
config.build = {
...config.build,
rollupOptions: {
...(_b = config.build) == null ? void 0 : _b.rollupOptions,
input: Object.fromEntries(
Object.keys(options.sites).map((name) => [
name,
`virtual:${name}.html`
])
)
}
};
}
},
resolveId(id) {
const pathname = id.split("/").slice(-1)[0];
if (pathname == null ? void 0 : pathname.startsWith("virtual:")) {
return pathname.replace("virtual:", "");
}
return null;
},
async load(id) {
if (Object.keys(options.sites).some((name) => id.endsWith(name + ".html"))) {
return await fillTemplate(id.replace(/\.html$/, ""));
}
}
};
}
var getBranch = (mode) => {
var _a, _b, _c;
let branch = (_c = (_b = (_a = env(mode).VITE_GITHUB_REF) == null ? void 0 : _a.split("/")) == null ? void 0 : _b.slice(-1)) == null ? void 0 : _c[0];
if (branch === "merge") {
branch = env(mode).VITE_GITHUB_HEAD_REF;
}
return branch ?? "";
};
var isProductionBranch = (mode) => {
return ["master", "next"].includes(getBranch(mode));
};
export {
vite_config_default as default,
getBranch,
isProductionBranch
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiLCAic2NyaXB0cy9ydW5TY3JpcHRPbkZpbGVDaGFuZ2UvZXhlY09uRmlsZUNoYW5nZS50cyIsICJzY3JpcHRzL3J1blNjcmlwdE9uRmlsZUNoYW5nZS9pbmRleC50cyIsICJ2aXRlLXB3YS1vcHRpb25zLnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJjb25zdCBfX3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