1
0
mirror of https://github.com/LibreScore/dl-librescore synced 2024-09-19 18:15:34 +02:00
dl-librescore/rollup.config.js

105 lines
2.6 KiB
JavaScript
Raw Normal View History

import typescript from "rollup-plugin-typescript";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import builtins from "@crokita/rollup-plugin-node-builtins";
import nodeGlobals from "rollup-plugin-node-globals";
import json from "@rollup/plugin-json";
import { string } from "rollup-plugin-string";
import fs from "fs";
2019-11-03 20:13:06 +01:00
2019-11-03 21:01:29 +01:00
const getBannerText = () => {
const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
const { version } = packageJson;
let bannerText = fs.readFileSync("./src/meta.js", "utf-8");
bannerText = bannerText.replace("%VERSION%", version);
return bannerText;
};
2019-11-03 20:13:06 +01:00
2020-12-06 08:49:55 +01:00
const getWrapper = (startL, endL) => {
2023-02-28 18:59:00 +01:00
const js = fs.readFileSync("./src/wrapper.js", "utf-8");
return js.split(/\n/g).slice(startL, endL).join("\n");
};
2020-12-06 08:21:33 +01:00
2020-11-24 19:11:19 +01:00
const basePlugins = [
2019-12-01 22:25:13 +01:00
typescript({
target: "ES6",
sourceMap: false,
allowJs: true,
lib: ["ES6", "dom"],
2019-12-01 22:25:13 +01:00
}),
resolve({
preferBuiltins: true,
jsnext: true,
extensions: [".js", ".ts"],
2019-12-01 22:25:13 +01:00
}),
commonjs({
extensions: [".js", ".ts"],
2019-12-01 22:25:13 +01:00
}),
json(),
2020-11-12 18:13:14 +01:00
string({
include: "**/*.css",
}),
2019-12-01 22:25:13 +01:00
{
/**
* remove tslib license comments
* @param {string} code
* @param {string} id
2019-12-01 22:25:13 +01:00
*/
transform(code, id) {
2019-12-01 22:25:13 +01:00
if (id.includes("tslib")) {
code = code.split(/\r?\n/g).slice(15).join("\n");
2019-12-01 22:25:13 +01:00
}
return {
code,
};
},
2019-12-01 22:25:13 +01:00
},
];
2019-12-01 22:25:13 +01:00
2020-11-24 19:11:19 +01:00
const plugins = [
...basePlugins,
builtins(),
nodeGlobals({
dirname: false,
filename: false,
baseDir: false,
}),
];
2020-11-24 19:11:19 +01:00
2019-12-01 22:25:13 +01:00
export default [
{
input: "src/worker.ts",
output: {
file: "dist/cache/worker.js",
format: "iife",
name: "worker",
2019-12-01 22:45:38 +01:00
banner: "export const PDFWorker = function () { ",
2021-08-01 04:18:00 +02:00
footer: "return worker\n}\n",
2019-12-01 22:25:13 +01:00
sourcemap: false,
},
2019-12-01 22:25:13 +01:00
plugins,
},
{
2019-12-01 22:45:38 +01:00
input: "src/main.ts",
2019-12-01 22:25:13 +01:00
output: {
2021-10-30 21:10:46 +02:00
file: "dist/main.user.js",
2019-12-01 22:25:13 +01:00
format: "iife",
sourcemap: false,
banner: getBannerText,
2023-02-28 18:59:00 +01:00
intro: () => getWrapper(0, -5),
outro: () => getWrapper(-5),
2019-12-01 22:25:13 +01:00
},
2019-12-01 22:45:38 +01:00
plugins,
2019-12-01 22:25:13 +01:00
},
2020-11-24 19:11:19 +01:00
{
input: "src/cli.ts",
output: {
file: "dist/cli.js",
format: "cjs",
2020-11-25 00:01:03 +01:00
banner: "#!/usr/bin/env node",
2020-11-24 19:11:19 +01:00
sourcemap: false,
},
plugins: basePlugins,
},
];