Parcel: Why I use "parcel watch src/index.html", and then generated dist/index.html has Wrong path about I want to import the JS and CSS file

Created on 9 Dec 2017  路  10Comments  路  Source: parcel-bundler/parcel

Choose one: is this a 馃悰 bug report or 馃檵 feature request?
bug report

This is my This is my contents of dist/index.html.

<html><head>
    <link rel="stylesheet" href="/dist/70ff6adcda1019612606fd7515c8afe8.css"></head><body>
        <div id="root"></div>
        <script src="/dist/70ff6adcda1019612606fd7515c8afe8.js"></script>
    </body>
</html>

_017

馃敠 Context

Most helpful comment

parcel build index.html --public-url ./

Will solve the issue of the invalid path to js and CSS files.

All 10 comments

What's wrong with the path? It looks fine

He probably just opened the index.html file in the browser and then it doesn't load js and css due to this using absolute paths. Or he pointed his webserver to another directory than the www directory in the screenshot which would also cause this.

When you build the output you can use --public-url argument to specify the root. For example:
parcel build index.html --public-url='/'

@davidnagli @DeMoorJasper I doesn't look fine. The script tag of the generated HTML file includes dist/xxxxxx.js but the REAL path of that js file is ./xxxx.js. The generated js file and the HTML file are in the same dist directory actually. How do I fix this?

Based on the screenshot you sent, the real path of the file should be dist/xxxxxx.js, not ./xxxx.js

I'm really sorry if I'm still misunderstanding you

Maybe you're looking for the --out-dir command, which would let you specify the output directory

Note: an alias for --out-dir is -d (they both do the same thing.

Example usage:

parcel src/index.html -d build

@davidnagli Thanks. It works.

@davidnagli Is there a way to use the relative path instead of absolute path?
A common practice is to output the html, js and css to public dir, and host the public dir as the root dir.

parcel build index.html --public-url ./

Will solve the issue of the invalid path to js and CSS files.

I have tried all of the solutions above, but I still get the compiled index.html pointing to
<script src="/dist/......js"></script> instead of src="....js"

If I want to compile everything into a single dist/ folder and serve that folder, how can I make sure the paths are correct?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

philipodev picture philipodev  路  3Comments

termhn picture termhn  路  3Comments

466023746 picture 466023746  路  3Comments

donaldallen picture donaldallen  路  3Comments

mnn picture mnn  路  3Comments