1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-10-31 23:26:19 +00:00
CC-Tweaked/rollup.config.js
Jonathan Coates a4c9e89370
Runnable examples (#576)
Provides a basic interface for running examples on tweaked.cc. This is probably
janky as anything, but it works on my machine.

This is the culmination of 18 months of me building far too much infrastructure
(copy-cat, illuaminate), so that's nice I guess.

I should probably get out more.
2020-11-12 19:01:50 +00:00

50 lines
1.7 KiB
JavaScript

import { readFileSync, promises as fs } from "fs";
import path from "path";
import typescript from "@rollup/plugin-typescript";
const input = "src/web";
const requirejs = readFileSync("node_modules/requirejs/require.js");
export default {
input: [`${input}/index.tsx`],
output: {
file: "build/rollup/index.js",
// We bundle requirejs (and config) into the header. It's rather gross
// but also works reasonably well.
banner: `${requirejs}\nrequire.config({ paths: { copycat: "https://copy-cat.squiddev.cc" } });`,
format: "amd",
preferConst: true,
amd: {
define: "require",
}
},
context: "window",
external: ["copycat/embed"],
plugins: [
typescript(),
{
name: "cc-tweaked",
async options(options) {
// Generate .d.ts files for all /mount files. This is the worst way to do it,
// but we need to run before the TS pass.
const template = "declare const contents : string;\nexport default contents;\n";
const files = await fs.readdir(`${input}/mount`);
await Promise.all(files
.filter(x => path.extname(x) !== ".ts")
.map(file => fs.writeFile(`${input}/mount/${file}.d.ts`, template))
);
return options;
},
async transform(code, file) {
// Allow loading files in /mount.
if (path.extname(file) != ".lua" && path.basename(file) != ".settings") return null;
return `export default ${JSON.stringify(code)};\n`;
},
}
],
};