Keycloak
81 строка · 1.9 Кб
1import commonjs from "@rollup/plugin-commonjs";
2import inject from "@rollup/plugin-inject";
3import { nodeResolve } from "@rollup/plugin-node-resolve";
4import terser from '@rollup/plugin-terser';
5import path from "node:path";
6import type { OutputOptions, RollupOptions } from "rollup";
7import { defineConfig } from "rollup";
8
9interface DefineOptionsArgs {
10file: string;
11name: string;
12amdId: string;
13}
14
15function defineOptions({
16file,
17name,
18amdId,
19}: DefineOptionsArgs): RollupOptions[] {
20const sourceDir = "src";
21const targetDir = "dist";
22const commonOptions = {
23input: path.join(sourceDir, `${file}.js`),
24plugins: [commonjs(), nodeResolve()],
25} satisfies RollupOptions;
26
27const umdOutput: OutputOptions = {
28format: "umd",
29name,
30amd: { id: amdId },
31};
32
33return [
34// Modern ES module variant, with externalized dependencies.
35{
36...commonOptions,
37output: [
38{
39file: path.join(targetDir, `${file}.mjs`),
40},
41],
42external: ["js-sha256", "jwt-decode"],
43},
44// Legacy Universal Module Definition, or “UMD”, with inlined dependencies.
45{
46...commonOptions,
47output: [
48{
49...umdOutput,
50file: path.join(targetDir, `${file}.js`),
51},
52{
53...umdOutput,
54file: path.join(targetDir, `${file}.min.js`),
55sourcemap: true,
56sourcemapExcludeSources: true,
57plugins: [terser()],
58},
59],
60plugins: [
61...commonOptions.plugins,
62inject({
63Promise: ["es6-promise/dist/es6-promise.min.js", "Promise"],
64}),
65],
66},
67];
68}
69
70export default defineConfig([
71...defineOptions({
72file: "keycloak",
73name: "Keycloak",
74amdId: "keycloak",
75}),
76...defineOptions({
77file: "keycloak-authz",
78name: "KeycloakAuthorization",
79amdId: "keycloak-authorization",
80}),
81]);
82