I'm learning webpack from this site and notice they tell me to use webpack ./entry.js bundle.js in the terminal but it still works even if I use webpack entry.js bundle.js as long as I'm in the root directory. I think I know that "./" signifies that the file is in the current directory, but it works the same without it, so what's the point? Is it just more clear?
Related
so i've beein struggling with an old laravel project from 2018 that i can't seen to run. The probem is that the project i splittedinto two folders not a classic laravel one, there's an other one named "httpdocs" and the index.php is there, so i managed to install everything and running the migrations, but noti can't run the website ? idk why it said:
Warning: require(C:\xampp\htdocs\httpdocs/../daddyshop_app/vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\httpdocs\index.php on line 24
the autoload.php file exists
I think this part is wired, see / and \ on the require:
require(C:\xampp\htdocs\httpdocs/../daddyshop_app/vendor/autoload.php)
Maybe you are setting wrongly the folder structure, or in the index.php file, you are searching in the wrong path.
For example, try checking paths are correct:
Maybe /../../laravel-app or ../.. or /../laravel-app.
You get the point, make sure paths are correct.
so I seem to be a bit confused on how to work with images in webpack encore + assets.
I store all JS & CSS like this
/assets/js
/assets/css
...
With encore I can access them later from my /public/build folder - no issues there.
Now I want to store some images (e.g. file upload).
First idea was to store them inside a folder like /assets/images. But with the current settings & using assets I can only access files inside /public/build folder.
So I tried to use to copyFiles to copy everything from /assets/images to /public/build/images.
But this does not automatically copy my files (e.g. file upload to /assets/images/ does not copy it to /public/build - which is in order not accessible in my project). So I would need to run manually encore - which I don't want.
Second idea was to store the uploaded images directly inside /public/build/images but those files would be deleted when I run encore.
Next I disabled the webpack option cleanupOutputBeforeBuild, so images would not be deleted. But without this option the folder will be flooded by new JS & CSS Files everytime I run encore.
What do I need?
A solution to store my images either way in /assets folder & make them available for my project.
or
store the images directly in /public/build folder without encore deleting them nor flooding the folder with JS/CSS by disabling cleanupOutput Option.
Thanks in advance ~Syllz
If u need to use it in JS, just require the file:
// assets/app.js
import logoPath from '../images/logo.png';
let html = `<img src="${logoPath}" alt="ACME logo">`;
When you require an image file, Webpack copies it into your output directory and returns the final, public path to that file.
If u need using it from a templates:
You need to install file-loader to use copyFiles()
yarn add file-loader#^6.0.0 --dev
then enable it in webpack.config.js:
.copyFiles({
from: './assets/images',
//optional target path, relative to the output dir
//to: 'images/[path][name].[ext]',
//if versioning is enabled, add the file hash too
to: 'images/[path][name].[hash:8].[ext]',
//only copy files matching this pattern
//pattern: /\.(png|jpg|jpeg)$/
})
then use it in your twig template:
<img src="{{ asset('build/images/logo.png') }}" alt="ACME logo">
more details in Symfony documentation
You can use the CopyWebpackPlugin to do this. You can read this post for more details.
Solution to my problem:
Store the images into /public/images and not into the build folder - which will be deleted when running encore.
I do not understand the meaning of the ~ char in the following line of code in a scss file:
#import "~bootstrap/dist/css/bootstrap.min.css";
Since it's in the file path, I guess it's the "Bootstrap user home directory".
On Linux or Unix, home directories are named ~:
~ : the current user directory (yours)
~juan would be your home directory.
~bootstrap : bootstrap's user directory (ex: /home/bootstrap or maybe /usr/share/bootstrap or /opt/bootstrap)
More examples on https://askubuntu.com/questions/656869/how-does-using-the-tilde-work-as-a-shortcut-to-my-home-directory
So maybe your bootstrap files are located in a particular directory owned by a bootstrap user having that directory as his $HOME directory.
In that case, it's not at all related to Sass, it's only a regular file path.
That is not part of sass, it's actually a feature of sass-loader which you are probably using with webpack.
What it does is importing the file relative to the node_modules folder instead of the current file.
Check out sass-loader's documentation for more details: https://github.com/webpack-contrib/sass-loader#imports.
I'm making a simple html and CSS app. I need to my SASS changes to show up on the website LIVE as im developing.
And once all the SASS and development is complete I will run webpack -b and webpack should convert the SASS to CSS.
I'm sure someone has done this before. Thanks.
It looks like the problem stems from wrong output.publicPath config in webpack.config.js file. In order for live-reload to work, requests going to webpack bundles (e.g. app.css, app.js) should be handled by webpack-dev-server. For the repository you're referring to, this could be done by setting output.publicPath to "/build".
Run webpack-dev-server --inline on the command line after changing config file and then go to http://localhost:8080. Now the page should reload everytime you change and save a file.
I'm having some trouble with artisan/packages.. I've added a package to my composer file and ran composer update and an error was returned:
PHP Warning: require(/home/xxx/public_html/bootstrap/autoload.php): failed to open stream: No such file or directory in /home/xxx/public_html/artisan on line 16
I can see that require path is incorrect, my structure is like so:
/home/xxx/bootstrap
/home/xxx/app
/home/xxx/vendor
/home/xxx/public_html
I hadn't changed any of the paths and everything seemed to work out of the box with this structure, basically removing the public folder and pushing everything up a directory.
I've opened up Artisan tried a couple of paths that kept failing so i've changed them to absolute:
require '/home/xxx/bootstrap/autoload.php';
It seemed to work from here on, but at the end of the process got another error:
Writing lock file
Generating autoload files
[RuntimeException]
Could not scan for classes inside "app/commands" which does not appear to be a file n or a folder
Rather than continue to mess it up i thought now would be a good time to clear it up, any ideas how to fix this?
Make sure you are using php 5.3 or higher.
Run php -v
Try creating an empty "app/commands" folder, fixed the issue for me!