2023-03-15 21:52:13 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-12-21 22:20:45 +00:00
|
|
|
import { readFileSync } from "fs";
|
2020-11-12 19:01:50 +00:00
|
|
|
import path from "path";
|
|
|
|
|
|
|
|
import typescript from "@rollup/plugin-typescript";
|
2021-12-21 22:20:45 +00:00
|
|
|
import url from '@rollup/plugin-url';
|
2023-03-14 18:41:31 +00:00
|
|
|
import terser from "@rollup/plugin-terser";
|
2020-11-12 19:01:50 +00:00
|
|
|
|
2022-11-06 13:37:07 +00:00
|
|
|
const input = "src";
|
|
|
|
const requirejs = readFileSync("../../node_modules/requirejs/require.js");
|
2020-11-12 19:01:50 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
input: [`${input}/index.tsx`],
|
|
|
|
output: {
|
2022-11-06 13:37:07 +00:00
|
|
|
// Also defined in build.gradle.kts
|
2021-12-21 22:20:45 +00:00
|
|
|
dir: "build/rollup/",
|
2022-11-06 13:37:07 +00:00
|
|
|
|
2020-11-12 19:01:50 +00:00
|
|
|
// We bundle requirejs (and config) into the header. It's rather gross
|
|
|
|
// but also works reasonably well.
|
2021-11-27 12:27:40 +00:00
|
|
|
// Also suffix a ?v=${date} onto the end in the event we need to require a specific copy-cat version.
|
|
|
|
banner: `
|
|
|
|
${requirejs}
|
|
|
|
require.config({
|
|
|
|
paths: { copycat: "https://copy-cat.squiddev.cc" },
|
2021-12-21 22:20:45 +00:00
|
|
|
urlArgs: function(id) { return id == "copycat/embed" ? "?v=20211221" : ""; }
|
2021-11-27 12:27:40 +00:00
|
|
|
});
|
|
|
|
`,
|
2020-11-12 19:01:50 +00:00
|
|
|
format: "amd",
|
2023-03-14 18:41:31 +00:00
|
|
|
generatedCode: {
|
|
|
|
preset: "es2015",
|
|
|
|
constBindings: true,
|
|
|
|
},
|
2020-11-12 19:01:50 +00:00
|
|
|
amd: {
|
|
|
|
define: "require",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
context: "window",
|
|
|
|
external: ["copycat/embed"],
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
typescript(),
|
|
|
|
|
2021-12-21 22:20:45 +00:00
|
|
|
url({
|
|
|
|
include: "**/*.dfpwm",
|
|
|
|
fileName: "[name]-[hash][extname]",
|
|
|
|
publicPath: "/",
|
|
|
|
}),
|
|
|
|
|
2020-11-12 19:01:50 +00:00
|
|
|
{
|
|
|
|
name: "cc-tweaked",
|
|
|
|
async transform(code, file) {
|
|
|
|
// Allow loading files in /mount.
|
2020-11-20 21:59:17 +00:00
|
|
|
const ext = path.extname(file);
|
2021-12-21 22:20:45 +00:00
|
|
|
return ext != '.dfpwm' && path.dirname(file) === path.resolve(`${input}/mount`)
|
2020-11-20 21:59:17 +00:00
|
|
|
? `export default ${JSON.stringify(code)};\n`
|
|
|
|
: null;
|
2020-11-12 19:01:50 +00:00
|
|
|
},
|
2021-11-27 12:27:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
terser(),
|
2020-11-12 19:01:50 +00:00
|
|
|
],
|
|
|
|
};
|