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!
11.
Webpack dev-server: Faster Updating
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 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
}
}
14 Comments
Here's a quick fix for those of you using a virtual host:
` // webpack.config.js
Then run
yarn encore dev-server --host myproject.localOR
yarn dev-server --host myproject.localyarn dev-server --host myproject.local --hotThanks for posting that! The dev server can be a pain when it comes to this host stuff (that's why I show
watchmore often... even thoughdev-serveris more awesome ;) )I am working on a Symfony 6 project and trying to get the Webpack/Encore dev server to use https. I have set it up exactly as indicated at https://symfony.com/doc/current/frontend/encore/dev-server.html#enabling-https-using-the-symfony-web-server, and when I run yarn dev-server, the output is
`yarn dev-server
yarn run v1.22.19
$ encore dev-server
Running webpack-dev-server ...
[webpack-dev-server] SSL certificate: /opt/www/shrinksoffice/node_modules/.cache/webpack-dev-server/server.pem
[webpack-dev-server] Project is running at:
[webpack-dev-server] Loopback: https://localhost:8080/, https://127.0.0.1:8080/
[webpack-dev-server] Content not from webpack is served from '/opt/www/shrinksoffice/public' directory
[webpack-dev-server] 404s will fallback to '/index.html'
DONE Compiled successfully in 1814ms `
which looks about right, doesn't it?
But when I load my app's main page into a browser, there is a CSS-less and JS-less skeleton -- because the output of my twig base template's
encore_entry_link_tags()andencore_entry_script_tags()say http (not https), and the debug console sayserror loading failed for the <script> http://localhost/[etc]. When I do load, e.g., https://localhost:8080/build/runtime.js directly with my browser, boom! There it is, as it should be. So I guess I am having trouble getting -- Twig? Encore? -- to get the memo that we are using https.HOWEVER! When I use the old deprecated --https option, yeah it works, but with a deprecation warning that I would like to be rid of.
Any suggestions? Thanks.
Hey davidmintz
I believe Symfony forgot how to read memos :p
I'd expect it to grab the URL schema from the request but it's not doing it for some reason. What you can do is to configure the base_url by adding this config
You only need to set up the
site_base_urlparameter to point to your domain (or localhost) e.g.you may want to use an environment variable instead so you can tweak its value easily when you deploy to production
Cheers!
Thanks for the reply!
So, in services.yaml I have added
site_base_url: 'https://localhost:8080'under the key
parameters.In framework.yaml, under the key
framework, I added:I cleared the cache just for good measure, and stopped and restarted dev-server and the symfony http server. The result I'm getting is still the same, i.e., symfony does not seem to be picking up the <b>https</b>; the template still says, e.g., http://localhost:8080/build/runtime.js. Don't know what I'm doing wrong, if anything.
This is with Symfony 6.0.10. Do you think upgrading to 6.1 might help?
Hey davidmintz
I had to do some research about this. I believe this is a bug on Webpack (or perhaps on Symfony Encore I couldn't get to the root of the problem), when you start Webpack's dev server using the new flag
--server-type httpsthe routes inside the filepublic/build/entrypoints.jsonare not pointing to HTTPS, but if you use the deprecated flag--httpsthen, the routes will be generated as expected.So, something inside Webpack is not detecting the HTTPS flag at the moment of generating the entrypoints.json file. I'd recommend using the deprecated flag and wait for the next Encore version, it may get fixed - or, if you feel proactive, you can create an issue on the Encore project :)
Cheers!
Isn't that interesting! Thanks.
It feels great when you find a bug in a core library :)
The https option resulted in this error. It's not going to stop me from continuing since I can just use http.
Error: not enough dataHey Aaron,
Thanks for sharing your workaround with others!
Cheers!
For those who prefer
npminstead ofyarn, use it like thatnpm run dev-server -- --https --pfx=$HOME/.symfony/certs/default.p12Hey Sargath
Isn't there an extra `--`?
Yes there should be an extra `--` https://stackoverflow.com/a...
Cool, great I just wanted to clarify :)
"Houston: no signs of life"
Start the conversation!