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';
|
|
|
|
import yaml from '@rollup/plugin-yaml';
|
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';
|
|
|
|
const DIST_DEFAULT = 'assets/js/dist';
|
2024-06-05 18:51:10 +03:00
|
|
|
|
2024-05-11 05:29:14 +03:00
|
|
|
const SRC_PWA = `${SRC_DEFAULT}/pwa`;
|
2024-06-05 18:51:10 +03:00
|
|
|
const DIST_PWA = '_app';
|
|
|
|
|
|
|
|
const banner = `/*!
|
|
|
|
* ${pkg.name} v${pkg.version} | © ${pkg.since} ${pkg.author} | ${pkg.license} Licensed | ${pkg.homepage}
|
|
|
|
*/`;
|
2024-05-11 05:29:14 +03:00
|
|
|
|
|
|
|
const isProd = process.env.BUILD === 'production';
|
|
|
|
|
2024-06-05 18:51:10 +03:00
|
|
|
function cleanup(...directories) {
|
|
|
|
for (const dir of directories) {
|
|
|
|
fs.rm(dir, { recursive: true, force: true }, (err) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(`Failed to remove directory ${dir}: ${err}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-05-11 05:29:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function build(filename, opts = {}) {
|
|
|
|
const src = opts.src || SRC_DEFAULT;
|
|
|
|
const dist = opts.dist || DIST_DEFAULT;
|
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-05-11 05:29:14 +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,
|
2023-03-13 15:20:59 +03:00
|
|
|
sourcemap: !isProd
|
|
|
|
},
|
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(),
|
|
|
|
yaml(),
|
2024-06-05 18:51:10 +03:00
|
|
|
isProd && terser()
|
2023-03-13 15:20:59 +03:00
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-05 18:51:10 +03:00
|
|
|
cleanup(DIST_DEFAULT, DIST_PWA);
|
|
|
|
|
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-06-05 18:51:10 +03:00
|
|
|
build('app', { src: SRC_PWA, dist: DIST_PWA }),
|
|
|
|
build('sw', { src: SRC_PWA, dist: DIST_PWA })
|
2023-03-13 15:20:59 +03:00
|
|
|
];
|