Parcel: How can I ignore the automatic resolution of a image path?

Created on 12 Feb 2019  路  5Comments  路  Source: parcel-bundler/parcel

I'm trying to use the plain text feature of Pug to define the content of a <img> tag based on a variable value. I have a boolean variable that defines when I'm in "development mode". When this value is set to false I would like to use a raw string that will be processed by my server (it is a Flask application).

So I've tried this:

if development
   img#qr-code(src='https://via.placeholder.com/300')
else
   | <img src='{{ qrcode }}' id='qr-code'>

I'm expecting on development mode:

<img id='qr-code' src='https://via.placeholder.com/300'>

And, for production:

<img src='{{ qrcode }}' id='qr-code'>

When I compile it with - var development = true, everything works.
But, when I use - var development = false, it fails.

$ parcel src/template/*.pug

Server running at http://localhost:1234
脳 C:\Users\renan\Desktop\development\parcel-test\src\template{{ qrcode }}: ENOENT: no such file or directory, open 'C:\Users\renan\Desktop\development\parcel-test\src\template{{ qrcode }}'

Error: ENOENT: no such file or directory, open 'C:\Users\renan\Desktop\development\parcel-test\src\template{{ qrcode }}'

I think that Parcel is trying to resolve the image path in {{ qrcode }}, because the problem is not in Pug. How can I ignore or bypass it? I would like to have the raw string.

Question

All 5 comments

How can I ignore or bypass it?

Currently, this is unfortunately not possible.

Why is parcel trying to process plain text? It shouldn't be in that part of the AST, should it? If that's the intention, why? I don't see the use case.

There is no way to tell if a url is a url or plain text.
A url can be anything as we don't require it to be preceded by a ./ or / or ~/.
So {{ qrcode }}, could in theory just be a file ./{{ qrcode }}.

If we would require it to be preceded by something like ./ it would be possible but would deviate from expected html behaviour afaik

@DeMoorJasper ah, I see. I thought pug HTML escapes plain text, but I can see now it doesn't. I saw this issue and was thinking any URL in plain text was processed, but clearly, this is only an issue if you are embedding HTML into pug which seems like a strange thing to do anyway. Thanks for satisfying my curiosity.

Closing as duplicate of #1186

Was this page helpful?
0 / 5 - 0 ratings