-
Reiter, Christoph authored
Instead of hardcoding the paths of the node_modules directory we use the node-resolve plugin of rollup to find the root of the corresponding JS package and calcucate a path from there. Resolving a package requires calling an async function, so we have to use await in the rollup config. Luckily rollup supports configs wrapped in a promise, so we just have to wrap it in a function which returns a promise.
Reiter, Christoph authoredInstead of hardcoding the paths of the node_modules directory we use the node-resolve plugin of rollup to find the root of the corresponding JS package and calcucate a path from there. Resolving a package requires calling an async function, so we have to use await in the rollup config. Luckily rollup supports configs wrapped in a promise, so we just have to wrap it in a function which returns a promise.
rollup.config.js 2.09 KiB
import glob from 'glob';
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 json from '@rollup/plugin-json';
import serve from 'rollup-plugin-serve';
import url from "@rollup/plugin-url"
import consts from 'rollup-plugin-consts';
import del from 'rollup-plugin-delete';
import {getPackagePath} from '../../rollup.utils.js';
const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local';
console.log("build: " + build);
export default (async () => {
return {
input: (build != 'test') ? ['src/dbp-person-select.js', 'src/dbp-person-select-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') {
return;
}
warn(warning);
},
plugins: [
del({
targets: 'dist/*'
}),
consts({
environment: build,
}),
resolve(),
commonjs(),
url({
limit: 0,
include: [
await getPackagePath('select2', '**/*.css'),
],
emitFiles: true,
fileName: 'shared/[name].[hash][extname]'
}),
json(),
(build !== 'local' && build !== 'test') ? terser() : false,
copy({
targets: [
{src: 'assets/index.html', dest: 'dist'},
{src: await getPackagePath('dbp-common', 'assets/icons/*.svg'), dest: 'dist/local/dbp-common/icons'},
],
}),
(process.env.ROLLUP_WATCH === 'true') ? serve({contentBase: 'dist', host: '127.0.0.1', port: 8002}) : false
]
};
})();