Skip to content
Snippets Groups Projects
Select Git revision
  • 42180bc49930471a2eb83a4c15f5dc4d2954c0a7
  • main default protected
  • renovate/lock-file-maintenance
  • demo protected
  • person-select-custom
  • dbp-translation-component
  • icon-set-mapping
  • port-i18next-parser
  • remove-sentry
  • favorites-and-recent-files
  • revert-6c632dc6
  • lit2
  • advertisement
  • wc-part
  • automagic
  • publish
  • wip-cleanup
  • demo-file-handling
18 results

rollup.config.js

Blame
  • rollup.config.js 3.01 KiB
    import glob from 'glob';
    import url from 'url';
    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';
    
    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);
        return {
            input:
                build != 'test'
                    ? ['src/' + appName + '.js', 'src/' + appName + '-demo.js']
                    : glob.sync('test/**/*.js'),
            output: {
                dir: 'dist',
                entryFileNames: '[name].js',
                chunkFileNames: 'shared/[name].[hash].[format].js',
                format: 'esm',
                sourcemap: true,
            },
            onwarn: function (warning, warn) {
                // keycloak bundled code uses eval
                if (warning.code === 'EVAL' && warning.id.includes('sha256.js')) {
                    return;
                }
                warn(warning);
            },
            plugins: [
                del({
                    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,
                    },
                }),
                resolve(),
                commonjs(),
                json(),
                build !== 'local' && build !== 'test' ? terser() : false,
                copy({
                    targets: [
                        {src: 'assets/silent-check-sso.html', dest: 'dist'},
                        {
                            src: await getPackagePath('@dbp-toolkit/common', 'assets/icons/*.svg'),
                            dest: 'dist/' + (await getDistPath('@dbp-toolkit/common', 'icons')),
                        },
                    ],
                }),
                process.env.ROLLUP_WATCH === 'true'
                    ? serve({
                          contentBase: '.',
                          historyApiFallback: basePath + 'index.html',
                          host: '127.0.0.1',
                          port: 8002,
                      })
                    : false,
            ],
        };
    })();