Chapters
46 Chapters
|
4:55:39
|
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!
28.
Webpack Bundle Analyzer
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!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial works perfectly with Stimulus 3!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1", // 1.11.99.1
"doctrine/annotations": "^1.0", // 1.11.1
"doctrine/doctrine-bundle": "^2.2", // 2.2.3
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.8", // 2.8.1
"phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
"sensio/framework-extra-bundle": "^5.6", // v5.6.1
"symfony/asset": "5.2.*", // v5.2.3
"symfony/console": "5.2.*", // v5.2.3
"symfony/dotenv": "5.2.*", // v5.2.3
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/form": "5.2.*", // v5.2.3
"symfony/framework-bundle": "5.2.*", // v5.2.3
"symfony/property-access": "5.2.*", // v5.2.3
"symfony/property-info": "5.2.*", // v5.2.3
"symfony/proxy-manager-bridge": "5.2.*", // v5.2.3
"symfony/security-bundle": "5.2.*", // v5.2.3
"symfony/serializer": "5.2.*", // v5.2.3
"symfony/twig-bundle": "5.2.*", // v5.2.3
"symfony/ux-chartjs": "^1.1", // v1.2.0
"symfony/validator": "5.2.*", // v5.2.3
"symfony/webpack-encore-bundle": "^1.9", // v1.11.1
"symfony/yaml": "5.2.*", // v5.2.3
"twig/extra-bundle": "^2.12|^3.0", // v3.2.1
"twig/intl-extra": "^3.2", // v3.2.1
"twig/twig": "^2.12|^3.0" // v3.2.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.0
"symfony/debug-bundle": "^5.2", // v5.2.3
"symfony/maker-bundle": "^1.27", // v1.30.0
"symfony/monolog-bundle": "^3.0", // v3.6.0
"symfony/stopwatch": "^5.2", // v5.2.3
"symfony/var-dumper": "^5.2", // v5.2.3
"symfony/web-profiler-bundle": "^5.2" // v5.2.3
}
}
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@babel/preset-react": "^7.0.0", // 7.12.13
"@popperjs/core": "^2.9.1", // 2.9.1
"@symfony/stimulus-bridge": "^2.0.0", // 2.1.0
"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets", // 1.1.0
"@symfony/webpack-encore": "^1.0.0", // 1.0.4
"bootstrap": "^5.0.0-beta2", // 5.0.0-beta2
"core-js": "^3.0.0", // 3.8.3
"jquery": "^3.6.0", // 3.6.0
"react": "^17.0.1", // 17.0.1
"react-dom": "^17.0.1", // 17.0.1
"regenerator-runtime": "^0.13.2", // 0.13.7
"stimulus": "^2.0.0", // 2.0.0
"stimulus-autocomplete": "^2.0.1-phylor-6095f2a9", // 2.0.1-phylor-6095f2a9
"stimulus-use": "^0.24.0-1", // 0.24.0-1
"sweetalert2": "^10.13.0", // 10.14.0
"webpack-bundle-analyzer": "^4.4.0", // 4.4.0
"webpack-notifier": "^1.6.0" // 1.13.0
}
}
15 Comments
On my windows 10 env I've got a syntax error runing webpack-bundle-analyzer command because the json file had a BOM.
Couldn't read webpack bundle stats from "D:\STINO\code-stimulus\mine\stats.json":<br />SyntaxError: Unexpected token � in JSON at position 0I removed the BOM and it worked !
how did you remove it I have the same issue
I guess just by removing the first (invisible) character ?
Well I tried that firstly there isn't anything to see in notepad. So i searched online and found the following.
info
So I used Hex Editor Neo and found spurious characters prior to the opening curly brace and deleted those. Then re ran the webpack analyzer and got this new error..
Couldn't read webpack bundle stats from "C:\Apache24\htdocs\symfonyux\stats.json":
SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
screenshots
Hey Stuart,
Hm, probably try to open that file in the IDE like PhpStorm, it has syntax highlighting for JSON files, probably it will hint you on the problematic spot. Or try some online json validators - may help as well.
Cheers!
lol going round in circles every time I delete the characters and rerun the analyzer they just re-appear. Think I will have to find another method possibly.
Hey Stuart,
Are you on Windows? It might be related I think. you need to try change that file in a different editor, probably with the correct chartset/encoding.
I hope that helps!
Cheers!
Apologies for the delay been doing the family guy stuff over xmas...
Yes a windows machine and i normally use VS code so Ill try phpstorm to check the characters.
phpStorm gave the same problem..
yarn run v1.22.22
$ C:\Apache24\htdocs\symfonyux\node_modules.bin\webpack-bundle-analyzer stats.json public/build
Couldn't read webpack bundle stats from "C:\Apache24\htdocs\symfonyux\stats.json":
SyntaxError: Unexpected token '�', "��{"ha"... is not valid JSON
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS C:\Apache24\htdocs\symfonyux>
Going to look for online file validator
Hey Stuart,
Yeah, Windows is probably most likely guilty here. Yeah, you definitely need to fix the encoding somehow, IIRC Notepad++ editor for Windows allows you to save in different encodings, probably other apps too, but you need to google how to do it correctly. I suppose you need UTF-8 encoding, but if that does not help, probably try the reverse: Windows-1251.
Sorry can't help more on it, I hope it will helps!
Cheers!
found a little work around upload the generated file to
JSON Validator / Formatter
then downloaded its version and replaced the original and it works.
A bit clunky but gets the result
Hey Stuart,
I'm glad to hear it worked for you wit this workaround, and thanks for confirming it worked for you this way, I bet it might be useful for our Windows friends :)
It still sounds like you should fix the encoding somehow in your OS... but at least you unblock yourself with this workaround, well done!
Cheers!
Hey Benjamin,
It's always tricky to make things work on Windows. Thanks for sharing your solution
Cheers!
...Not
webpack-bundle-analyserwhich does exist but isn't relatedHa! Who would imagine... thanks for sharing it to others. Cheers!
"Houston: no signs of life"
Start the conversation!