Skip to content
Snippets Groups Projects
rollup.config.js 3.01 KiB
Newer Older
import url from 'url';
Reiter, Christoph's avatar
Reiter, Christoph committed
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import terser from '@rollup/plugin-terser';
import serve from 'rollup-plugin-serve';
import del from 'rollup-plugin-delete';
import json from '@rollup/plugin-json';
import emitEJS from 'rollup-plugin-emit-ejs';
import {getPackagePath, getDistPath} from '../../rollup.utils.js';
import config from '../../demo.common.config.js';
Reiter, Christoph's avatar
Reiter, Christoph committed
const build = typeof process.env.BUILD !== 'undefined' ? process.env.BUILD : 'local';
console.log('build: ' + build);
const pkg = require('./package.json');
const basePath = '/dist/';
const appName = 'dbp-auth';

export default (async () => {
    let privatePath = await getDistPath(pkg.name);
Reiter, Christoph's avatar
Reiter, Christoph committed
        input:
            build != 'test'
                ? ['src/' + appName + '.js', 'src/' + appName + '-demo.js']
Reiter, Christoph's avatar
Reiter, Christoph committed
                : glob.sync('test/**/*.js'),
        output: {
            dir: 'dist',
            entryFileNames: '[name].js',
            chunkFileNames: 'shared/[name].[hash].[format].js',
            format: 'esm',
Reiter, Christoph's avatar
Reiter, Christoph committed
            sourcemap: true,
        onwarn: function (warning, warn) {
            // keycloak bundled code uses eval
            if (warning.code === 'EVAL' && warning.id.includes('sha256.js')) {
                return;
            }
            warn(warning);
        },
Reiter, Christoph's avatar
Reiter, Christoph committed
                targets: 'dist/*',
            emitEJS({
                src: 'assets',
                include: ['**/*.ejs', '**/.*.ejs'],
                data: {
                    getUrl: (p) => {
                        return url.resolve(basePath, p);
                    },
                    getPrivateUrl: (p) => {
                        return url.resolve(`${basePath}${privatePath}/`, p);
                    },
                    name: appName,
                    entryPointURL: config.entryPointURL,
                    keyCloakBaseURL: config.keyCloakBaseURL,
                    keyCloakRealm: config.keyCloakRealm,
                    keyCloakClientId: config.keyCloakClientId,
                },
            }),
Reiter, Christoph's avatar
Reiter, Christoph committed
            build !== 'local' && build !== 'test' ? terser() : false,
                    {src: 'assets/silent-check-sso.html', dest: 'dist'},
Reiter, Christoph's avatar
Reiter, Christoph committed
                    {
                        src: await getPackagePath('@dbp-toolkit/common', 'assets/icons/*.svg'),
                        dest: 'dist/' + (await getDistPath('@dbp-toolkit/common', 'icons')),
                    },
Reiter, Christoph's avatar
Reiter, Christoph committed
            process.env.ROLLUP_WATCH === 'true'
                ? serve({
                      contentBase: '.',
                      historyApiFallback: basePath + 'index.html',
                      host: '127.0.0.1',
                      port: 8002,
                  })
Reiter, Christoph's avatar
Reiter, Christoph committed
                : false,
        ],
Reiter, Christoph's avatar
Reiter, Christoph committed
})();