You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.6 KiB

3 years ago
3 years ago
  1. import fs from "fs";
  2. import svelte from "rollup-plugin-svelte";
  3. import commonjs from "@rollup/plugin-commonjs";
  4. import resolve from "@rollup/plugin-node-resolve";
  5. import livereload from "rollup-plugin-livereload";
  6. import { terser } from "rollup-plugin-terser";
  7. import sveltePreprocess from "svelte-preprocess";
  8. import typescript from "@rollup/plugin-typescript";
  9. import css from "rollup-plugin-css-only";
  10. import dev from "rollup-plugin-dev";
  11. import replace from "@rollup/plugin-replace";
  12. import json from "@rollup/plugin-json";
  13. const production = !process.env.ROLLUP_WATCH;
  14. const envVariables = fs.readFileSync("build.env", "utf-8")
  15. .split("\n")
  16. .filter(l => l.length > 0)
  17. .map(l => l.trim().split("="))
  18. .reduce((p, [key, value]) => ({...p, [key]: value}), {});
  19. export default {
  20. input: "src/main.ts",
  21. output: {
  22. sourcemap: true,
  23. format: "iife",
  24. name: "app",
  25. file: "public/build/bundle.js"
  26. },
  27. plugins: [
  28. svelte({
  29. preprocess: sveltePreprocess(),
  30. compilerOptions: {
  31. // enable run-time checks when not in production
  32. dev: !production
  33. }
  34. }),
  35. // we"ll extract any component CSS out into
  36. // a separate file - better for performance
  37. css({ output: "bundle.css" }),
  38. // If you have external dependencies installed from
  39. // npm, you'll most likely need these plugins. In
  40. // some cases you'll need additional configuration -
  41. // consult the documentation for details:
  42. // https://github.com/rollup/plugins/tree/master/packages/commonjs
  43. resolve({
  44. browser: true,
  45. preferBuiltins: false,
  46. dedupe: ["svelte"],
  47. }),
  48. json(),
  49. commonjs({
  50. include: 'node_modules/**',
  51. }),
  52. typescript({
  53. sourceMap: !production,
  54. inlineSources: !production
  55. }),
  56. replace({
  57. // 2 level deep object should be stringify
  58. "process.env": JSON.stringify({
  59. NODE_ENV: production ? "production" : "development",
  60. ...envVariables,
  61. }),
  62. }),
  63. // Watch the `public` directory and refresh the
  64. // browser on changes when not in production
  65. !production && livereload("public"),
  66. // Add dev server in development.
  67. !production && dev({
  68. dirs: ["public"],
  69. spa: "public/index.html",
  70. port: 5000,
  71. proxy: {
  72. "/api/*": process.env.API_PROXY_TARGET || "localhost:8000",
  73. },
  74. }),
  75. // If we're building for production (npm run build
  76. // instead of npm run dev), minify
  77. production && terser({
  78. output: { comments: false },
  79. })
  80. ],
  81. watch: {
  82. clearScreen: false
  83. },
  84. onwarn: function(warning) {
  85. // Skip certain warnings
  86. if ( warning.code === "THIS_IS_UNDEFINED" ) { return; }
  87. // console.warn everything else
  88. console.warn( warning.message );
  89. }
  90. };