简体   繁体   中英

Wrong root with JavaScript debug

I'm using IntelliJ ultimate and working on an early POC for a web application I'm going to develop. I'm learning how to use webpack for the first time in this, and I'm pretty certain that things are configured properly (since the CLI did all the heavy lifting for me).

Here is the HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>my-app</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="/dist/build.js"></script>
  </body>
</html>

When I run this using IntelliJ's JavaScript debug configuration, it opens a URL with this address: "http://localhost:63342/my-app/index.html?_ijt=854p8s3lp1diu87uinl4mdripi". This URL doesn't resolve, because /dist/build.js doesn't resolve. If I change it to /my-app/dist/build.js, it will work.

I want to ditch the my-app part of that URL, since it won't be a part of the URL in any production version of an application, it's just the directory name. What can I do to fix this?

the built-in webserver serves files from http://localhost:63342/<project root> . Forward slashes in URLs tell the browser to resolve them relative to the web server root ( localhost:63342 ), causing 404 errors.

If you like to use URLs relative to server root (the ones starting with slash), you have to change the default web path on built-in web server (to map your project to the server root). To do this, you need editing your system hosts file accordingly - see http://youtrack.jetbrains.com/issue/WEB-8988#comment=27-577559 . Or, just use a 'normal' web server (Apache, etc.) to host your files and configure it in the way you like

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM