From 30fb6416d22937c8cf878f0a34cbd7eb1ac4c1d5 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Mon, 26 Jun 2023 13:11:04 +0100 Subject: [PATCH] Update rollup.config.js --- rollup.config.js | 135 ++++++++++++++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 48 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 8fd85d412..bd5cc5410 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,7 +9,7 @@ let entries = []; let core = {}; -let coreIconDependencies = { +const CORE_ICON_DEPENDENCIES = { 'primevue/baseicon': 'primevue.baseicon', 'primevue/icons/angledoubledown': 'primevue.icons.angledoubledown', 'primevue/icons/angledoubleleft': 'primevue.icons.angledoubleleft', @@ -58,7 +58,7 @@ let coreIconDependencies = { 'primevue/icons/windowminimize': 'primevue.icons.windowminimize' }; -let coreDependencies = { +const CORE_DEPENDENCIES = { 'primevue/utils': 'primevue.utils', 'primevue/api': 'primevue.api', 'primevue/config': 'primevue.config', @@ -66,7 +66,7 @@ let coreDependencies = { 'primevue/ripple': 'primevue.ripple', 'primevue/portal': 'primevue.portal', 'primevue/basecomponent': 'primevue.basecomponent', - ...coreIconDependencies, + ...CORE_ICON_DEPENDENCIES, 'primevue/tooltip': 'primevue.tooltip', 'primevue/focustrap': 'primevue.focustrap', 'primevue/virtualscroller': 'primevue.virtualscroller', @@ -93,55 +93,94 @@ let coreDependencies = { 'primevue/badge': 'primevue.badge' }; -let globalDependencies = { - vue: 'Vue', - ...coreDependencies +// dependencies +const GLOBAL_DEPENDENCIES = { + 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) { - 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({ - input: 'components/lib/' + folder + '/' + inFile, - output: [ - { - format: 'cjs', - file: 'dist/' + folder + '/' + outFile + '.cjs.js' - }, - { - format: 'esm', - file: 'dist/' + folder + '/' + outFile + '.esm.js' - }, - { - format: 'iife', - name: 'primevue.' + folder.replaceAll('/', '.'), - file: 'dist/' + folder + '/' + outFile + '.js', - globals: globalDependencies - } - ], - plugins: [vue(), postcss(), useCorePlugin && corePlugin()] - }); + const input = `components/lib/${folder}/${inFile}`; + const output = `dist/${folder}/${outFile}`; - entries.push({ - input: 'components/lib/' + folder + '/' + inFile, - output: [ - { - format: 'cjs', - file: 'dist/' + folder + '/' + outFile + '.cjs.min.js' - }, - { - format: 'esm', - file: 'dist/' + folder + '/' + outFile + '.esm.min.js' - }, - { - format: 'iife', - name: 'primevue.' + folder.replaceAll('/', '.'), - file: 'dist/' + folder + '/' + outFile + '.min.js', - globals: globalDependencies - } - ], - plugins: [vue(), postcss(), terser(), useCorePlugin && corePlugin()] - }); + 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)); } function corePlugin() { @@ -172,7 +211,7 @@ function addCore() { name: 'coreMergePlugin', generateBundle() { 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/', ''); val += value[name] + '\n';