UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in

96 lines (84 loc) 2.99 kB
/** * @param {import('../types').userSettings} userSettings */ export const needleDependencies = (command, config, userSettings) => { const handleChunks = true; /** * @type {import('vite').Plugin} */ return { name: 'needle:dependencies', enforce: 'pre', /** * @param {import('vite').UserConfig} config */ config: (config, env) => { handleOptimizeDeps(config); handleManualChunks(config); } } } /** * @param {import('vite').UserConfig} config */ function handleOptimizeDeps(config) { if (config.optimizeDeps?.include?.includes("three-mesh-bvh")) { console.log("[needle-dependencies] three-mesh-bvh is included in the optimizeDeps.include array. This may cause issues with the worker import."); } else { if (!config.optimizeDeps) { config.optimizeDeps = {}; } if (!config.optimizeDeps.exclude) { config.optimizeDeps.exclude = []; } console.log("[needle-dependencies] Adding three-mesh-bvh to the optimizeDeps.exclude array."); // This needs to be excluded from optimization because otherwise the worker import fails // three-mesh-bvh/src/workers/generateMeshBVH.worker.js?worker config.optimizeDeps.exclude.push("three-mesh-bvh"); } } /** * @param {import('vite').UserConfig} config */ function handleManualChunks(config) { if (!config.build) { config.build = {}; } if (!config.build.rollupOptions) { config.build.rollupOptions = {}; } if (!config.build.rollupOptions.output) { config.build.rollupOptions.output = {}; } const rollupOutput = config.build.rollupOptions.output; if (Array.isArray(rollupOutput)) { // append the manualChunks function to the array console.log("[needle-dependencies] registering manualChunks"); rollupOutput.push({ manualChunks: needleManualChunks }) } else { if (rollupOutput.manualChunks) { // if the user has already defined manualChunks, we don't want to overwrite it console.log("[needle-dependencies] manualChunks already defined"); } else { console.log("[needle-dependencies] registering manualChunks"); rollupOutput.manualChunks = needleManualChunks; } } function needleManualChunks(id) { // Push the pmndrs postprocessing package into a separate postprocessing chunk if (id.includes("node_modules/postprocessing/" || id.includes("node_modules/n8ao"))) { return "postprocessing"; } else if (id.includes("node_modules/three-mesh-ui")) { return "three-mesh-ui"; } else if (id.includes("@dimforge/rapier3d")) { return "rapier3d"; } } }