ds4/rollup.config.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-06-26 22:02:00 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
2022-08-15 15:01:47 +02:00
import livereload from "rollup-plugin-livereload";
import styles from "rollup-plugin-styles";
import { swc } from "rollup-plugin-swc3";
import { copy } from "@guanghechen/rollup-plugin-copy";
2022-08-22 22:05:14 +02:00
import { distDirectory, name, sourceDirectory } from "./tools/const.js";
import { convertJSONToPack } from "./tools/json-pack-tools.js";
const staticFiles = [
".reuse",
"assets",
"ATTRIBUTION.md",
"fonts",
"lang",
2022-01-31 16:56:50 +01:00
"LICENSE.md",
"LICENSES",
"README.md",
"system.json.license",
"system.json",
"template.json.license",
"template.json",
"templates",
];
const isProduction = process.env.NODE_ENV === "production";
2022-08-15 15:01:47 +02:00
const isWatch = process.env.ROLLUP_WATCH === "true";
2021-03-17 12:15:25 +01:00
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: { [name]: `${sourceDirectory}/${name}.ts` },
2021-03-17 12:15:25 +01:00
output: {
dir: distDirectory,
2021-03-17 12:15:25 +01:00
format: "es",
sourcemap: true,
assetFileNames: "[name].[ext]",
2021-03-17 12:15:25 +01:00
},
plugins: [
swc({
2022-05-13 20:08:00 +02:00
jsc: {
2022-08-22 22:05:14 +02:00
minify: isProduction && {
2022-05-13 20:08:00 +02:00
sourceMap: true,
mangle: {
keepClassNames: true,
keepFnNames: true,
},
},
},
sourceMaps: true,
}),
styles({
mode: ["extract", `css/${name}.css`],
url: false,
sourceMap: true,
minimize: isProduction,
}),
copy({
targets: [
{ src: staticFiles, dest: distDirectory },
{
src: [`packs/*.json`],
dest: `${distDirectory}/packs`,
rename: (name) => `${name}.db`,
transform: convertJSONToPack,
},
{
src: [`packs/*.json.license`],
dest: `${distDirectory}/packs`,
rename: (name, extension) => `${name.replace(".json", ".db")}.${extension}`,
},
],
verbose: true,
}),
2022-08-15 15:01:47 +02:00
isWatch && livereload(distDirectory),
],
2021-03-17 12:15:25 +01:00
};
export default config;