Commit the functional vite config and dependencies while I have them at a baseline working state
This commit is contained in:
parent
10c1760afe
commit
19a2bdc32f
4 changed files with 3042 additions and 0 deletions
89
vite.config.js
Normal file
89
vite.config.js
Normal 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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue