So I am currently using ThreeJS module using the standard importmap (“three” and “three/addons/”). Now I would like to use the postprocessing library from pmndrs so that those import directives on “postprocessing” works, but I could not find the JavaScript module file needed for that. I looked in their GitHub page, but all I see are the effect JavaScript files and nothing like postprocessing.module.js or something.
do not use import maps. use vite like the docs say: three.js docs
you can’t expect any npm library to work through import maps because it’s an unfinished spec that doesn’t reflect the real world (npm is to a large degree commonjs). you get no benefits, everything takes longer and is more complex, involves manual work, you still rely heavily on tooling (servers etc), things won’t work, your bundles are huge without minification or tree-shaking — basically you are not ready for production.
npm create vite
# pick projectName
# pick javascript
cd projectName
npm install three @types/three postprocessing
npm run dev
now every change you make in the editor will be reflected in the browser
import * as THREE from 'three'
import { EffectComposer } from 'postprocessing'
...
run this to obtain a minimised, tree-shaked smallest-possible /build that you can upload to a hoster
Just going to test that a bit more. I wish I could just download the entire ZIP from GitHub and point to those local files like I used to do with the ThreeJS module. If that is not possible with this postprocessing package, then so be it.
Your imports in your js module will look like this
import * as THREE from 'three'
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
import { BloomEffect, EffectComposer, EffectPass, RenderPass } from 'postprocessing'
Maybe there is a tool that can download, edit and save esm modules locally for offline use. I don’t know of any.
Manually downloading modules and editing them to work with your own importmaps is a lot of work and prone to errors.
Perfect! I have changed the URL inside the module to point to the importmap value and it works great! I have applied that technique where I imported my custom JavaScript modules and used local URLs in each import and now I only need to modify them in 1 file (index.js).
I will keep you guys advice on using a bundler. Proably will look into that more when I’m almost done this project.