@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.
40 lines (33 loc) • 1.79 kB
JavaScript
const { existsSync } = require("fs");
const path = require("path");
module.exports.alias = function (config) {
const workingDirectory = process.cwd();
config.resolve.alias['three'] = path.resolve(workingDirectory, 'node_modules/three');
config.resolve.alias['three/examples/jsm'] = path.resolve(workingDirectory, 'node_modules/three/examples/jsm');
config.resolve.alias['@needle-tools/engine'] = path.resolve(workingDirectory, 'node_modules/@needle-tools/engine');
// first check if gltf-progressive exists locally (due to local installation of engine)
const gltfProgressive_local = path.resolve(workingDirectory, 'node_modules/@needle-tools/engine/node_modules/@needle-tools/gltf-progressive');
if (existsSync(gltfProgressive_local)) {
config.resolve.alias['@needle-tools/gltf-progressive'] = gltfProgressive_local;
}
else {
config.resolve.alias['@needle-tools/gltf-progressive'] = path.resolve(workingDirectory, 'node_modules/@needle-tools/gltf-progressive');
}
const packageJsonPath = path.resolve(workingDirectory, 'package.json');
// now resolve all local package dependencies
if (existsSync(packageJsonPath)) {
/**
* @type {{ dependencies?: { [key: string]: string } }}
*/
const packageJson = require(packageJsonPath);
if (packageJson?.dependencies) {
for (const key of Object.keys(packageJson.dependencies)) {
const value = packageJson.dependencies[key];
if (value.startsWith("file:")) {
const pathValue = value.substring(5);
config.resolve.alias[key] = path.resolve(workingDirectory, pathValue);
}
}
}
}
}