This repository has been archived on 2023-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
scoresaber-reloaded/rollup.config.js
Liam 76260f7896
Some checks failed
deploy / deploy (push) Failing after 58s
fix commit hash
2023-10-18 01:58:28 +01:00

165 lines
4.2 KiB
JavaScript

const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import css from "rollup-plugin-css-only";
import livereload from "rollup-plugin-livereload";
import svelte from "rollup-plugin-svelte";
import svg from "rollup-plugin-svg";
import { terser } from "rollup-plugin-terser";
import sveltePreprocess from "svelte-preprocess";
const production = !process.env.ROLLUP_WATCH;
let buildVersion;
if (production) {
buildVersion = process.env.GIT_REV; // latest commit hash
} else {
buildVersion = execSync("git rev-parse --short HEAD").toString();
}
fs.writeFileSync(
"build-info.js",
"export default " +
JSON.stringify({
buildDate:
new Date().toISOString().substr(0, 19).replace("T", " ") + " UTC",
buildVersion,
})
);
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
server = require("child_process").spawn(
"npm",
["run", "start", "--", "--dev"],
{
stdio: ["ignore", "inherit", "inherit"],
shell: true,
}
);
process.on("SIGTERM", toExit);
process.on("exit", toExit);
},
};
}
export default [
{
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/bundle.js",
},
plugins: [
svelte({
preprocess: sveltePreprocess({ sourceMap: !production }),
compilerOptions: {
// enable run-time checks when not in production
dev: !production,
},
}),
// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: "bundle.css" }),
svg(),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ["svelte"],
}),
commonjs(),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload("public"),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
{
name: "copy-comlink",
generateBundle() {
const buildDir = "./public/build";
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir);
}
fs.copyFileSync(
path.resolve("./node_modules/comlink/dist/umd/comlink.min.js"),
path.resolve("./public/build/comlink.min.js")
);
},
},
],
watch: {
clearScreen: false,
},
},
{
input: "src/workers/stats-worker.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/stats-worker.js",
},
plugins: [
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ["svelte"],
}),
commonjs(),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
{
name: "copy-test-worker",
load() {
this.addWatchFile(path.resolve("./src/workers/stats-worker.js"));
},
generateBundle() {
const buildDir = "./public/build";
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir);
}
fs.copyFileSync(
path.resolve("./src/workers/stats-worker.js"),
path.resolve("./public/build/stats-worker.js")
);
},
},
],
},
];