1
0

rollup.config.mjs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import pluginTypeScript from "@rollup/plugin-typescript";
  2. import pluginNodeResolve from "@rollup/plugin-node-resolve";
  3. import pluginJson from "@rollup/plugin-json";
  4. import pluginHtml from "rollup-plugin-html";
  5. import pluginCss from "rollup-plugin-import-css";
  6. import pluginExecute from "rollup-plugin-execute";
  7. import typescript from "typescript";
  8. const outputDir = "dist";
  9. const outputFile = getOutputFileName();
  10. /** @param {string} [suffix] */
  11. function getOutputFileName(suffix) {
  12. return `BetterYTM${suffix ?? ""}.user.js`;
  13. }
  14. export default (/**@type {import("./src/types").RollupArgs}*/ args) => (async () => {
  15. const mode = args["config-mode"] ?? (process.env.NODE_ENV === "production" ? "production" : "development");
  16. const branch = args["config-branch"] ?? "develop";
  17. const host = args["config-host"] ?? "github";
  18. const suffix = args["config-suffix"] ?? "";
  19. /** @type {import("rollup").RollupOptions} */
  20. const config = {
  21. input: "src/index.ts",
  22. plugins: [
  23. pluginNodeResolve({
  24. extensions: [".ts", ".mts", ".json"],
  25. }),
  26. pluginTypeScript({
  27. typescript,
  28. sourceMap: mode === "development",
  29. }),
  30. pluginJson(),
  31. pluginHtml(),
  32. pluginCss({
  33. output: "global.css",
  34. }),
  35. pluginExecute([
  36. `npm run --silent post-build -- --mode=${mode} --branch=${branch} --host=${host} --suffix=${suffix}`,
  37. ...(mode === "development" ? ["npm run --silent invisible -- \"npm run tr-progress\""] : []),
  38. ]),
  39. ],
  40. output: {
  41. file: `${outputDir}/${getOutputFileName(suffix)}`,
  42. format: "iife",
  43. sourcemap: mode === "development",
  44. compact: mode === "development",
  45. globals: {
  46. "marked": "marked",
  47. "@sv443-network/userutils": "UserUtils",
  48. },
  49. },
  50. onwarn(warning) {
  51. // ignore circular dependency warnings
  52. if(warning.code !== "CIRCULAR_DEPENDENCY") {
  53. const { message, ...rest } = warning;
  54. console.error(`\x1b[33m(!)\x1b[0m ${message}\n`, rest);
  55. }
  56. },
  57. external: [
  58. "marked",
  59. "@sv443-network/userutils",
  60. ],
  61. };
  62. return config;
  63. })();
  64. export { outputDir, outputFile };