2023-03-13 15:20:59 +03:00
|
|
|
import babel from '@rollup/plugin-babel';
|
|
|
|
import terser from '@rollup/plugin-terser';
|
2024-05-11 05:29:14 +03:00
|
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
2024-06-05 18:51:10 +03:00
|
|
|
import fs from 'fs';
|
|
|
|
import pkg from './package.json';
|
2023-03-13 15:20:59 +03:00
|
|
|
|
2024-01-27 21:22:33 +03:00
|
|
|
const SRC_DEFAULT = '_javascript';
|
2024-05-11 05:29:14 +03:00
|
|
|
const SRC_PWA = `${SRC_DEFAULT}/pwa`;
|
2024-08-26 11:49:48 +03:00
|
|
|
const DIST = 'assets/js/dist';
|
2024-06-05 18:51:10 +03:00
|
|
|
|
|
|
|
const banner = `/*!
|
|
|
|
* ${pkg.name} v${pkg.version} | © ${pkg.since} ${pkg.author} | ${pkg.license} Licensed | ${pkg.homepage}
|
|
|
|
*/`;
|
2024-05-11 05:29:14 +03:00
|
|
|
|
2024-08-26 11:49:48 +03:00
|
|
|
const frontmatter = `---\npermalink: /:basename\n---\n`;
|
|
|
|
|
2024-05-11 05:29:14 +03:00
|
|
|
const isProd = process.env.BUILD === 'production';
|
|
|
|
|
2024-08-26 11:49:48 +03:00
|
|
|
function cleanup() {
|
|
|
|
fs.rmSync(DIST, { recursive: true, force: true });
|
|
|
|
console.log(`> Directory "${DIST}" has been cleaned.`);
|
2024-05-11 05:29:14 +03:00
|
|
|
}
|
|
|
|
|
2024-08-26 11:49:48 +03:00
|
|
|
function insertFrontmatter() {
|
|
|
|
return {
|
|
|
|
name: 'insert-frontmatter',
|
|
|
|
generateBundle(_, bundle) {
|
|
|
|
for (const chunkOrAsset of Object.values(bundle)) {
|
|
|
|
if (chunkOrAsset.type === 'chunk') {
|
|
|
|
chunkOrAsset.code = frontmatter + chunkOrAsset.code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-03-13 15:20:59 +03:00
|
|
|
|
2024-08-26 11:49:48 +03:00
|
|
|
function build(filename, { src = SRC_DEFAULT, jekyll = false } = {}) {
|
2023-03-13 15:20:59 +03:00
|
|
|
return {
|
2024-06-05 18:51:10 +03:00
|
|
|
input: `${src}/${filename}.js`,
|
2023-03-13 15:20:59 +03:00
|
|
|
output: {
|
2024-08-26 11:49:48 +03:00
|
|
|
file: `${DIST}/${filename}.min.js`,
|
2023-03-13 15:20:59 +03:00
|
|
|
format: 'iife',
|
|
|
|
name: 'Chirpy',
|
2024-06-05 18:51:10 +03:00
|
|
|
banner,
|
2024-09-18 17:32:26 +03:00
|
|
|
sourcemap: !isProd && !jekyll
|
2023-03-13 15:20:59 +03:00
|
|
|
},
|
2023-03-30 23:55:09 +03:00
|
|
|
watch: {
|
2024-05-11 05:29:14 +03:00
|
|
|
include: `${src}/**`
|
2023-03-30 23:55:09 +03:00
|
|
|
},
|
2023-03-13 15:20:59 +03:00
|
|
|
plugins: [
|
|
|
|
babel({
|
|
|
|
babelHelpers: 'bundled',
|
|
|
|
presets: ['@babel/env'],
|
2024-02-25 15:30:21 +03:00
|
|
|
plugins: ['@babel/plugin-transform-class-properties']
|
2023-03-13 15:20:59 +03:00
|
|
|
}),
|
2024-05-11 05:29:14 +03:00
|
|
|
nodeResolve(),
|
2024-08-26 11:49:48 +03:00
|
|
|
isProd && terser(),
|
|
|
|
jekyll && insertFrontmatter()
|
2023-03-13 15:20:59 +03:00
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-08-26 11:49:48 +03:00
|
|
|
cleanup();
|
2024-06-05 18:51:10 +03:00
|
|
|
|
2023-03-13 15:20:59 +03:00
|
|
|
export default [
|
|
|
|
build('commons'),
|
2023-03-18 01:28:44 +03:00
|
|
|
build('home'),
|
2023-03-13 15:20:59 +03:00
|
|
|
build('categories'),
|
|
|
|
build('page'),
|
|
|
|
build('post'),
|
2024-05-11 05:29:14 +03:00
|
|
|
build('misc'),
|
2024-08-26 11:49:48 +03:00
|
|
|
build('app', { src: SRC_PWA, jekyll: true }),
|
|
|
|
build('sw', { src: SRC_PWA, jekyll: true })
|
2023-03-13 15:20:59 +03:00
|
|
|
];
|