This repository has been archived on 2021-11-08. You can view files and clone it, but cannot push or open issues or pull requests.
svelte-sharg/rollup.config.mjs

105 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2021-09-26 16:04:20 +02:00
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import autoprefixer from "autoprefixer";
import child_process from "child_process";
2021-09-26 21:02:02 +02:00
import postcss from "postcss";
import livereload from "rollup-plugin-livereload";
import scss from "rollup-plugin-scss";
import svelte from "rollup-plugin-svelte";
import { terser } from "rollup-plugin-terser";
import sveltePreprocess from "svelte-preprocess";
2021-09-26 16:04:20 +02:00
const production = !process.env.ROLLUP_WATCH;
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
2021-09-28 12:27:52 +02:00
server = child_process.spawn("yarn", ["start", "--dev"], {
2021-09-26 16:04:20 +02:00
stdio: ["ignore", "inherit", "inherit"],
shell: true,
});
process.on("SIGTERM", toExit);
process.on("exit", toExit);
},
};
}
export default {
input: "src/main.ts",
output: {
sourcemap: true,
2021-09-29 17:38:53 +02:00
format: "module",
name: "sharg",
2021-09-26 16:04:20 +02:00
file: "public/build/bundle.js",
2021-09-29 17:38:53 +02:00
externalLiveBindings: false,
preferConst: true,
strict: true,
2021-10-05 12:53:14 +02:00
compact: production,
2021-09-26 16:04:20 +02:00
},
plugins: [
2021-09-29 17:38:53 +02:00
// Svelte adds "stdin" to the sourceMap
2021-09-26 16:04:20 +02:00
svelte({
2021-09-29 17:38:53 +02:00
preprocess: [
sveltePreprocess({
scss: {
renderSync: true,
},
2021-09-27 12:30:23 +02:00
}),
2021-09-29 17:38:53 +02:00
],
2021-09-26 16:04:20 +02:00
compilerOptions: {
// enable run-time checks when not in production
dev: !production,
},
}),
2021-09-29 17:38:53 +02:00
// The processor (postcss) adds "bundle.css" to the sourceMap
// but for some reason only in dev mode?
2021-09-26 16:04:20 +02:00
scss({
2021-09-27 12:30:23 +02:00
outputStyle: production ? "compressed" : "expanded",
2021-09-29 17:38:53 +02:00
processor() {
// If this is a separate plugin, it doesn't seem to run (autoprefixer doesn't run)
return postcss({
plugins: [autoprefixer()],
});
},
2021-09-26 16:04:20 +02:00
}),
resolve({
browser: true,
dedupe: ["svelte"],
}),
typescript({
sourceMap: true,
2021-09-29 17:38:53 +02:00
inlineSources: true,
2021-10-05 12:53:14 +02:00
exclude: ["node_modules/*", "public/*", "**/service-worker.ts"],
2021-09-26 16:04:20 +02:00
}),
2021-09-29 17:38:53 +02:00
// In dev mode, call `yarn start` once
2021-09-26 16:04:20 +02:00
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload("public"),
2021-09-29 17:38:53 +02:00
// If we're building for production (yarn build
// instead of yarn dev), minify js
production &&
terser({
mangle: false,
output: { comments: false },
}),
2021-09-26 16:04:20 +02:00
],
watch: {
clearScreen: false,
},
};