primevue-mirror/rollup.config.js

192 lines
5.9 KiB
JavaScript
Raw Normal View History

2021-01-18 08:25:54 +00:00
import vue from 'rollup-plugin-vue';
import postcss from 'rollup-plugin-postcss';
2021-01-18 12:21:54 +00:00
import { terser } from 'rollup-plugin-terser';
2021-01-18 08:25:54 +00:00
const fs = require('fs-extra');
const path = require('path');
let entries = [];
2021-10-05 10:08:36 +00:00
let core = {};
2021-10-04 20:24:12 +00:00
let coreDependencies = {
2021-01-18 14:35:36 +00:00
'primevue/utils': 'primevue.utils',
2021-10-05 10:08:36 +00:00
'primevue/api': 'primevue.api',
'primevue/config': 'primevue.config',
2021-10-04 20:24:12 +00:00
'primevue/ripple': 'primevue.ripple',
2021-10-05 10:08:36 +00:00
'primevue/virtualscroller': 'primevue.virtualscroller',
2021-01-18 14:35:36 +00:00
'primevue/confirmationeventbus': 'primevue.confirmationeventbus',
'primevue/toasteventbus': 'primevue.toasteventbus',
2021-03-03 10:30:19 +00:00
'primevue/overlayeventbus': 'primevue.overlayeventbus',
2021-10-04 20:24:12 +00:00
'primevue/terminalservice': 'primevue.terminalservice',
2021-01-18 14:35:36 +00:00
'primevue/useconfirm': 'primevue.useconfirm',
'primevue/usetoast': 'primevue.usetoast',
2021-10-04 20:24:12 +00:00
'primevue/button': 'primevue.button',
'primevue/inputtext': 'primevue.inputtext',
2021-10-05 10:08:36 +00:00
'primevue/inputnumber': 'primevue.inputnumber',
2021-01-18 14:35:36 +00:00
'primevue/message': 'primevue.message',
2021-10-05 10:08:36 +00:00
'primevue/progressbar': 'primevue.progressbar',
2021-01-18 14:35:36 +00:00
'primevue/dropdown': 'primevue.dropdown',
2021-10-05 10:08:36 +00:00
'primevue/dialog': 'primevue.dialog',
'primevue/paginator': 'primevue.paginator',
2021-04-09 12:04:11 +00:00
'primevue/tree': 'primevue.tree',
2021-10-05 10:08:36 +00:00
'primevue/menu': 'primevue.menu',
'primevue/tieredmenu': 'primevue.tieredmenu'
2021-10-04 20:24:12 +00:00
}
let globalDependencies = {
'vue': 'Vue',
'@fullcalendar/core': 'FullCalendar',
...coreDependencies
2021-01-18 14:35:36 +00:00
}
function addEntry(folder, inFile, outFile) {
2021-10-04 20:24:12 +00:00
let useCorePlugin = Object.keys(coreDependencies).some(d => d.replace('primevue/', '') === outFile);
entries.push({
input: 'src/components/' + folder + '/' + inFile,
output: [
2021-01-18 12:21:54 +00:00
{
format: 'cjs',
file: 'dist/' + folder + '/' + outFile + '.cjs.js',
2021-01-18 12:21:54 +00:00
},
{
format: 'esm',
file: 'dist/' + folder + '/' + outFile + '.esm.js'
},
{
2021-01-18 12:21:54 +00:00
format: 'iife',
2021-01-18 14:35:36 +00:00
name: 'primevue.' + folder,
2021-01-18 13:41:06 +00:00
file: 'dist/' + folder + '/' + outFile + '.js',
2021-01-18 14:35:36 +00:00
globals: globalDependencies
2021-01-18 12:21:54 +00:00
}
],
plugins: [
vue(),
2021-10-04 20:24:12 +00:00
postcss(),
useCorePlugin && corePlugin()
2021-01-18 12:21:54 +00:00
]
});
entries.push({
2021-01-18 12:21:54 +00:00
input: 'src/components/' + folder + '/' + inFile,
output: [
{
format: 'cjs',
file: 'dist/' + folder + '/' + outFile + '.cjs.min.js'
2021-01-18 12:21:54 +00:00
},
{
format: 'esm',
file: 'dist/' + folder + '/' + outFile + '.esm.min.js'
},
{
format: 'iife',
2021-02-10 20:12:05 +00:00
name: 'primevue.' + folder,
file: 'dist/' + folder + '/' + outFile + '.min.js',
globals: globalDependencies
}
],
plugins: [
vue(),
2021-01-18 12:21:54 +00:00
postcss(),
2021-10-04 20:24:12 +00:00
terser(),
useCorePlugin && corePlugin()
]
});
}
2021-10-04 20:24:12 +00:00
function corePlugin() {
return {
name: 'corePlugin',
generateBundle(outputOptions, bundle) {
if (outputOptions.format === 'iife') {
Object.keys(bundle).forEach(id => {
const chunk = bundle[id];
2021-10-05 10:08:36 +00:00
const name = id.replace('.min.js', '').replace('.js', '');
2021-10-04 20:24:12 +00:00
const filePath = `./dist/core/core${id.indexOf('.min.js') > 0 ? '.min.js': '.js'}`;
2021-10-05 10:08:36 +00:00
core[filePath] ? (core[filePath][name] = chunk.code) : (core[filePath] = { [`${name}`]: chunk.code });
});
}
}
};
}
function addCore() {
const lastEntry = entries[entries.length - 1];
lastEntry.plugins = [
...lastEntry.plugins,
{
name: 'coreMergePlugin',
buildEnd() {
Object.entries(core).forEach(([filePath, value]) => {
const code = Object.keys(coreDependencies).reduce((val, d) => {
const name = d.replace('primevue/', '');
val += value[name] + '\n';
return val;
}, '');
fs.outputFile(path.resolve(__dirname, filePath), code, {}, function(err) {
2021-10-04 20:24:12 +00:00
if (err) {
return console.error(err);
}
});
});
}
}
2021-10-05 10:08:36 +00:00
]
2021-10-04 20:24:12 +00:00
}
function addSFC() {
fs.readdirSync(path.resolve(__dirname, './src/components/')).forEach(folder => {
fs.readdirSync(path.resolve(__dirname, './src/components/' + folder)).forEach(file => {
2021-01-18 08:25:54 +00:00
let name = file.split(/(.vue)$|(.js)$/)[0].toLowerCase();
if (/\.vue$/.test(file) && (name === folder)) {
addEntry(folder, file, name);
2021-01-18 08:25:54 +00:00
}
});
2021-01-18 08:25:54 +00:00
});
}
function addDirectives() {
addEntry('badgedirective', 'BadgeDirective.js', 'badgedirective');
addEntry('ripple', 'Ripple.js', 'ripple');
addEntry('tooltip', 'Tooltip.js', 'tooltip');
2021-08-04 10:01:32 +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');
2021-03-03 10:30:19 +00:00
addEntry('overlayeventbus', 'OverlayEventBus.js', 'overlayeventbus');
addEntry('usetoast', 'UseToast.js', 'usetoast');
2021-01-18 14:35:36 +00:00
addEntry('terminalservice', 'TerminalService.js', 'terminalservice');
}
addUtils();
addApi();
2021-10-04 20:24:12 +00:00
addConfig();
addDirectives();
addServices();
2021-10-04 20:24:12 +00:00
addSFC();
2021-10-05 10:08:36 +00:00
addCore();
2021-01-18 08:25:54 +00:00
2021-08-13 14:29:39 +00:00
export default entries;