primevue-mirror/apps/showcase/rollup.config.js

297 lines
9.6 KiB
JavaScript
Raw Normal View History

2024-05-23 19:45:05 +00:00
import alias from '@rollup/plugin-alias';
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
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
}
};
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
}
});
});
}
function addStyle() {
2024-05-23 19:45:05 +00:00
fs.readdirSync(path.resolve(__dirname, process.env.INPUT_DIR), { withFileTypes: true })
.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) => {
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;
2024-05-24 14:00:32 +00:00
ENTRY.format.es({ input, output });
}
});
} 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' });
}
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();
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;