Skip to content

Hello AssetMapper Documentation #18370

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

Closed
wants to merge 14 commits into from
Closed

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Jun 3, 2023

Hi!

I wrote some docs! This covers all the important things that I can think of right now :). I'd appreciate any reviews.

Post-Merge Symfony.com TODOs:

Thanks!


frontend/asset_mapper/installation
frontend/asset_mapper/usage
frontend/asset_mapper/*
frontend/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bottom of https://symfony.com/doc/current/frontend.html is currently "wonky". I think the intention was for the the first, :hidden toctree to "load" all of the encore stuff into the toctree... and then this bottom toctree would only load anything "remaining". In practice, it would render everything.

So, I reduced this to just ONE toctree, which is :hidden:. The 2 documents that are outside of encore/* were added manually under the Other Front-End Articles section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, including documents in a toctree entry is no longer relevant with the PHP based parser IIRC

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That IS a fun fact, thank you!

frontend.rst Outdated
create static CSS and JS files in your ``public/`` directory directly and
include them in your templates.
Symfony Frontend Tools
======================
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This document is now a bit more important than before. On https://symfony.com/doc/current/index.html, I don't think we link to it at all. After we merge this, we probably should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Webpack Encore" is linking to it. We should probably do the same as with Security and call it "Introduction"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I added some TODO to the PR description for post-merge changes to the main documentation page.

@weaverryan
Copy link
Member Author

This is ready to go! About the Code Blocks failure - I've added symfony-tools/symfony-application#16 - but it looks like it's using the 5.4 version of the app, and I'm not sure why.

Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. A cool feature just got cool new documentation 😎

frontend.rst Outdated
create static CSS and JS files in your ``public/`` directory directly and
include them in your templates.
Symfony Frontend Tools
======================
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Webpack Encore" is linking to it. We should probably do the same as with Security and call it "Introduction"?

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ryan, thanks a lot for this massive contribution. The new docs are fun to read and super easy to follow. Thanks!

@wolviey
Copy link

wolviey commented Jun 5, 2023

I really like all the hard work on assetmapper . its really great, just i wonder is there a way to extend functionality of assetmapper like some php handlers ? i didnt see it in documentation, missed out or not a functionality yet ?

@Hanmac
Copy link

Hanmac commented Jun 5, 2023

general question about the AssetMapper stuff
if for example i have some sass/scss stuff, but i don't want to use NoteJS and Webcore,
the AssetMapper could still be helpful for me, right?

@weaverryan
Copy link
Member Author

Tweaks handled! Thank you for the HUGE review on a big document (and very fast) ❤️

@wolviey: i wonder is there a way to extend functionality of assetmapper like some php handlers

What kind of extending are you imagining? There is an "asset compiler" system where you can parse and modify the contents of any file in asset mapper. It's a bit more advanced, so I didn't document it on this first pass. You can also decorate a "public path resolver" to change the final, public paths of files.

@Hanmac: i have some sass/scss stuff, but i don't want to use NoteJS and Webcore, the AssetMapper could still be helpful for me, right?

Yes :). This is in the new docs. Fortunately, you can download a standalone dart-sass binary to compile your Sass code, which doesn't require Node or Webpack. I think we could make the process of executing this binary even easier, but it's straightforward and (hopefully) well-documented in this new doc.

@wolviey
Copy link

wolviey commented Jun 5, 2023

@wolviey: i wonder is there a way to extend functionality of assetmapper like some php handlers

What kind of extending are you imagining? There is an "asset compiler" system where you can parse and modify the contents of any file in asset mapper. It's a bit more advanced, so I didn't document it on this first pass. You can also decorate a "public path resolver" to change the final, public paths of files.

Thanks for awesome documentation and good work, easy to read and understandable. Thought things like, people can have tools for custom optimizations on css or js for special to their projects, I wondered is't possible to use assetmapper with custom optimization tools at compile time.

@weaverryan
Copy link
Member Author

Thanks for awesome documentation and good work, easy to read and understandable. Thought things like, people can have tools for custom optimizations on css or js for special to their projects, I wondered is't possible to use assetmapper with custom optimization tools at compile time.

The answer is probably yes, and it would be by creating an asset compiler (you can see a few in core - one for js files and 2 for CSS files). With these, you could take the source of a file and change it - like minifying it (not, while that’s possible, that’s better left to the server). In practice, I don’t know yet how useful this stuff will be for that purpose… we’ll see what people come up with. And we may need to add even more hook points depending on what people want to do.

@wolviey
Copy link

wolviey commented Jun 5, 2023

Thanks for awesome documentation and good work, easy to read and understandable. Thought things like, people can have tools for custom optimizations on css or js for special to their projects, I wondered is't possible to use assetmapper with custom optimization tools at compile time.

The answer is probably yes, and it would be by creating an asset compiler (you can see a few in core - one for js files and 2 for CSS files). With these, you could take the source of a file and change it - like minifying it (not, while that’s possible, that’s better left to the server). In practice, I don’t know yet how useful this stuff will be for that purpose… we’ll see what people come up with. And we may need to add even more hook points depending on what people want to do.

Thank you so much for showing way of do this. :) At my side, i have my own typescripts and i like to compile them before deploy automatically. normally i do it with script. collecting all typescripts compile them. some optimizations with css (minification removing unused stuff etc) html and js afterwards and publish the latest html css and js files. what assetmapper give duplicate of this work and also in better some places. thats why i thought it can be good idea to merge them (need to check possible or not) . at server every request doing minification even with locks scary for my part when there can be 1000 page request same time. i prefer to do it offline before deployment. And assetmapper really make this things more less config necessary way. i hope there will more hook points :) Assetmapper Itself is great idea honestly.

@weaverryan
Copy link
Member Author

I think this is ready to go :)

{% endblock %}

If you'd rather download the CSS file and include it locally, you can do that.
For example, you could download it to ``assets/vendor/bootstrap.min.css`` and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a manual process or done via a command?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently manually - I've clarified the wording to be more clear :)

@javiereguiluz javiereguiluz added this to the 6.3 milestone Jun 6, 2023
@weaverryan
Copy link
Member Author

FYI - this is still ready to go, but I also added a new section about page-specific JavaScript, per @bendavies question on Slack :)

@weaverryan weaverryan closed this Jun 7, 2023
weaverryan added a commit that referenced this pull request Jun 7, 2023
This PR was squashed before being merged into the 6.3 branch.

Discussion
----------

Hello AssetMapper Documentation

Hi!

I wrote some docs! This covers all the important things that I can think of right now :). I'd appreciate any reviews.

### Post-Merge Symfony.com TODOs:

* [ ] On https://symfony.com/doc/current/index.html, add an `Introduction` link under `Front-End` that links to https://symfony.com/doc/current/frontend.html
* [ ] Update the `Webpack Encore` link on that same page to... probably https://symfony.com/doc/current/frontend.html#webpack-encore ?

Thanks!

Commits
-------

ef77936 Hello AssetMapper Documentation
Comment on lines +237 to +239
This will download the package into an ``assets/vendor/`` directory and update
the ``importmap.php`` file to point to it. You *should* commit this file to
your repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the vendor directory should also be committed or should be gitignored ? In that case, is the recipe add the folder to gitignore ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! You can't actually commit directories to git - only files. But the meaning here is that you "commit the vendor/ directory and all files inside to git". So the assets/vendor/ directory should NOT be ignored :)

@seb-jean
Copy link
Contributor

seb-jean commented Jun 9, 2023

Hi,
What is the reason for closing this PR?

@Kocal
Copy link
Member

Kocal commented Jun 9, 2023

The PR has been merged, but GitHub does not show as is

@seb-jean
Copy link
Contributor

seb-jean commented Jun 9, 2023

Thanks 👍

@seb-jean
Copy link
Contributor

How can we manage fonts? Is it different with AssetMapper? Is there a good practice?

@weaverryan
Copy link
Member Author

How can we manage fonts? Is it different with AssetMapper? Is there a good practice?

Good question - it's the same as 3rd party CSS:

A) Search on jsdelivr.com for the font you want. from fontsource - e.g. https://www.jsdelivr.com/package/npm/@fontsource/roboto
B) Copy the link tag from this page into base.html.twig (or, if you want to avoid a CDN, manually download this into assets/vendor/ (e.g. assets/vendor/roboto.css), commit that file, then include a link tag with {{ asset('vendor/roboto.css') }}.

It's "simple" but I would love if it were easier - it may be for 6.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants