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-11 12:21:12 +00:00
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
2022-09-10 14:15:16 +00:00
|
|
|
import postcss from 'rollup-plugin-postcss';
|
|
|
|
import { terser } from 'rollup-plugin-terser';
|
|
|
|
import vue from 'rollup-plugin-vue';
|
|
|
|
|
2023-10-24 18:06:20 +00:00
|
|
|
import fs from 'fs-extra';
|
2024-06-11 12:21:12 +00:00
|
|
|
import path, { dirname } from 'path';
|
|
|
|
import { fileURLToPath } from 'url';
|
2023-10-24 18:06:20 +00:00
|
|
|
|
2024-06-11 12:21:12 +00:00
|
|
|
// @todo - Remove
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
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'];
|
2024-06-11 12:21:12 +00:00
|
|
|
const INLINE_EXTERNALS = [/@primevue\/core\/.*/, /@primevue\/icons\/.*/];
|
2024-05-23 19:45:05 +00:00
|
|
|
const EXTERNALS = [...GLOBAL_EXTERNALS, ...INLINE_EXTERNALS];
|
2023-06-26 12:11:04 +00:00
|
|
|
|
2024-05-23 19:45:05 +00:00
|
|
|
// alias
|
2024-06-11 12:21:12 +00:00
|
|
|
const ALIAS_ENTRIES = [
|
|
|
|
{
|
|
|
|
find: /^primevue\/(.*)$/,
|
|
|
|
replacement: path.resolve(__dirname, './src/$1'),
|
|
|
|
customResolver(source, importer) {
|
|
|
|
const basedir = path.dirname(importer);
|
|
|
|
const folderPath = path.resolve(basedir, source);
|
|
|
|
const folderName = path.basename(folderPath);
|
|
|
|
|
|
|
|
const fName = folderName === 'style' ? `${path.basename(path.dirname(folderPath))}Style` : folderName;
|
|
|
|
const files = fs.readdirSync(folderPath);
|
|
|
|
const targetFile = files.find((file) => {
|
|
|
|
const ext = path.extname(file);
|
|
|
|
return ['.vue', '.js'].includes(ext) && path.basename(file, ext).toLowerCase() === fName.toLowerCase();
|
|
|
|
});
|
|
|
|
|
|
|
|
return targetFile ? path.join(folderPath, targetFile) : null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// @todo - Remove
|
|
|
|
{ find: '@primevue/core/api', replacement: path.resolve(__dirname, '../core/src/api/Api.js') },
|
|
|
|
{ find: '@primevue/core/base/style', replacement: path.resolve(__dirname, '../core/src/base/style/BaseStyle.js') },
|
|
|
|
{ find: '@primevue/core/base', replacement: path.resolve(__dirname, '../core/src/base/Base.js') },
|
|
|
|
{ find: '@primevue/core/basecomponent/style', replacement: path.resolve(__dirname, '../core/src/basecomponent/style/BaseComponentStyle.js') },
|
|
|
|
{ find: '@primevue/core/basecomponent', replacement: path.resolve(__dirname, '../core/src/basecomponent/BaseComponent.vue') },
|
|
|
|
{ find: '@primevue/core/basedirective', replacement: path.resolve(__dirname, '../core/src/basedirective/BaseDirective.js') },
|
|
|
|
{ find: '@primevue/core/config', replacement: path.resolve(__dirname, '../core/src/config/PrimeVue.js') },
|
|
|
|
{ find: '@primevue/core/service', replacement: path.resolve(__dirname, '../core/src/service/PrimeVueService.js') },
|
|
|
|
{ find: '@primevue/core/usestyle', replacement: path.resolve(__dirname, '../core/src/usestyle/UseStyle.js') },
|
|
|
|
{ find: '@primevue/core/utils', replacement: path.resolve(__dirname, '../core/src/utils/Utils.js') },
|
2024-06-12 13:37:30 +00:00
|
|
|
{ find: '@primevue/core', replacement: path.resolve(__dirname, '../core/src/index.js') },
|
2024-06-11 12:21:12 +00:00
|
|
|
{ find: '@primevue/icons/baseicon/style', replacement: path.resolve(__dirname, '../icons/src/baseicon/style/BaseIconStyle.js') },
|
|
|
|
{ find: '@primevue/icons/baseicon', replacement: path.resolve(__dirname, '../icons/src/baseicon/BaseIcon.vue') },
|
|
|
|
{ find: '@primevue/themes', replacement: path.resolve(__dirname, '../themes/src/index.js') }
|
|
|
|
];
|
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-06-11 12:21:12 +00:00
|
|
|
ENTRY.update.packageJson({ input, output, options: { main: `${output}.cjs` } });
|
|
|
|
|
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-06-11 12:21:12 +00:00
|
|
|
ENTRY.update.packageJson({ input, output, options: { main: `${output}.mjs`, module: `${output}.mjs` } });
|
|
|
|
|
2024-05-23 19:45:05 +00:00
|
|
|
return ENTRY.format;
|
|
|
|
},
|
|
|
|
umd({ name, input, output, minify }) {
|
|
|
|
ENTRY.entries.push({
|
|
|
|
onwarn: ENTRY.onwarn,
|
|
|
|
input,
|
2024-06-11 12:21:12 +00:00
|
|
|
plugins: [alias(ALIAS_PLUGIN_OPTIONS), resolve(), ...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-06-11 12:21:12 +00:00
|
|
|
},
|
|
|
|
update: {
|
|
|
|
packageJson({ input, output, options }) {
|
|
|
|
try {
|
|
|
|
const inputDir = path.resolve(__dirname, path.dirname(input));
|
|
|
|
const outputDir = path.resolve(__dirname, path.dirname(output));
|
|
|
|
const packageJson = path.resolve(outputDir, 'package.json');
|
|
|
|
|
|
|
|
!fs.existsSync(packageJson) && fs.copySync(path.resolve(inputDir, './package.json'), packageJson);
|
|
|
|
|
|
|
|
const pkg = JSON.parse(fs.readFileSync(packageJson, { encoding: 'utf8', flag: 'r' }));
|
|
|
|
|
|
|
|
!pkg?.main?.includes('.cjs') && (pkg.main = path.basename(options?.main) ? `./${path.basename(options.main)}` : pkg.main);
|
|
|
|
pkg.module = path.basename(options?.module) ? `./${path.basename(options.module)}` : packageJson.module;
|
|
|
|
pkg.types && (pkg.types = './index.d.ts');
|
|
|
|
|
|
|
|
fs.writeFileSync(packageJson, JSON.stringify(pkg, null, 4));
|
|
|
|
} catch {}
|
|
|
|
}
|
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;
|
2024-06-11 12:21:12 +00:00
|
|
|
const output = process.env.OUTPUT_DIR + folderName + '/index';
|
2024-05-23 19:45:05 +00:00
|
|
|
|
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;
|
2024-06-11 12:21:12 +00:00
|
|
|
const output = process.env.OUTPUT_DIR + folderName + '/style/index';
|
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 {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-05-23 19:45:05 +00:00
|
|
|
addFile();
|
2024-06-11 12:21:12 +00:00
|
|
|
addStyle();
|
2023-08-05 01:36:07 +00:00
|
|
|
addPassThrough();
|
2024-05-23 19:45:05 +00:00
|
|
|
addLibrary();
|
2022-09-10 14:15:16 +00:00
|
|
|
|
2024-05-23 19:45:05 +00:00
|
|
|
export default ENTRY.entries;
|