mirror of
https://github.com/storytold/spark.git
synced 2026-10-27 08:58:05 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { defineConfig } from "vite";
|
||||
import glsl from "vite-plugin-glsl";
|
||||
|
||||
const assetsDirectory = "examples/assets";
|
||||
const localAssetsDirectoryExist = fs.existsSync(assetsDirectory);
|
||||
if (!localAssetsDirectoryExist) {
|
||||
console.log(
|
||||
"************************************************************************",
|
||||
);
|
||||
console.log(" Examples assets will be fetched from an external server.");
|
||||
console.log(
|
||||
" To work offline you can download them: npm run assets:download",
|
||||
);
|
||||
console.log(
|
||||
"************************************************************************",
|
||||
);
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const isMinify = mode === "production";
|
||||
const isFirstPass = mode === "production";
|
||||
|
||||
return {
|
||||
appType: "mpa",
|
||||
|
||||
plugins: [
|
||||
glsl({
|
||||
include: ["**/*.glsl"],
|
||||
}),
|
||||
|
||||
{
|
||||
name: "serve-three-alias",
|
||||
configureServer(server) {
|
||||
const urlPath = "/examples/js/vendor/three/";
|
||||
|
||||
const filePath = path.resolve("node_modules/three/");
|
||||
server.middlewares.use(urlPath, (req, res, next) => {
|
||||
if (fs.existsSync(filePath)) {
|
||||
res.setHeader("Content-Type", "application/javascript");
|
||||
fs.createReadStream(filePath).pipe(res);
|
||||
} else {
|
||||
res.statusCode = 404;
|
||||
res.end("three.module.js not found");
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`📦 Dev alias active: ${urlPath} → ${filePath}`);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
build: {
|
||||
minify: isMinify,
|
||||
lib: {
|
||||
entry: path.resolve(__dirname, "src/index.ts"),
|
||||
name: "forge",
|
||||
formats: ["es", "cjs"],
|
||||
fileName: (format) => {
|
||||
const base = format === "es" ? "forge.module" : `forge.${format}`;
|
||||
return isMinify ? `${base}.min.js` : `${base}.js`;
|
||||
},
|
||||
},
|
||||
rollupOptions: {
|
||||
external: ["three"],
|
||||
output: {
|
||||
globals: {
|
||||
three: "THREE",
|
||||
},
|
||||
},
|
||||
},
|
||||
emptyOutDir: isFirstPass,
|
||||
},
|
||||
|
||||
server: {
|
||||
watch: {
|
||||
usePolling: true,
|
||||
},
|
||||
port: 8080,
|
||||
},
|
||||
|
||||
optimizeDeps: {
|
||||
force: true,
|
||||
exclude: ["three"], // prevent Vite pre-bundling
|
||||
},
|
||||
|
||||
define: {
|
||||
forgeLocalAssets: localAssetsDirectoryExist,
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user