import svelte from "rollup-plugin-svelte"; import resolve from "@rollup/plugin-node-resolve"; import commonjs from "@rollup/plugin-commonjs"; import livereload from "rollup-plugin-livereload"; import postcss from "rollup-plugin-postcss"; import { terser } from "rollup-plugin-terser"; import sveltePreprocessPostcss from "svelte-preprocess-postcss"; const production = !process.env.ROLLUP_WATCH; export default { input: "src/main.js", output: { sourcemap: true, format: "iife", name: "app", file: "public/out/bundle.js", }, plugins: [ svelte({ dev: !production, // Allow PostCSS to include the CSS output from our SFCs. preprocess: { style: sveltePreprocessPostcss() }, emitCss: true, // Let PostCSS handle it. // We can also write CSS to a file. //css: (css) => css.write("public/out/svelte.css"); }), postcss({ extract: true }), // Write to a file resolve({ browser: true, dedupe: ["svelte"], }), commonjs(), !production && serve(), !production && livereload('public') ,// reload when /public changes production && terser() ], watch: { clearScreen: false }, }; function serve() { let started = false; return { writeBundle() { if (!started) { started = true; require("child_process").spawn("npm", ["run", "start", "--", "--dev"], { stdio: ["ignore", "inherit", "inherit"], shell: true, }); } }, }; }