-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parcel ignores resources declared in JS template literals #3553
Comments
I don't know if this works with the import { html } from 'lit-element';
import global from "/css/global.css"; // is the path to the bundles css file
export default (element) => html`
<link rel="stylesheet" href="${global}">
<h1><slot></slot></h1>
`; |
No sadly it doesn't, that's what I meant when I mentioned the 'JSX pattern' not working |
With Parcel 2, a custom transformer could easily do |
I would also add I've now discovered Parcel appears to ignore attributes on Web Components custom elements entirely. For example, implementing a custom |
You mean when using the element in an html file? The issue here is that Parcel needs to know which attributes to process, there is for example no inherent difference between |
From a dev perspective it should be simple enough to see if a 404 matches an asset in the source path and then add that attribute and asset to the build, but that doesn't really work for a prod build. One solution might be to process all attributes on unknown elements, then dynamically add that attribute into a known list if it maps to an asset URL. That way the attribute source list can be built at compile time by the first instance discovered. |
That way you wouldn't notice a typo in a filename.
I think it would be easier (and less error prone) to have a config file where you specify elements and attributes to process. |
I can see your point, but then I'm actually tying my build process into the specifics of the underlying code. Now when a developer changes some attribute in code he now needs to modify the build process config too. It all starts moving away from Parcel's zero-config approach too. Personally, I'm not keen on the existing asset/attribute detection anyway, I've already had to fork HTMLAsset.js and |
I don't like saying this either but: zero-config has technical limits.
If we just transformed every HTML attribute that looks like a file, our issue track would be full of this.... What would be acceptable for you (between manual config and error-prone automatic detection)? |
The same issue occurs in JSX. You can't write |
@nstansbury this seems to work: https://codesandbox.io/embed/parcel-issue-3553-1dobw import { html } from "lit-html";
import img from "./img.png";
export const App = () => html`
<div>
<img src="${img}" />
</div>
`; |
I can't comment on images specifically as this bug was originally about stylesheets, following the JSX pattern above generates:
Not sure why this issue is closed unless I'm missing something? |
The issue here is that This issue is not really specific to lit-html, you can follow this proposal about being able to specify the format of the import: #3477 |
I've been caught out with this a few times too. Is it too heinous to suggest parcel might support adding an attribute in the template literal to ensure parcel resolves it an associated
And parcel could strip this |
One Year Later Here. |
🐛 bug report
LitElement declares its ShadowDOM HTML in JavaScript template literals. When CSS files or other assets are declared inside the literal string Parcel doesn't bundle them. CSS is especially relevant to allow CSS files to be injected into the ShadowDOM. Eg:
The JSX pattern for including resources does not work for template literals
🎛 Configuration (.babelrc, package.json, cli command)
parcel --port 8080 --https ./src/index.html --cache-dir ./build/cache --out-dir ./build/make
🤔 Expected Behavior
Assets declared in JS template literals are bundled as normal
😯 Current Behavior
The assets included in the template strings are ignored.
💁 Possible Solution
a) Parcel should parse JS template literals for resources and include them
b) Allow specific resource path strings to be mapped and replaced during the build process
c) Import a
path
variable that can be included in the template literal as a variable🔦 Context
Build WebComponents using JavaScript template literals
💻 Code Sample
🌍 Your Environment
The text was updated successfully, but these errors were encountered: