2023-03-13 15:20:59 +03:00
|
|
|
import babel from '@rollup/plugin-babel';
|
|
|
|
import terser from '@rollup/plugin-terser';
|
|
|
|
import license from 'rollup-plugin-license';
|
2024-05-11 05:29:14 +03:00
|
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
|
|
import fs from 'fs';
|
2023-03-13 15:20:59 +03:00
|
|
|
import path from 'path';
|
2024-05-11 05:29:14 +03:00
|
|
|
import yaml from '@rollup/plugin-yaml';
|
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-05-11 05:29:14 +03:00
|
|
|
const SRC_PWA = `${SRC_DEFAULT}/pwa`;
|
|
|
|
|
|
|
|
const isProd = process.env.BUILD === 'production';
|
|
|
|
|
|
|
|
if (fs.existsSync(DIST_DEFAULT)) {
|
|
|
|
fs.rm(DIST_DEFAULT, { recursive: true, force: true }, (err) => {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function build(filename, opts = {}) {
|
|
|
|
const src = opts.src || SRC_DEFAULT;
|
|
|
|
const dist = opts.dist || DIST_DEFAULT;
|
|
|
|
const bannerUrl =
|
|
|
|
opts.bannerUrl || path.join(__dirname, SRC_DEFAULT, '_copyright');
|
|
|
|
const commentStyle = opts.commentStyle || 'ignored';
|
2023-03-13 15:20:59 +03:00
|
|
|
|
|
|
|
return {
|
2024-05-11 05:29:14 +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',
|
|
|
|
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(),
|
|
|
|
isProd && commentStyle === 'none' && terser(),
|
2023-03-13 15:20:59 +03:00
|
|
|
license({
|
|
|
|
banner: {
|
2024-05-11 05:29:14 +03:00
|
|
|
commentStyle,
|
|
|
|
content: { file: bannerUrl }
|
2023-03-13 15:20:59 +03:00
|
|
|
}
|
|
|
|
}),
|
2024-05-11 05:29:14 +03:00
|
|
|
isProd && commentStyle !== 'none' && terser()
|
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'),
|
|
|
|
build('app', { src: SRC_PWA }),
|
|
|
|
build('sw', {
|
|
|
|
src: SRC_PWA,
|
|
|
|
bannerUrl: path.join(__dirname, SRC_PWA, '_frontmatter'),
|
|
|
|
commentStyle: 'none'
|
|
|
|
})
|
2023-03-13 15:20:59 +03:00
|
|
|
];
|