Commit the functional vite config and dependencies while I have them at a baseline working state

This commit is contained in:
Oliver-Akins 2025-04-19 15:50:10 -06:00
parent 10c1760afe
commit 19a2bdc32f
4 changed files with 3042 additions and 0 deletions

95
eslint.config.mjs Normal file
View file

@ -0,0 +1,95 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";
export default [
// Tell eslint to ignore files that I don't mind being formatted slightly differently
{ ignores: [ `scripts/`, `*.dist/` ] },
{
languageOptions: {
globals: globals.browser,
},
},
pluginJs.configs.recommended,
// MARK: Foundry Globals
{
languageOptions: {
globals: {
CONFIG: `writable`,
CONST: `readonly`,
game: `readonly`,
Handlebars: `readonly`,
Hooks: `readonly`,
ui: `readonly`,
Actor: `readonly`,
Item: `readonly`,
foundry: `readonly`,
ChatMessage: `readonly`,
ActiveEffect: `readonly`,
Dialog: `readonly`,
renderTemplate: `readonly`,
TextEditor: `readonly`,
fromUuid: `readonly`,
Combat: `readonly`,
Combatant: `readonly`,
canvas: `readonly`,
Token: `readonly`,
Tour: `readonly`,
},
},
},
// MARK: Project Specific
{
plugins: {
"@stylistic": stylistic,
},
languageOptions: {
globals: {
__ID__: `readonly`,
__VERSION__: `readonly`,
},
},
rules: {
"curly": `error`,
"func-names": [`warn`, `as-needed`],
"grouped-accessor-pairs": `error`,
"no-alert": `error`,
"no-empty": [`error`, { allowEmptyCatch: true }],
"no-implied-eval": `error`,
"no-invalid-this": `error`,
"no-lonely-if": `error`,
"no-unneeded-ternary": `error`,
"no-nested-ternary": `error`,
"no-var": `error`,
"no-unused-vars": [
`error`,
{
"vars": `local`,
"args": `after-used`,
"varsIgnorePattern": `^_`,
"argsIgnorePattern": `^_`,
},
],
"sort-imports": [`warn`, { "ignoreCase": true, "allowSeparatedGroups": true }],
"@stylistic/semi": [`warn`, `always`, { "omitLastInOneLineBlock": true }],
"@stylistic/no-trailing-spaces": `warn`,
"@stylistic/space-before-blocks": [`warn`, `always`],
"@stylistic/space-infix-ops": `warn`,
"@stylistic/eol-last": `warn`,
"@stylistic/operator-linebreak": [`warn`, `before`],
"@stylistic/indent": [`warn`, `tab`],
"@stylistic/brace-style": [`warn`, `1tbs`, { "allowSingleLine": true }],
"@stylistic/quotes": [`warn`, `backtick`, { "avoidEscape": true }],
"@stylistic/comma-dangle": [`warn`, { arrays: `always-multiline`, objects: `always-multiline`, imports: `always-multiline`, exports: `always-multiline`, functions: `always-multiline` }],
"@stylistic/comma-style": [`warn`, `last`],
"@stylistic/dot-location": [`error`, `property`],
"@stylistic/no-confusing-arrow": `error`,
"@stylistic/no-whitespace-before-property": `error`,
"@stylistic/nonblock-statement-body-position": [
`error`,
`beside`,
{ "overrides": { "while": `below` } },
],
},
},
];

2836
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

22
package.json Normal file
View file

@ -0,0 +1,22 @@
{
"name": "stat-tracker",
"private": true,
"type": "module",
"scripts": {
"lint": "eslint --fix",
"lint:nofix": "eslint",
"dev": "NODE_ENV=development vite build --mode dev --watch",
"dev:once": "NODE_ENV=development vite build --mode dev",
"build": "NODE_ENV=production vite build --mode prod"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^4.2.0",
"eslint": "^9.25.0",
"glob": "^11.0.1",
"terser": "^5.39.0",
"vite": "^6.3.1"
},
"dependencies": {
"chart.js": "^4.4.9"
}
}

89
vite.config.js Normal file
View file

@ -0,0 +1,89 @@
/* eslint-disable no-undef */
import { defineConfig } from "vite";
import { glob } from "glob";
import path from "path";
import { readFileSync } from "fs";
// MARK: custom plugins
function fileMarkerPlugin() {
return {
name: `file-marker-plugin`,
transform(code, id) {
const basePath = __dirname;
const relative = path.relative(basePath, id);
const comment = `/*! --- ${relative} --- */\n`;
return {
code: comment + code,
map: null,
};
},
};
};
function watcher(...globs) {
return {
buildStart() {
for (const item of globs) {
glob.sync(path.resolve(item)).forEach((filename) => {
this.addWatchFile(filename);
});
}
},
};
};
// MARK: config
export default defineConfig(({ mode }) => {
const isProd = mode === `prod`;
const plugins = [];
if (!isProd) {
plugins.push(
watcher(
`./public/module.json`,
),
fileMarkerPlugin(),
);
};
const manifest = JSON.parse(readFileSync(`./public/module.json`, `utf-8`));
return {
plugins,
define: {
__ID__: JSON.stringify(manifest.id),
__VERSION__: JSON.stringify(manifest.version),
},
mode: isProd ? `production` : `development`,
build: {
minify: isProd ? `terser` : false,
sourcemap: true,
rollupOptions: {
input: {
module: `./module/main.mjs`,
// TODO: Figure out how to get handlebars files being used here
},
output: {
entryFileNames: `[name].mjs`,
format: `esm`,
},
},
watch: {
include: [
`module/**`,
`public/**`,
],
// skipWrite: false,
// onInvalidate: console.log
},
outDir: `${mode}.dist`,
emptyOutDir: true,
},
};
});
/* eslint-enable no-undef */