Chapters
48 Chapters
|
5:05:52
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
05.
CSS: Styling a Component
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
This course is also built to work with Vue 3!
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@symfony/webpack-encore": "^0.30.0", // 0.30.2
"axios": "^0.19.2", // 0.19.2
"bootstrap": "^4.4.1", // 4.5.0
"core-js": "^3.0.0", // 3.6.5
"eslint": "^6.7.2", // 6.8.0
"eslint-config-airbnb-base": "^14.0.0", // 14.1.0
"eslint-plugin-import": "^2.19.1", // 2.20.2
"eslint-plugin-vue": "^6.0.1", // 6.2.2
"regenerator-runtime": "^0.13.2", // 0.13.5
"sass": "^1.29.0", // 1.29.0
"sass-loader": "^8.0.0", // 8.0.2
"vue": "^2.6.11", // 2.6.11
"vue-loader": "^15.9.1", // 15.9.2
"vue-template-compiler": "^2.6.11", // 2.6.11
"webpack-notifier": "^1.6.0" // 1.8.0
}
}
21 Comments
Here's a warning I see in my console (using Vue 3).
<blockquote>
Feature flags VUE_OPTIONS_API, VUE_PROD_DEVTOOLS are not explicitly defined. You are running the esm-bundler build of Vue, which expects these compile-time feature flags to be globally injected via the bundler config in order to get better tree-shaking in the production bundle.
For more details, see https://link.vuejs.org/feature-flags.
</blockquote>I was about to ask you to spoon-feed me the answer but then sighed and did my own homework like a good citizen. :-) PhpStorm's hinting and autocompleting makes it so easy even a noob can muddle through! You can get rid of this warning by adding this to webpack.config.js:
Thanks for the tip!
In general, I would assume you could leave these flags undefined, but it definitely helps to have them!
Hey friends! We miss the code block in every video. It’s important to copy and paste in our code. The final code inside the dos loas its diferent than the current in each video. For example: all the css and html in this video. I hope yo can put them in every video like always.
Thanks
hi Alberto
Here the code :
https://github.com/SymfonyC...
Wow, thanks!
Hey It O.
We are sorry about that, we have a little internal process where we add "code blocks" to the page - so they are not available immediately when chapter is released. We understand that it's a bit odd because Ryan said "copy the HTML from this page!"... but there is no HTML...yet
Anyways code blocks will be able soon!
Thanks for your attention to the details and watching new chapter as soon as it was released we really appreciate it!
Cheers!
I have a problem when i try to inject the <style>. It doesnt give an error but it does not give the syle to the page, what could be the problem?
Hmm, I'm actually not sure :/. Parsing the
<style>tag is the job of Webpack + the vue-loader that works with Webpack. I would try mis-typing style - e.g.<stly>just to see if you can trigger a build error in Webpack (and thus, make sure it's parsing this file correctly).Cheers!
Hey Ryan + Team,
I know this issues does not really belong to this lecture, however, I could not find any solution to my issue in other lectures or on the web, so I decided to ask this here.
The point is, that I want to use a static image inside my vue component. The image lives in assets/static/images/image.jpg.
Referencing the image with
<img src="/build/images/image.jpg">does work, however, I am using.enableVersioning(Encore.isProduction())in my webpack.config.js. So with hashing I don't know how to reference my image anymore since the hash changes for every build.In twig this is usually handled like this, as far as I know:
src="{{ asset('build/images/image.jpg') }}"(from manifest.json)Is there a way to handle this problem in vue as well? :-)
Cheers!
Hey @Luca!
Great timing on this - I just answered this question a day or two ago :). The tl;dr is that it's easy! But... due to bad behavior between a few libraries... it's only kinda easy :p. Here is the answer: https://symfonycasts.com/sc...
On a philosophical Webpack level, the answer is "just import the image in the same way you would import another JavaScript file", which is kinda cool ;).
Let me know if that helps!
Cheers!
Hey! It does not work for me. If I write simple css at the end of my vue-file, it will not include anything. It is simply ignored and does not work at all. Any ideas? I've done everything one-to-one...
Hey @Jakob!
Hmm. Can you post your Vue file for us? I know you're doing everything one-to-one, but maybe there is something tiny that's wrong - that's the hardest stuff to find :). Also, what version of vue, vue-loader, vue-style-loader and vue-template-compiler do you have? You can find this by running
yarn list --depth=0.Oh, and two more things - if you view source on the page, do you see a link tag for products.css? I want to make sure that is being included on the page (it is if you started with our code), And finally, when you run
yarn watchwhat files does it say it is rendering? Do you see a products.css there?Cheers!
Hey, thank you for your answer!
├─ vue-hot-reload-api@2.3.4
├─ vue-loader@15.9.3
├─ vue-style-loader@4.1.2
├─ vue-template-compiler@2.6.11
├─ vue-template-es2015-compiler@1.9.1
├─ vue@2.6.11
I've just a style tag in the end of the template🙂
I am one step further: The .css is packed into the js directory, but it is not included on the page
I fixed it - Thank you very much for your answer :)
Hey @Jakob!
Nice work! What was the final solution?
Cheers!
Hey!
I think one package was missing, I deleted node_modules and ran yarn install again :) It was a little weird, but now it works perfectly😀
Hey! unfortunately i have the same problem and this solution didn't work. The css file is not created ☹️
Hi Caprarolainfo!
Can you tell us a little bit more about your issue? Have you looked into your packages.json to see if your packages are all there and are the latest versions? That does seem like a webpack issue to me!
Let me know what you can find!
Hi Matias Jose!
Sorry if I wasted your time, I found the problem. 😳I wrote the link encore_entry_link_tags wrong. Now everything works.
Thanks so much
No problem! I'm glad you've found it! :)
"Houston: no signs of life"
Start the conversation!