How to Make Webpack and Import Statement in JavaScript Understand the Same Paths
January 19, 2024•72 words
Example project structure
project/
src/
mod1/
mod2/
app.js
mod1 (symbolic link) -> src/mod1
mod2 (symbolic link) -> src/mod2
pack.sh
Inside JavaScript code
import mod1 from "/mod1/file.js"
import mod2 from "/mod2/file.js"
When run Webpack inside pack.sh, all the root slashes will make Webpack to find in src dir instead of current working directory.
Browser also understand the same, the root slash means from src dir, if Ngix aliasing there.