Files
IoTManagerWeb/rollup.config.js

98 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-10-05 14:38:57 +02:00
import svelte from "rollup-plugin-svelte";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import livereload from "rollup-plugin-livereload";
import { terser } from "rollup-plugin-terser";
import css from "rollup-plugin-css-only";
2021-09-16 02:00:52 +08:00
import sveltePreprocess from "svelte-preprocess";
const production = !process.env.ROLLUP_WATCH;
function serve() {
2023-10-05 14:38:57 +02:00
let server;
2021-09-16 02:00:52 +08:00
2023-10-05 14:38:57 +02:00
function toExit() {
if (server) server.kill(0);
}
2021-09-16 02:00:52 +08:00
2023-10-05 14:38:57 +02:00
return {
writeBundle() {
if (server) return;
server = require("child_process").spawn(
"npm",
["run", "start", "--", "--dev"],
{
stdio: ["ignore", "inherit", "inherit"],
shell: true,
}
);
2021-09-16 02:00:52 +08:00
2023-10-05 14:38:57 +02:00
process.on("SIGTERM", toExit);
process.on("exit", toExit);
},
};
2021-09-16 02:00:52 +08:00
}
export default {
2023-10-05 14:38:57 +02:00
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/bundle.js",
},
plugins: [
terser({
ecma: 2020,
mangle: { toplevel: true },
compress: {
module: true,
toplevel: true,
unsafe_arrows: true,
2024-08-24 23:00:03 +02:00
drop_console: false,
2023-10-05 14:38:57 +02:00
drop_debugger: true,
},
output: { quote_style: 1 },
}),
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production,
},
preprocess: sveltePreprocess({
sourceMap: !production,
postcss: true,
}),
}),
// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: "bundle.css" }),
2021-09-16 02:00:52 +08:00
2023-10-05 14:38:57 +02:00
// 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(),
2021-09-16 02:00:52 +08:00
2023-10-05 14:38:57 +02:00
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
2021-09-16 02:00:52 +08:00
2023-10-05 14:38:57 +02:00
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload("public"),
2021-09-16 02:00:52 +08:00
2023-10-05 14:38:57 +02:00
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
],
watch: {
clearScreen: false,
},
2021-09-16 02:00:52 +08:00
};