primevue-mirror/rollup.config.js

305 lines
11 KiB
JavaScript
Raw Normal View History

2022-09-10 14:15:16 +00:00
import postcss from 'rollup-plugin-postcss';
import { terser } from 'rollup-plugin-terser';
import vue from 'rollup-plugin-vue';
const fs = require('fs-extra');
const path = require('path');
let entries = [];
let core = {};
2023-06-26 12:11:04 +00:00
const CORE_ICON_DEPENDENCIES = {
2023-04-01 01:15:53 +00:00
'primevue/baseicon': 'primevue.baseicon',
'primevue/icons/angledoubledown': 'primevue.icons.angledoubledown',
'primevue/icons/angledoubleleft': 'primevue.icons.angledoubleleft',
'primevue/icons/angledoubleright': 'primevue.icons.angledoubleright',
'primevue/icons/angledoubleup': 'primevue.icons.angledoubleup',
'primevue/icons/angledown': 'primevue.icons.angledown',
'primevue/icons/angleleft': 'primevue.icons.angleleft',
'primevue/icons/angleright': 'primevue.icons.angleright',
'primevue/icons/angleup': 'primevue.icons.angleup',
'primevue/icons/arrowdown': 'primevue.icons.arrowdown',
'primevue/icons/arrowup': 'primevue.icons.arrowup',
'primevue/icons/ban': 'primevue.icons.ban',
'primevue/icons/bars': 'primevue.icons.bars',
'primevue/icons/calendar': 'primevue.icons.calendar',
'primevue/icons/check': 'primevue.icons.check',
'primevue/icons/chevrondown': 'primevue.icons.chevrondown',
'primevue/icons/chevronleft': 'primevue.icons.chevronleft',
'primevue/icons/chevronright': 'primevue.icons.chevronright',
'primevue/icons/chevronup': 'primevue.icons.chevronup',
'primevue/icons/exclamationtriangle': 'primevue.icons.exclamationtriangle',
'primevue/icons/eye': 'primevue.icons.eye',
'primevue/icons/eyeslash': 'primevue.icons.eyeslash',
'primevue/icons/filter': 'primevue.icons.filter',
'primevue/icons/filterslash': 'primevue.icons.filterslash',
'primevue/icons/infocircle': 'primevue.icons.infocircle',
'primevue/icons/minus': 'primevue.icons.minus',
'primevue/icons/pencil': 'primevue.icons.pencil',
'primevue/icons/plus': 'primevue.icons.plus',
'primevue/icons/refresh': 'primevue.icons.refresh',
'primevue/icons/search': 'primevue.icons.search',
'primevue/icons/searchminus': 'primevue.icons.searchminus',
'primevue/icons/searchplus': 'primevue.icons.searchplus',
'primevue/icons/sortalt': 'primevue.icons.sortalt',
'primevue/icons/sortamountdown': 'primevue.icons.sortamountdown',
'primevue/icons/sortamountupalt': 'primevue.icons.sortamountupalt',
'primevue/icons/spinner': 'primevue.icons.spinner',
'primevue/icons/star': 'primevue.icons.star',
'primevue/icons/starfill': 'primevue.icons.starfill',
'primevue/icons/thlarge': 'primevue.icons.thlarge',
'primevue/icons/times': 'primevue.icons.times',
'primevue/icons/timescircle': 'primevue.icons.timescircle',
'primevue/icons/trash': 'primevue.icons.trash',
'primevue/icons/undo': 'primevue.icons.undo',
'primevue/icons/upload': 'primevue.icons.upload',
'primevue/icons/windowmaximize': 'primevue.icons.windowmaximize',
'primevue/icons/windowminimize': 'primevue.icons.windowminimize'
2023-04-01 01:15:53 +00:00
};
2023-06-26 12:11:04 +00:00
const CORE_DEPENDENCIES = {
2022-09-10 14:15:16 +00:00
'primevue/utils': 'primevue.utils',
'primevue/api': 'primevue.api',
'primevue/config': 'primevue.config',
2023-06-21 13:48:00 +00:00
'primevue/basedirective': 'primevue.basedirective',
2022-09-10 14:15:16 +00:00
'primevue/ripple': 'primevue.ripple',
'primevue/portal': 'primevue.portal',
2023-04-01 01:15:53 +00:00
'primevue/basecomponent': 'primevue.basecomponent',
2023-06-26 12:11:04 +00:00
...CORE_ICON_DEPENDENCIES,
2022-09-10 14:15:16 +00:00
'primevue/tooltip': 'primevue.tooltip',
2022-12-09 08:12:43 +00:00
'primevue/focustrap': 'primevue.focustrap',
2022-09-10 14:15:16 +00:00
'primevue/virtualscroller': 'primevue.virtualscroller',
'primevue/confirmationeventbus': 'primevue.confirmationeventbus',
'primevue/toasteventbus': 'primevue.toasteventbus',
'primevue/overlayeventbus': 'primevue.overlayeventbus',
'primevue/dynamicdialogeventbus': 'primevue.dynamicdialogeventbus',
'primevue/terminalservice': 'primevue.terminalservice',
'primevue/useconfirm': 'primevue.useconfirm',
'primevue/usetoast': 'primevue.usetoast',
'primevue/usedialog': 'primevue.usedialog',
'primevue/usestyle': 'primevue.usestyle',
2022-09-10 14:15:16 +00:00
'primevue/button': 'primevue.button',
'primevue/inputtext': 'primevue.inputtext',
'primevue/inputnumber': 'primevue.inputnumber',
'primevue/message': 'primevue.message',
'primevue/progressbar': 'primevue.progressbar',
'primevue/dropdown': 'primevue.dropdown',
'primevue/dialog': 'primevue.dialog',
'primevue/paginator': 'primevue.paginator',
'primevue/tree': 'primevue.tree',
'primevue/menu': 'primevue.menu',
2022-12-09 08:12:43 +00:00
'primevue/tieredmenu': 'primevue.tieredmenu',
'primevue/badge': 'primevue.badge'
2022-09-10 14:15:16 +00:00
};
2023-06-26 12:11:04 +00:00
// dependencies
const GLOBAL_DEPENDENCIES = {
vue: 'Vue'
2022-09-10 14:15:16 +00:00
};
2023-06-26 12:11:04 +00:00
const GLOBAL_COMPONENT_DEPENDENCIES = {
...GLOBAL_DEPENDENCIES,
...CORE_DEPENDENCIES
};
// externals
const EXTERNAL = ['vue', 'chart.js/auto', 'quill'];
const EXTERNAL_COMPONENT = [...EXTERNAL, ...Object.keys(CORE_DEPENDENCIES)];
// plugins
const POSTCSS_PLUGIN_OPTIONS = {
sourceMap: false
};
const TERSER_PLUGIN_OPTIONS = {
compress: {
keep_infinity: true,
pure_getters: true,
reduce_funcs: false
}
};
const PLUGINS = [vue(), postcss(POSTCSS_PLUGIN_OPTIONS)];
2022-09-10 14:15:16 +00:00
function addEntry(folder, inFile, outFile) {
2023-06-26 12:11:04 +00:00
const exports = inFile === 'PrimeVue.js' ? 'named' : 'auto';
const useCorePlugin = Object.keys(GLOBAL_COMPONENT_DEPENDENCIES).some((d) => d.replace('primevue/', '') === folder);
const plugins = PLUGINS;
const external = EXTERNAL_COMPONENT;
const inlineDynamicImports = true;
const input = `components/lib/${folder}/${inFile}`;
const output = `dist/${folder}/${outFile}`;
const getEntry = (isMinify) => {
return {
input,
plugins: [...plugins, isMinify && terser(TERSER_PLUGIN_OPTIONS), useCorePlugin && corePlugin()],
external,
inlineDynamicImports
};
};
const get_CJS_ESM = (isMinify) => {
return {
...getEntry(isMinify),
output: [
{
format: 'cjs',
file: `${output}.cjs${isMinify ? '.min' : ''}.js`,
exports
},
{
format: 'esm',
file: `${output}.esm${isMinify ? '.min' : ''}.js`,
exports
}
]
};
};
const get_IIFE = (isMinify) => {
return {
...getEntry(isMinify),
output: [
{
format: 'iife',
name: 'primevue.' + folder.replaceAll('/', '.'),
file: `${output}${isMinify ? '.min' : ''}.js`,
globals: GLOBAL_COMPONENT_DEPENDENCIES,
exports
}
]
};
};
entries.push(get_CJS_ESM());
entries.push(get_IIFE());
// Minify
entries.push(get_CJS_ESM(true));
entries.push(get_IIFE(true));
2022-09-10 14:15:16 +00:00
}
function corePlugin() {
return {
name: 'corePlugin',
generateBundle(outputOptions, bundle) {
2023-04-01 01:15:53 +00:00
const { name, format } = outputOptions;
if (format === 'iife') {
2022-09-10 14:15:16 +00:00
Object.keys(bundle).forEach((id) => {
const chunk = bundle[id];
2023-04-01 01:15:53 +00:00
const folderName = name.replace('primevue.', '').replaceAll('.', '/');
2022-09-10 14:15:16 +00:00
const filePath = `./dist/core/core${id.indexOf('.min.js') > 0 ? '.min.js' : '.js'}`;
2023-04-01 01:15:53 +00:00
core[filePath] ? (core[filePath][folderName] = chunk.code) : (core[filePath] = { [`${folderName}`]: chunk.code });
2022-09-10 14:15:16 +00:00
});
}
}
};
}
function addCore() {
const lastEntry = entries[entries.length - 1];
lastEntry.plugins = [
...lastEntry.plugins,
{
name: 'coreMergePlugin',
generateBundle() {
Object.entries(core).forEach(([filePath, value]) => {
2023-06-26 12:11:04 +00:00
const code = Object.keys(CORE_DEPENDENCIES).reduce((val, d) => {
2022-09-10 14:15:16 +00:00
const name = d.replace('primevue/', '');
2022-09-14 14:49:38 +00:00
2022-09-10 14:15:16 +00:00
val += value[name] + '\n';
return val;
}, '');
fs.outputFile(path.resolve(__dirname, filePath), code, {}, function (err) {
if (err) {
// eslint-disable-next-line no-console
return console.error(err);
}
});
});
}
}
];
}
function addSFC() {
fs.readdirSync(path.resolve(__dirname, './components/lib'), { withFileTypes: true })
2022-09-10 14:15:16 +00:00
.filter((dir) => dir.isDirectory())
.forEach(({ name: folderName }) => {
fs.readdirSync(path.resolve(__dirname, './components/lib/' + folderName)).forEach((file) => {
2022-09-10 14:15:16 +00:00
let name = file.split(/(.vue)$|(.js)$/)[0].toLowerCase();
2022-12-20 12:32:32 +00:00
2022-09-10 14:15:16 +00:00
if (/\.vue$/.test(file) && name === folderName) {
addEntry(folderName, file, name);
}
});
});
}
2023-04-01 01:15:53 +00:00
function addIcon() {
fs.readdirSync(path.resolve(__dirname, './components/lib/icons'), { withFileTypes: true })
2023-04-01 01:15:53 +00:00
.filter((dir) => dir.isDirectory())
.forEach(({ name: folderName }) => {
fs.readdirSync(path.resolve(__dirname, './components/lib/icons/' + folderName)).forEach((file) => {
2023-04-01 01:15:53 +00:00
if (/\.vue$/.test(file)) {
2023-04-19 07:23:17 +00:00
addEntry('icons/' + folderName, 'index.vue', 'index');
2023-04-01 01:15:53 +00:00
}
});
});
}
2022-09-10 14:15:16 +00:00
function addDirectives() {
addEntry('badgedirective', 'BadgeDirective.js', 'badgedirective');
addEntry('ripple', 'Ripple.js', 'ripple');
addEntry('tooltip', 'Tooltip.js', 'tooltip');
2022-12-09 08:12:43 +00:00
addEntry('focustrap', 'FocusTrap.js', 'focustrap');
2022-09-10 14:15:16 +00:00
addEntry('styleclass', 'StyleClass.js', 'styleclass');
}
function addConfig() {
addEntry('config', 'PrimeVue.js', 'config');
}
function addUtils() {
addEntry('utils', 'Utils.js', 'utils');
}
function addApi() {
addEntry('api', 'Api.js', 'api');
}
function addServices() {
addEntry('confirmationservice', 'ConfirmationService.js', 'confirmationservice');
addEntry('confirmationeventbus', 'ConfirmationEventBus.js', 'confirmationeventbus');
addEntry('useconfirm', 'UseConfirm.js', 'useconfirm');
addEntry('toastservice', 'ToastService.js', 'toastservice');
addEntry('toasteventbus', 'ToastEventBus.js', 'toasteventbus');
addEntry('overlayeventbus', 'OverlayEventBus.js', 'overlayeventbus');
addEntry('usetoast', 'UseToast.js', 'usetoast');
2023-05-30 10:19:48 +00:00
addEntry('usestyle', 'UseStyle.js', 'usestyle');
2022-09-10 14:15:16 +00:00
addEntry('terminalservice', 'TerminalService.js', 'terminalservice');
addEntry('usedialog', 'UseDialog.js', 'usedialog');
addEntry('dialogservice', 'DialogService.js', 'dialogservice');
addEntry('dynamicdialogeventbus', 'DynamicDialogEventBus.js', 'dynamicdialogeventbus');
}
addUtils();
addApi();
addConfig();
addDirectives();
addServices();
addSFC();
2023-04-01 01:15:53 +00:00
addIcon();
2022-09-10 14:15:16 +00:00
addCore();
export default entries;