Can some one shed any light on this weird issue i've been having.
I have a project of the following shape:
index.js
src/
static/
favicon.ico
styles.css
server.js
routes.js
app.jsx
//[...]
dist/
/static
favicon.ico
styles.css
server.js
The /src
dir gets compiled (via webpack) and uglified out into a /dist
dir. The index.js
in the root project directory is just a simple switch that requires /dist/server.js
if NODE_ENV=production
, and reqiures /src/server.js
if in development.
The issue i'm having is that __dirname
and __filename
behave as expected when running in development --- correctly reporting the directory each executed file is in. However, when running in production, the only directory getting reported is the root directory where index.js
is. dist/server.js
does not seem to recognise that it's inside a /dist
folder, it seems to now think it's inside the project root. Weird!!
What's happening here? Why does the minified dist/server.js
think it's nested within ./index.js
, but the non minified src/server.js
correctly recognises its within the src/
dir?
Is this webpack/uglify transforming things it shouldn't, or is this just the nature of minified code running in production? I'm struggling to find a work around, which is making setting dist/static/
as the correct static dir in production rather difficult.