__dirname is not working in node js with webpack bundling

后端 未结 2 1361
孤独总比滥情好
孤独总比滥情好 2021-02-19 21:36

My current directory is

D:\\bkp\\Programming\\TestWorks\\nodejs\\testApp

but when i am using __dirname and trying to show a file

2条回答
  •  时光取名叫无心
    2021-02-19 22:34

    The __dirname is set to / by webpack, that's why you end up with /views/index.html which is the root of your file system, that happens to be D:\ in your case. You can set node.dirname to false in your webpack config to not inject it and defer it to runtime. Keep in mind that __dirname will refer to the location of the script you're executing, that means the location of the bundle, not the original source.

    node: {
      __dirname: false
    }
    

提交回复
热议问题