2022-04-30 16:16:10 +00:00
|
|
|
import { readFileSync } from 'fs';
|
2022-04-29 20:19:22 +00:00
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
|
|
import { terser } from 'rollup-plugin-terser';
|
|
|
|
import replace from '@rollup/plugin-replace';
|
|
|
|
|
2022-04-30 16:16:10 +00:00
|
|
|
// Header
|
2022-04-29 20:19:22 +00:00
|
|
|
const header = `/**
|
|
|
|
* (c) Iconify
|
|
|
|
*
|
2022-04-30 16:16:10 +00:00
|
|
|
* For the full copyright and license information, please view the license.txt
|
2022-04-29 20:19:22 +00:00
|
|
|
* files at https://github.com/iconify/iconify
|
|
|
|
*
|
2022-04-30 16:16:10 +00:00
|
|
|
* Licensed under MIT.
|
2022-04-29 20:19:22 +00:00
|
|
|
*
|
2022-04-30 16:16:10 +00:00
|
|
|
* @license MIT
|
2022-04-29 20:19:22 +00:00
|
|
|
* @version __iconify_version__
|
|
|
|
*/`;
|
|
|
|
|
|
|
|
// Get replacements
|
|
|
|
const replacements = {
|
|
|
|
preventAssignment: true,
|
|
|
|
};
|
|
|
|
const packageJSON = JSON.parse(readFileSync('package.json', 'utf8'));
|
|
|
|
replacements['__iconify_version__'] = packageJSON.version;
|
|
|
|
|
|
|
|
// Export configuration
|
|
|
|
const config = [];
|
|
|
|
|
2022-04-30 16:16:10 +00:00
|
|
|
// Full and minified
|
|
|
|
[false, true].forEach((minify) => {
|
|
|
|
// Parse all formats
|
|
|
|
['js', 'cjs', 'mjs'].forEach((ext) => {
|
|
|
|
if (minify && ext !== 'js') {
|
|
|
|
// Minify only .js files
|
|
|
|
return;
|
|
|
|
}
|
2022-04-29 20:19:22 +00:00
|
|
|
|
2022-04-30 16:16:10 +00:00
|
|
|
// Get export format
|
|
|
|
let format = ext;
|
|
|
|
let input = 'lib/index.js';
|
|
|
|
let exportType = 'named';
|
|
|
|
switch (ext) {
|
|
|
|
case 'js':
|
|
|
|
format = 'iife';
|
|
|
|
exportType = void 0;
|
|
|
|
input = 'lib/script.js';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mjs':
|
|
|
|
format = 'es';
|
|
|
|
break;
|
|
|
|
}
|
2022-04-29 20:19:22 +00:00
|
|
|
|
2022-04-30 16:16:10 +00:00
|
|
|
const item = {
|
|
|
|
input,
|
|
|
|
output: [
|
|
|
|
{
|
|
|
|
file: `dist/iconify-icon${minify ? '.min' : ''}.${ext}`,
|
|
|
|
format,
|
|
|
|
exports: exportType,
|
|
|
|
banner: header,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
resolve({
|
|
|
|
browser: true,
|
|
|
|
}),
|
|
|
|
replace(replacements),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
if (minify) {
|
|
|
|
item.plugins.push(terser());
|
|
|
|
}
|
2022-04-29 20:19:22 +00:00
|
|
|
|
2022-04-30 16:16:10 +00:00
|
|
|
config.push(item);
|
2022-04-29 20:19:22 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
export default config;
|