Update rollup.config.js

pull/4087/head
mertsincan 2023-06-26 13:11:04 +01:00
parent a34e9e285b
commit 30fb6416d2
1 changed files with 87 additions and 48 deletions

View File

@ -9,7 +9,7 @@ let entries = [];
let core = {}; let core = {};
let coreIconDependencies = { const CORE_ICON_DEPENDENCIES = {
'primevue/baseicon': 'primevue.baseicon', 'primevue/baseicon': 'primevue.baseicon',
'primevue/icons/angledoubledown': 'primevue.icons.angledoubledown', 'primevue/icons/angledoubledown': 'primevue.icons.angledoubledown',
'primevue/icons/angledoubleleft': 'primevue.icons.angledoubleleft', 'primevue/icons/angledoubleleft': 'primevue.icons.angledoubleleft',
@ -58,7 +58,7 @@ let coreIconDependencies = {
'primevue/icons/windowminimize': 'primevue.icons.windowminimize' 'primevue/icons/windowminimize': 'primevue.icons.windowminimize'
}; };
let coreDependencies = { const CORE_DEPENDENCIES = {
'primevue/utils': 'primevue.utils', 'primevue/utils': 'primevue.utils',
'primevue/api': 'primevue.api', 'primevue/api': 'primevue.api',
'primevue/config': 'primevue.config', 'primevue/config': 'primevue.config',
@ -66,7 +66,7 @@ let coreDependencies = {
'primevue/ripple': 'primevue.ripple', 'primevue/ripple': 'primevue.ripple',
'primevue/portal': 'primevue.portal', 'primevue/portal': 'primevue.portal',
'primevue/basecomponent': 'primevue.basecomponent', 'primevue/basecomponent': 'primevue.basecomponent',
...coreIconDependencies, ...CORE_ICON_DEPENDENCIES,
'primevue/tooltip': 'primevue.tooltip', 'primevue/tooltip': 'primevue.tooltip',
'primevue/focustrap': 'primevue.focustrap', 'primevue/focustrap': 'primevue.focustrap',
'primevue/virtualscroller': 'primevue.virtualscroller', 'primevue/virtualscroller': 'primevue.virtualscroller',
@ -93,55 +93,94 @@ let coreDependencies = {
'primevue/badge': 'primevue.badge' 'primevue/badge': 'primevue.badge'
}; };
let globalDependencies = { // dependencies
vue: 'Vue', const GLOBAL_DEPENDENCIES = {
...coreDependencies vue: 'Vue'
}; };
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)];
function addEntry(folder, inFile, outFile) { function addEntry(folder, inFile, outFile) {
let useCorePlugin = Object.keys(coreDependencies).some((d) => d.replace('primevue/', '') === folder); 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;
entries.push({ const input = `components/lib/${folder}/${inFile}`;
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: [ output: [
{ {
format: 'cjs', format: 'cjs',
file: 'dist/' + folder + '/' + outFile + '.cjs.js' file: `${output}.cjs${isMinify ? '.min' : ''}.js`,
exports
}, },
{ {
format: 'esm', format: 'esm',
file: 'dist/' + folder + '/' + outFile + '.esm.js' file: `${output}.esm${isMinify ? '.min' : ''}.js`,
}, exports
{
format: 'iife',
name: 'primevue.' + folder.replaceAll('/', '.'),
file: 'dist/' + folder + '/' + outFile + '.js',
globals: globalDependencies
} }
], ]
plugins: [vue(), postcss(), useCorePlugin && corePlugin()] };
}); };
entries.push({ const get_IIFE = (isMinify) => {
input: 'components/lib/' + folder + '/' + inFile, return {
...getEntry(isMinify),
output: [ output: [
{
format: 'cjs',
file: 'dist/' + folder + '/' + outFile + '.cjs.min.js'
},
{
format: 'esm',
file: 'dist/' + folder + '/' + outFile + '.esm.min.js'
},
{ {
format: 'iife', format: 'iife',
name: 'primevue.' + folder.replaceAll('/', '.'), name: 'primevue.' + folder.replaceAll('/', '.'),
file: 'dist/' + folder + '/' + outFile + '.min.js', file: `${output}${isMinify ? '.min' : ''}.js`,
globals: globalDependencies globals: GLOBAL_COMPONENT_DEPENDENCIES,
exports
} }
], ]
plugins: [vue(), postcss(), terser(), useCorePlugin && corePlugin()] };
}); };
entries.push(get_CJS_ESM());
entries.push(get_IIFE());
// Minify
entries.push(get_CJS_ESM(true));
entries.push(get_IIFE(true));
} }
function corePlugin() { function corePlugin() {
@ -172,7 +211,7 @@ function addCore() {
name: 'coreMergePlugin', name: 'coreMergePlugin',
generateBundle() { generateBundle() {
Object.entries(core).forEach(([filePath, value]) => { Object.entries(core).forEach(([filePath, value]) => {
const code = Object.keys(coreDependencies).reduce((val, d) => { const code = Object.keys(CORE_DEPENDENCIES).reduce((val, d) => {
const name = d.replace('primevue/', ''); const name = d.replace('primevue/', '');
val += value[name] + '\n'; val += value[name] + '\n';