Note: The Listed platform will permanently shut down December 31, 2026. Your data published on Listed will still be available in your personal Standard Notes account. Learn more

How to Make Webpack and Import Statement in JavaScript Understand the Same Paths

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.


You'll only receive email when they publish something new.

More from Arno
All posts