添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

🐛 Bug report

While building or running in dev mode with parcel, if I include manifest.json in html, then parcel return's me .js file path.

🤔 Expected Behavior

<link rel="manifest" href="/dist/manifest.json">

😯 Current Behavior

<link rel="manifest" href="/dist/05bfa35095e6bfacdb8b334d1023872b.js">

🌍 Your Environment

Thanks for reporting this 😀

It looks like you have a mistake in your code. Instead of using the path to the manifest.json in dist , you should be setting the path to your original manifest.json , and Parcel will handle transforming it to the correct path within dist .

You should be doing something like:

<!-- Assuming your manifest.json file is in a directory called src -->
<link rel=“manifest” href="/src/manifest.json">

I'm happy to take this on, as it is a bit of a blocker for me for migrating a couple of PWAs to parcel.

My questions:

  • Would it make more sense to just consider manifests something that should be ignored? (it'd be easy to add an exclusion for <link/> tags with a rel='manifest' .
  • If not, is there a way to add an option here: https://github.com/parcel-bundler/parcel/blob/master/src/assets/HTMLAsset.js#L49 that specifies that it should be kept "raw" in that circumstance?
  • @devongovett any guidance?

    Ah interesting issue. The type needs to be js so JSON files can be imported from JavaScript. Ideally the assets could return multiple renditions of different types and the correct one could be chosen based on the parent asset type. Let me think about this a bit and see what I can come up with. If you have suggestions on how this could work let me know!

    @devongovett it's weird, because how to handle this file can't be inferred from its file type. This isn't a JSON file that needs to be read and used as a module, it's just a JSON file that needs to be copied into the build directory. I started in on this by adding a check to determine if the link tag has a ‘rel=manifest‘. It'd be cool if addURLDependency took an option to specify that it should be "raw".

    Hi @devongovett , I faced something similar working with the implementation of rust/wasm.
    My case was that I needed to make some difference between the wasm files that were called from html file or the js files.

    So I came up with this:

    -let assetPath = this.addURLDependency(node.attrs[attr]);
    +let assetPath = this.addURLDependency(node.attrs[attr], {
    +  fromHtml: true
    + });

    I'm not sure if this is the best way to do it, but it works 😄
    you can see the changes in my PR #312

    but I think your idea using the parent's type is a better way to do it.

    @albinotonnina wouldn't it be a better idea to make from a more generic field like

    let assetPath = this.addURLDependency(node.attrs[attr], {
      from: asset.type
    

    resolving into

    let assetPath = this.addURLDependency(node.attrs[attr], {
      from: 'html'
    

    I'm not sure but thought there was a way to address the parent element already, i might be mistaken

    With all the years of experience I've had thinking about these graph problems while implementing Assetgraph, I can tell you that you won't be able to infer from the asset alone what format you need to keep it in. Knowing the parent type will only be enough in the most naive cases as well. What you need is a model that also keep the information of what type of relation is between these two assets.

    In Assegraph each way any asset can refer to a different asset is modelled as different relation type. This information has turned out to be much more valuable than the assets themselves, as you can infer a lot of things from the relation types alone. It's especially valuable when you start to traverse the graph for processing.

    In this single case you might be able to hack it with a condition that excludes json files linked from html from being interpreted as js. But a bit further in the future you might want to cover the case where fetch('data.json') is picked up as a file reference, and the application logic of runtime json loading would fail if the file changes extension as well.

    You probably also want to start treating the webmanifest as a separate asset type inheriting from JSON, since it has well defined properties that also describe asset relations.

    Just got here after some searching because I hit this very issue myself while trying to create a PWA with a manifest.json file.

    I think that in general, the most flexible thing from an HTML entry point would be to have some data attribute that we could use to manually tell Parcel.js NOT to process the file.

    Something like this:

    <link rel=“manifest” href="/src/manifest.json" data-parceljs-ignore>

    That data attribute would then be noted, processing would be skipped for that file, and the resulting output would remove the data attribute without doing any processing on the file at all:

    <link rel=“manifest” href="/src/manifest.json">
    esaramago, akshaysmurthy, amir20, martingeorgiu, kcoyner, Tanoemon, judas-christ, msanatan, hanshou101, amazingandyyy, and 23 more reacted with thumbs up emoji gonzaloriestra, raphaklaus, arturh85, lichenglu, amir20, martingeorgiu, tamlyn, kcoyner, Mindcraft1, sbward, and 14 more reacted with hooray emoji All reactions digitalbocca, keemor, cheeaun, lichenglu, krnlde, joseluisq, rjoydip-zz, MakChan, augnustin, viktordineout, and 16 more reacted with thumbs up emoji aminnairi, raphaklaus, rrjoson, viktordineout, kcoyner, LifeOfQui, izn, lucasreppewelander, au5ton, nish17, and hanquf1 reacted with hooray emoji hanquf1 and Alabs02 reacted with heart emoji All reactions
    This caused the PWA to open in a full browser on iOS
    - Rename manifest.json to manifest.webmanifest (parcel-bundler/parcel#235 (comment))
    - Include the new manifest file in index.html

    @devongovett @DeMoorJasper hey! Just wanted to drop a quick note here for parcel v2. In talking to some friends at Google, it's important for how browsers handle web manifests specifically that the final filename stays the same between builds.

    Otherwise it's interpreted as a different app, somehow. Maybe @slightlyoff or @addyosmani can elaborate a bit.

    In order to work around this I've had to do some HTML manipulation after the fact to inject the manifest.

    I just wanted to drop note in hopes that there would be some way to control the final filename in v2.

    Thanks for all your work on Parcel! ❤️

    Hey there. My use case is probably different: I've used create-react-app and now want to have a relatively easy (few mangling steps) way of bundling all assets with parcel--which BTW works awesome, not requiring to eject!

    And I simply wanted to say it'd be great if there was a way to bundle/build with a tag/token of sorts that copies the original manifest.json file into the build folder (with that filename) and keeps the original content (link tag with rel="manifest" and href="/manifest.json" fields), even if in the original index.html file another tag (e.g. parcel-asset-copy-only) needed to be added, which I could do pre-build...

    As a first pass, it's not too many steps:
    https://github.com/neuroelf/dermodelphi/blob/master/README.md#building-with-parcel-without-minification

    Anyway, great project!! :)

    Given the discusison here: parcel-bundler/parcel#235
    This needs to be done for parcel not to rename it as a json file
    refs #82

    How about putting manifest.json as an entry point? Then we know it shouldn't be renamed or converted to a module.

    This is what I had in mind:
    parcel src/manifest.json src/*.html src/*.js --hmr-hostname localhost

    Parcel currently converts the manifest to a module even though it isn't referenced in any code.

    * I later found the plugin for browser addons.

    I was using the manifest.json naming convention from the Google Web App Manifest documentation. While MDN was using the manifest.webmanifest naming convention. Using the later solved the issue (which was Parcel.js converting the manifest.json to a javascript file). Hope this helps!

    This worked for me,

    @GeoffMahugu is .webmanifest still working for you?

    Yes it is, I have my index.html and manifest.webmanifest in src folder and this is how I reference the file in the index:

    on running parcel src/index.html should serve the manifest file.