2022-01-13 07:28:30 +00:00
|
|
|
import commonjs from "@rollup/plugin-commonjs";
|
|
|
|
import inject from "@rollup/plugin-inject";
|
|
|
|
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
2023-03-03 12:56:53 +00:00
|
|
|
import terser from '@rollup/plugin-terser';
|
2022-01-13 07:28:30 +00:00
|
|
|
import path from "node:path";
|
|
|
|
import type { OutputOptions, RollupOptions } from "rollup";
|
|
|
|
import { defineConfig } from "rollup";
|
|
|
|
|
|
|
|
interface DefineOptionsArgs {
|
|
|
|
file: string;
|
|
|
|
name: string;
|
|
|
|
amdId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function defineOptions({
|
|
|
|
file,
|
|
|
|
name,
|
|
|
|
amdId,
|
|
|
|
}: DefineOptionsArgs): RollupOptions[] {
|
2022-02-08 18:52:46 +00:00
|
|
|
const sourceDir = "src";
|
|
|
|
const targetDir = "dist";
|
2023-03-03 12:56:53 +00:00
|
|
|
const commonOptions = {
|
2022-01-13 07:28:30 +00:00
|
|
|
input: path.join(sourceDir, `${file}.js`),
|
|
|
|
plugins: [commonjs(), nodeResolve()],
|
2023-03-03 12:56:53 +00:00
|
|
|
} satisfies RollupOptions;
|
2022-01-13 07:28:30 +00:00
|
|
|
|
|
|
|
const umdOutput: OutputOptions = {
|
|
|
|
format: "umd",
|
|
|
|
name,
|
|
|
|
amd: { id: amdId },
|
|
|
|
};
|
|
|
|
|
|
|
|
return [
|
|
|
|
// Modern ES module variant, with externalized dependencies.
|
|
|
|
{
|
|
|
|
...commonOptions,
|
|
|
|
output: [
|
|
|
|
{
|
|
|
|
file: path.join(targetDir, `${file}.mjs`),
|
|
|
|
},
|
|
|
|
],
|
2024-09-10 19:13:57 +00:00
|
|
|
external: ["@noble/hashes/sha256", "jwt-decode"],
|
2022-01-13 07:28:30 +00:00
|
|
|
},
|
|
|
|
// Legacy Universal Module Definition, or “UMD”, with inlined dependencies.
|
|
|
|
{
|
|
|
|
...commonOptions,
|
|
|
|
output: [
|
|
|
|
{
|
|
|
|
...umdOutput,
|
|
|
|
file: path.join(targetDir, `${file}.js`),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...umdOutput,
|
|
|
|
file: path.join(targetDir, `${file}.min.js`),
|
|
|
|
sourcemap: true,
|
|
|
|
sourcemapExcludeSources: true,
|
|
|
|
plugins: [terser()],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
...commonOptions.plugins,
|
|
|
|
inject({
|
|
|
|
Promise: ["es6-promise/dist/es6-promise.min.js", "Promise"],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defineConfig([
|
|
|
|
...defineOptions({
|
|
|
|
file: "keycloak",
|
|
|
|
name: "Keycloak",
|
|
|
|
amdId: "keycloak",
|
|
|
|
}),
|
|
|
|
...defineOptions({
|
|
|
|
file: "keycloak-authz",
|
|
|
|
name: "KeycloakAuthorization",
|
|
|
|
amdId: "keycloak-authorization",
|
|
|
|
}),
|
|
|
|
]);
|