2023-10-17 22:38:18 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2023-10-17 20:42:37 +00:00
|
|
|
const { execSync } = require("child_process");
|
2023-10-17 22:38:18 +00:00
|
|
|
import commonjs from "@rollup/plugin-commonjs";
|
|
|
|
import resolve from "@rollup/plugin-node-resolve";
|
2023-10-18 01:18:09 +00:00
|
|
|
import moment from "moment/moment";
|
2023-10-18 00:58:28 +00:00
|
|
|
import css from "rollup-plugin-css-only";
|
2023-10-17 22:38:18 +00:00
|
|
|
import livereload from "rollup-plugin-livereload";
|
2023-10-18 00:58:28 +00:00
|
|
|
import svelte from "rollup-plugin-svelte";
|
|
|
|
import svg from "rollup-plugin-svg";
|
2023-10-17 22:38:18 +00:00
|
|
|
import { terser } from "rollup-plugin-terser";
|
|
|
|
import sveltePreprocess from "svelte-preprocess";
|
2023-10-17 20:42:37 +00:00
|
|
|
|
|
|
|
const production = !process.env.ROLLUP_WATCH;
|
|
|
|
|
2023-10-18 00:58:28 +00:00
|
|
|
let buildVersion;
|
|
|
|
if (production) {
|
2023-10-18 01:32:47 +00:00
|
|
|
buildVersion = process.env.GIT_REV.substring(0, 7); // latest commit hash
|
2023-10-18 00:58:28 +00:00
|
|
|
} else {
|
|
|
|
buildVersion = execSync("git rev-parse --short HEAD").toString();
|
|
|
|
}
|
2023-10-17 22:38:18 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
"build-info.js",
|
|
|
|
"export default " +
|
|
|
|
JSON.stringify({
|
2023-10-18 01:18:09 +00:00
|
|
|
buildDate: moment().format("MMMM Do YYYY, h:mm:ss a"),
|
2023-10-17 22:38:18 +00:00
|
|
|
buildVersion,
|
2023-10-17 22:41:42 +00:00
|
|
|
})
|
2023-10-17 22:38:18 +00:00
|
|
|
);
|
2023-10-17 20:42:37 +00:00
|
|
|
|
|
|
|
function serve() {
|
2023-10-17 22:38:18 +00:00
|
|
|
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,
|
2023-10-17 22:41:42 +00:00
|
|
|
}
|
2023-10-17 22:38:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
process.on("SIGTERM", toExit);
|
|
|
|
process.on("exit", toExit);
|
|
|
|
},
|
|
|
|
};
|
2023-10-17 20:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default [
|
2023-10-17 22:38:18 +00:00
|
|
|
{
|
|
|
|
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"),
|
2023-10-17 22:41:42 +00:00
|
|
|
path.resolve("./public/build/comlink.min.js")
|
2023-10-17 22:38:18 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
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"),
|
2023-10-17 22:41:42 +00:00
|
|
|
path.resolve("./public/build/stats-worker.js")
|
2023-10-17 22:38:18 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-10-17 20:42:37 +00:00
|
|
|
];
|