2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-09 23:00:56 +00:00
iconify/components/svg-framework/rollup.config.mjs

133 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-06-01 21:20:11 +00:00
import { readFileSync, writeFileSync } from 'fs';
2020-04-28 09:47:35 +00:00
import resolve from '@rollup/plugin-node-resolve';
2023-04-02 07:42:40 +00:00
import terser from '@rollup/plugin-terser';
2020-04-28 09:47:35 +00:00
import replace from '@rollup/plugin-replace';
const names = ['iconify', 'iconify.without-api'];
2020-04-28 09:47:35 +00:00
const global = 'Iconify';
// Wrapper to export module as global and as ES module
const header = `/**
2020-06-01 21:20:11 +00:00
* (c) Iconify
2020-04-28 09:47:35 +00:00
*
* For the full copyright and license information, please view the license.txt or license.gpl.txt
* files at https://github.com/iconify/iconify
*
* Licensed under MIT.
2020-04-28 09:47:35 +00:00
*
* @license MIT
* @version __iconify_version__
2020-04-28 09:47:35 +00:00
*/`;
const defaultFooter = `
2020-04-28 09:47:35 +00:00
// Export to window or web worker
try {
if (self.Iconify === void 0) {
self.Iconify = Iconify;
}
} catch (err) {
}`;
2020-04-28 09:47:35 +00:00
const iifeFooter = `
// Export as ES module
2020-04-28 09:47:35 +00:00
if (typeof exports === 'object') {
try {
exports.__esModule = true;
exports.default = Iconify;
for (var key in Iconify) {
exports[key] = Iconify[key];
}
2020-04-28 09:47:35 +00:00
} catch (err) {
}
}
2020-04-28 09:47:35 +00:00
${defaultFooter}`;
2020-04-28 09:47:35 +00:00
// Get replacements
2021-06-16 13:58:27 +00:00
const replacements = {
preventAssignment: true,
};
2020-04-28 09:47:35 +00:00
const packageJSON = JSON.parse(readFileSync('package.json', 'utf8'));
replacements['__iconify_version__'] = packageJSON.version;
2020-06-01 21:20:11 +00:00
// Update README.md
let readme = readFileSync('README.md', 'utf8');
const oldReadme = readme;
const replaceCodeLink = (search) => {
let start = 0;
let pos;
while ((pos = readme.indexOf(search, start)) !== -1) {
start = pos + search.length;
let pos2 = readme.indexOf('/', start);
if (pos2 === -1) {
return;
}
readme =
readme.slice(0, start) + packageJSON.version + readme.slice(pos2);
}
};
replaceCodeLink('/code.iconify.design/3/');
2020-06-01 21:20:11 +00:00
replaceCodeLink('/@iconify/iconify@');
if (readme !== oldReadme) {
console.log('Updatead README');
writeFileSync('README.md', readme, 'utf8');
}
2020-04-28 09:47:35 +00:00
// Export configuration
const config = [];
names.forEach((name) => {
// Full and minified
[false, true].forEach((minify) => {
// Parse all formats
['js', 'cjs', 'mjs'].forEach((ext) => {
if (minify && ext !== 'js') {
// Minify only .js files
return;
}
// Get export format and footer
let format = ext;
let footer = defaultFooter;
switch (ext) {
case 'js':
format = 'iife';
footer = iifeFooter;
break;
case 'mjs':
format = 'es';
break;
}
const item = {
input: `lib/${name}.js`,
output: [
{
file: `dist/${name}${minify ? '.min' : ''}.${ext}`,
format,
exports: 'named',
name: global,
banner: header,
footer,
},
],
plugins: [
resolve({
browser: true,
}),
replace(replacements),
],
};
if (minify) {
item.plugins.push(terser());
}
config.push(item);
});
});
2020-04-28 09:47:35 +00:00
});
2020-04-28 09:47:35 +00:00
export default config;