2024-05-23 19:45:05 +00:00
import alias from '@rollup/plugin-alias' ;
2023-07-03 22:20:35 +00:00
import { babel } from '@rollup/plugin-babel' ;
2024-06-20 15:39:51 +00:00
import terser from '@rollup/plugin-terser' ;
2022-09-10 14:15:16 +00:00
import postcss from 'rollup-plugin-postcss' ;
import vue from 'rollup-plugin-vue' ;
2023-10-24 18:06:20 +00:00
import fs from 'fs-extra' ;
import path from 'path' ;
2024-05-23 19:45:05 +00:00
import viteConfig , { THEME _PRESETS } from './nuxt-vite.config.js' ;
2023-10-24 18:06:20 +00:00
import pkg from './package.json' ;
2022-09-10 14:15:16 +00:00
2024-05-23 19:45:05 +00:00
// globals
const GLOBALS = {
2023-06-26 12:11:04 +00:00
vue : 'Vue'
2022-09-10 14:15:16 +00:00
} ;
2023-06-26 12:11:04 +00:00
// externals
2024-05-23 19:45:05 +00:00
const GLOBAL _EXTERNALS = [ 'vue' , 'chart.js/auto' , 'quill' ] ;
const INLINE _EXTERNALS = Object . keys ( viteConfig . resolve . alias ) ;
const EXTERNALS = [ ... GLOBAL _EXTERNALS , ... INLINE _EXTERNALS ] ;
2023-06-26 12:11:04 +00:00
2024-05-23 19:45:05 +00:00
// alias
const ALIAS _ENTRIES = Object . entries ( viteConfig . resolve . alias ) . map ( ( [ key , value ] ) => ( { find : key , replacement : value } ) ) ;
2023-06-26 12:11:04 +00:00
// plugins
2023-07-03 22:20:35 +00:00
const BABEL _PLUGIN _OPTIONS = {
extensions : [ '.js' , '.vue' ] ,
exclude : 'node_modules/**' ,
presets : [ '@babel/preset-env' ] ,
plugins : [ ] ,
skipPreflightCheck : true ,
babelHelpers : 'runtime' ,
babelrc : false
} ;
2024-05-23 22:11:48 +00:00
const ALIAS _PLUGIN _OPTIONS = {
entries : ALIAS _ENTRIES
} ;
2023-06-26 12:11:04 +00:00
const POSTCSS _PLUGIN _OPTIONS = {
sourceMap : false
} ;
const TERSER _PLUGIN _OPTIONS = {
compress : {
keep _infinity : true ,
pure _getters : true ,
2024-05-03 08:08:52 +00:00
reduce _funcs : true
} ,
mangle : {
reserved : [ 'theme' , 'css' ]
2023-06-26 12:11:04 +00:00
}
} ;
2023-07-03 22:20:35 +00:00
const PLUGINS = [ vue ( ) , postcss ( POSTCSS _PLUGIN _OPTIONS ) , babel ( BABEL _PLUGIN _OPTIONS ) ] ;
2023-06-26 12:11:04 +00:00
2024-05-23 19:45:05 +00:00
const ENTRY = {
entries : [ ] ,
onwarn ( warning ) {
if ( warning . code === 'CIRCULAR_DEPENDENCY' ) {
//console.error(`(!) ${warning.message}`);
return ;
}
} ,
format : {
cjs _es ( options ) {
return ENTRY . format . cjs ( options ) . es ( options ) ;
} ,
cjs ( { input , output , minify } ) {
ENTRY . entries . push ( {
onwarn : ENTRY . onwarn ,
input ,
plugins : [ ... PLUGINS , minify && terser ( TERSER _PLUGIN _OPTIONS ) ] ,
external : EXTERNALS ,
inlineDynamicImports : true ,
output : [
{
format : 'cjs' ,
file : ` ${ output } ${ minify ? '.min' : '' } .cjs ` ,
sourcemap : true ,
exports : 'auto'
}
]
} ) ;
2023-04-01 01:15:53 +00:00
2024-05-23 19:45:05 +00:00
return ENTRY . format ;
} ,
es ( { input , output , minify } ) {
ENTRY . entries . push ( {
onwarn : ENTRY . onwarn ,
input ,
plugins : [ ... PLUGINS , minify && terser ( TERSER _PLUGIN _OPTIONS ) ] ,
external : EXTERNALS ,
inlineDynamicImports : true ,
output : [
{
format : 'es' ,
file : ` ${ output } ${ minify ? '.min' : '' } .mjs ` ,
sourcemap : true ,
exports : 'auto'
}
]
} ) ;
2022-09-10 14:15:16 +00:00
2024-05-23 19:45:05 +00:00
return ENTRY . format ;
} ,
umd ( { name , input , output , minify } ) {
ENTRY . entries . push ( {
onwarn : ENTRY . onwarn ,
input ,
2024-05-23 22:11:48 +00:00
plugins : [ alias ( ALIAS _PLUGIN _OPTIONS ) , ... PLUGINS , minify && terser ( TERSER _PLUGIN _OPTIONS ) ] ,
2024-05-23 19:45:05 +00:00
external : GLOBAL _EXTERNALS ,
inlineDynamicImports : true ,
output : [
{
format : 'umd' ,
name : name ? ? 'PrimeVue' ,
file : ` ${ output } ${ minify ? '.min' : '' } .js ` ,
globals : GLOBALS ,
exports : 'auto'
}
]
} ) ;
2022-09-10 14:15:16 +00:00
2024-05-23 19:45:05 +00:00
return ENTRY . format ;
2022-09-10 14:15:16 +00:00
}
2024-05-23 19:45:05 +00:00
}
} ;
2022-09-10 14:15:16 +00:00
2024-05-23 19:45:05 +00:00
function addFile ( ) {
fs . readdirSync ( path . resolve ( _ _dirname , process . env . INPUT _DIR ) , { withFileTypes : true } )
2022-09-10 14:15:16 +00:00
. filter ( ( dir ) => dir . isDirectory ( ) )
. forEach ( ( { name : folderName } ) => {
2024-05-23 19:45:05 +00:00
fs . readdirSync ( path . resolve ( _ _dirname , process . env . INPUT _DIR + 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
2024-05-23 19:45:05 +00:00
if ( name === folderName ) {
const input = process . env . INPUT _DIR + folderName + '/' + file ;
const output = process . env . OUTPUT _DIR + folderName + '/' + name ;
2024-05-24 14:00:32 +00:00
ENTRY . format . es ( { input , output } ) ;
2022-09-10 14:15:16 +00:00
}
} ) ;
} ) ;
}
2023-04-01 01:15:53 +00:00
function addIcon ( ) {
2024-05-23 19:45:05 +00:00
const iconDir = path . resolve ( _ _dirname , process . env . INPUT _DIR + 'icons' ) ;
fs . readdirSync ( path . resolve ( _ _dirname , iconDir ) , { withFileTypes : true } )
2023-04-01 01:15:53 +00:00
. filter ( ( dir ) => dir . isDirectory ( ) )
. forEach ( ( { name : folderName } ) => {
2024-05-23 19:45:05 +00:00
fs . readdirSync ( path . resolve ( _ _dirname , iconDir + '/' + folderName ) ) . forEach ( ( file ) => {
2023-04-01 01:15:53 +00:00
if ( /\.vue$/ . test ( file ) ) {
2024-05-23 19:45:05 +00:00
const name = file . split ( /(.vue)$/ ) [ 0 ] . toLowerCase ( ) ;
const input = process . env . INPUT _DIR + 'icons/' + folderName + '/' + file ;
const output = process . env . OUTPUT _DIR + 'icons/' + folderName + '/' + name ;
2024-05-24 14:00:32 +00:00
ENTRY . format . es ( { input , output } ) ;
2023-04-01 01:15:53 +00:00
}
} ) ;
} ) ;
}
2023-10-02 10:46:09 +00:00
function addStyle ( ) {
2024-05-23 19:45:05 +00:00
fs . readdirSync ( path . resolve ( _ _dirname , process . env . INPUT _DIR ) , { withFileTypes : true } )
2023-10-02 10:46:09 +00:00
. filter ( ( dir ) => dir . isDirectory ( ) )
. forEach ( ( { name : folderName } ) => {
try {
2024-05-23 19:45:05 +00:00
fs . readdirSync ( path . resolve ( _ _dirname , process . env . INPUT _DIR + folderName + '/style' ) ) . forEach ( ( file ) => {
2023-10-02 10:46:09 +00:00
if ( /\.js$/ . test ( file ) ) {
2024-05-23 19:45:05 +00:00
const name = file . split ( /(.js)$/ ) [ 0 ] . toLowerCase ( ) ;
const input = process . env . INPUT _DIR + folderName + '/style/' + file ;
const output = process . env . OUTPUT _DIR + folderName + '/style/' + name ;
2023-10-02 10:46:09 +00:00
2024-05-24 14:00:32 +00:00
ENTRY . format . es ( { input , output } ) ;
2023-10-02 10:46:09 +00:00
}
} ) ;
} catch { }
} ) ;
}
2024-03-27 13:13:15 +00:00
function traverseDir ( dir , condition , callback ) {
try {
const files = fs . readdirSync ( dir ) ;
files . forEach ( ( file ) => {
const filePath = path . join ( dir , file ) ;
const fileStat = fs . statSync ( filePath ) ;
if ( fileStat . isDirectory ( ) ) {
traverseDir ( filePath , condition , callback ) ;
} else if ( condition ? . ( file ) && fileStat . isFile ( ) ) {
callback ? . ( file , filePath , dir ) ;
}
} ) ;
} catch { }
}
function addThemes ( ) {
traverseDir (
2024-05-23 19:45:05 +00:00
path . resolve ( _ _dirname , process . env . INPUT _DIR + 'themes' ) ,
2024-03-27 13:13:15 +00:00
( file ) => file === 'index.js' ,
( file , filePath , folderPath ) => {
2024-05-23 19:45:05 +00:00
const searchFolder = '/' + process . env . INPUT _DIR ;
const folderName = folderPath . substring ( folderPath . indexOf ( searchFolder ) + searchFolder . length ) ;
const input = process . env . INPUT _DIR + folderName + '/' + file ;
const output = process . env . OUTPUT _DIR + folderName + '/' + 'index' ;
2024-03-27 13:13:15 +00:00
2024-05-24 14:00:32 +00:00
ENTRY . format . es ( { input , output } ) ;
2024-03-27 13:13:15 +00:00
}
) ;
}
2024-05-23 19:45:05 +00:00
function addCore ( ) {
2024-05-24 14:00:32 +00:00
ENTRY . format . es ( { input : process . env . INPUT _DIR + 'config/PrimeVue.js' , output : process . env . OUTPUT _DIR + 'config/config' } ) ;
ENTRY . format . es ( { input : process . env . INPUT _DIR + 'service/PrimeVueService.js' , output : process . env . OUTPUT _DIR + 'service/primevueservice' } ) ;
2022-09-10 14:15:16 +00:00
}
2023-08-05 01:36:07 +00:00
function addPassThrough ( ) {
2024-05-24 14:00:32 +00:00
ENTRY . format . es ( { input : process . env . INPUT _DIR + 'passthrough/index.js' , output : process . env . OUTPUT _DIR + 'passthrough/index' } ) ;
2023-07-25 11:53:01 +00:00
}
2024-05-23 19:45:05 +00:00
function addLibrary ( ) {
THEME _PRESETS ? . forEach ( ( preset ) => {
ENTRY . format . umd ( { name : ` PrimeVue.Themes. ${ preset [ 0 ] . toUpperCase ( ) + preset . slice ( 1 ) } ` , input : process . env . INPUT _DIR + ` themes/ ${ preset } /index.js ` , output : process . env . OUTPUT _DIR + ` umd/themes/ ${ preset } ` , minify : true } ) ;
} ) ;
2022-09-10 14:15:16 +00:00
2024-05-23 19:45:05 +00:00
ENTRY . format . umd ( { name : 'PrimeVue' , input : process . env . INPUT _DIR + 'primevue.js' , output : process . env . OUTPUT _DIR + 'umd/primevue' , minify : true } ) ;
2022-09-10 14:15:16 +00:00
}
2023-10-24 18:06:20 +00:00
function addPackageJson ( ) {
2024-05-23 19:45:05 +00:00
const outputDir = path . resolve ( _ _dirname , process . env . OUTPUT _DIR ) ;
2023-10-24 18:06:20 +00:00
const packageJson = ` {
"name" : "primevue" ,
"version" : "${pkg.version}" ,
2024-06-12 02:11:56 +00:00
"private" : "false" ,
2023-10-24 18:06:20 +00:00
"author" : "PrimeTek Informatics" ,
"description" : "PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, which has 370+ ready to use UI blocks to build spectacular applications in no time." ,
"homepage" : "https://primevue.org/" ,
"repository" : {
"type" : "git" ,
"url" : "https://github.com/primefaces/primevue.git"
} ,
"license" : "MIT" ,
"bugs" : {
"url" : "https://github.com/primefaces/primevue/issues"
} ,
"keywords" : [
"primevue" ,
"vue" ,
"vue.js" ,
"vue2" ,
"vue3" ,
"ui library" ,
"component library" ,
"material" ,
"bootstrap" ,
"fluent" ,
"tailwind" ,
"unstyled" ,
"passthrough"
] ,
2024-05-23 19:45:05 +00:00
"unpkg" : "umd/primevue.min.js" ,
"jsdelivr" : "umd/primevue.min.js" ,
2023-10-24 18:06:20 +00:00
"web-types" : "./web-types.json" ,
"vetur" : {
"tags" : "./vetur-tags.json" ,
"attributes" : "./vetur-attributes.json"
} ,
2024-05-01 08:33:20 +00:00
"sideEffects" : [
"*.vue"
] ,
2023-10-24 18:06:20 +00:00
"peerDependencies" : {
"vue" : "^3.0.0"
2024-05-23 19:45:05 +00:00
} ,
"engines" : {
"node" : ">=12.11.0"
2023-10-24 18:06:20 +00:00
}
} ` ;
! fs . existsSync ( outputDir ) && fs . mkdirSync ( outputDir ) ;
fs . writeFileSync ( path . resolve ( outputDir , 'package.json' ) , packageJson ) ;
}
2024-05-23 19:45:05 +00:00
addCore ( ) ;
2023-10-02 10:46:09 +00:00
addStyle ( ) ;
2024-03-27 13:13:15 +00:00
addThemes ( ) ;
2023-04-01 01:15:53 +00:00
addIcon ( ) ;
2024-05-23 19:45:05 +00:00
addFile ( ) ;
2023-08-05 01:36:07 +00:00
addPassThrough ( ) ;
2024-05-23 19:45:05 +00:00
addLibrary ( ) ;
2023-10-24 18:06:20 +00:00
addPackageJson ( ) ;
2022-09-10 14:15:16 +00:00
2024-05-23 19:45:05 +00:00
export default ENTRY . entries ;