Assets not install in symfony 4 - symfony

I read symfony documentation for Web Assets and create /assets directory in root of my project then run command php bin/console assets:install but get:
[OK] No assets were provided by any bundle.
I store one CSS file in assets directory but didn't install in /public
how should I do?

The web assets documentation for Symfony 4 recommends using Webpack Encore.
The assets:install command is not used in this configuration.
Here's what you have to do according to the documentation :
Install Node.js and Yarn on your computer.
Install Encore into your project with : yarn add #symfony/webpack-encore --dev
Configure webpack / Encore by editing (or creating) the webpack.config.js file as described here.
Compile your assets by running : yarn run encore dev

There is a workaround to do it clearly (more or less) while we are waiting for further webpack-encore development. Can be done by Makefile or similar way but here is more native solution.
Create blank bundle:
// src/BlankBundle/BlankBundle.php
namespace App\BlankBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class BlankBundle extends Bundle
{
}
Then put your assets to src/BlankBundle/Resources/public directory and enable the bundle:
// add it to config/bundles.php
App\BlankBundle\BlankBundle::class => ['all' => true],
After executing php bin/console assets:install command your resources will be at public/bundles/blank directory.

Related

assets in Symfony6 - manifest.json missing

I'm learning Symfony, following a tuto. Problem is, it is with Symfony5 and i'm using Symfony6.
The tuto says to create an assets folder in public directory, which I did :
When I use Twig to call my bootstrap.css like this :
<link href="{{ assets('assets/css/bootstrap.min.css' )}}" rel="stylesheet">
I get this error :
An exception has been thrown during the rendering of a template ("Asset manifest file "/Applications/MAMP/htdocs/laboutiquefr/public/build/manifest.json" does not exist. Did you forget to build the assets with npm or yarn?").
My questions are :
How do I fix this manifest.json error ?
I see an assets folder with Symfony6, which is not on the tuto with Symfony5. Should I use this folder instead ?
Thank you very much.
You need to build asset when updating css/js/images by using the command:
yarn encore dev --watch when using yarn or npm run watch when using npm.
This should build your assets (and create a manifest.json referencing those assets).

Why is Symfony not working on shared host?

I installed Symfony on my local host and it is working like a charm.
But when I upload the project folder via php to my shared host it is not working.
I see only the message: This site is currently under construction.
I am using the right php version (7.1.)
This is my folder structure.
.DS_Store
.env
.env.dist
.git
.gitignore
assets
bin
composer.json
composer.lock
config
package.json
phpunit.xml.dist
public
src
symfony.lock
templates
tests
translations
var
vendor
webpack.config.js

Error when launch yarn run encore dev for the first time

I've a problem when I configure for the first time the webpack.config.js in my Symfony 3.4 project.
I folow the documentation of symfony to install and configure encore but I don't know why I've allways this error:
$ yarn run encore dev
yarn run v1.6.0
$ [my_root_project_path]\node_modules\.bin\encore dev
Running webpack ...
ERROR Failed to compile with 1 errors10:01:31
error
Entry module not found: Error: Can't resolve 'web/build/app.js' in '[my_root_project_path]'
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
my webpack.config.js file is this:
// webpack.config.js
var Encore = require('#symfony/webpack-encore');
Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.addEntry('app', 'web/build/app.js')
.autoProvidejQuery()
.enableSourceMaps(!Encore.isProduction())
.cleanupOutputBeforeBuild()
;
module.exports = Encore.getWebpackConfig();
Does the problem come from a permission on files that Encore doesn't? Anyway, I'm lost, I don't know what to do.
Config:
Windows 10
wamp server
php version 5.6.31
Symfony 3.4
yarn 1.6.0
Note:
I know there is probably another post of the same kind of issue but I think that at the moment I have tested everything and my problem persists. I'm always listening and if you think there's a stackoverflow post that can solve my problem I'll let you share it with me.
Your problem is in addEntry path
.addEntry('app', 'web/build/app.js')
which does not point to the right file. The correct syntax is:
.addEntry(<name_of_the_entry>, <path_to_the_entry>)
where path_to_the_entry must point to a js file you want to add in your build, not directly to your build path. This file should be in a different folder e.g. 'your_project_root/assets/js/your_js_file.js' as specified in doc.
Encore will create the appropriate .js file (and possibly .css if you added one in your .js file) in your web/build folder so that your users can access those files.

Symfony 4 - Assets folder not found

According to Symfony Best Practices,
Store your assets in the assets/ directory at the root of your project.
But currently, I don't have this folder created and if I create it, I got the error telling me that ressources can't be found.
I tried composer require webassets , but don't working.
Anyone have the solution ?
Regards
Placing assets folder in root directory is best practice. Reason that root directory cannot be accessible from outside. You should try Symfony's Webpack Encore plugin. It compiles your minimized and compressed assets into public folder so they can never be shown as original.
If that is not fit your interest just put your whole assets folder into public directory.
You try following command.
$ composer require encore
$ yarn install
May be good to refer to here.
http://symfony.com/doc/current/frontend/encore/installation.html
Enable the encore composer require encore
update yarn yarn install

Autoload Bundle with custom path in Symfony2

I am developing a Symfony2 web app that will be hosted on an Ubuntu server and want my directory structure to be:
/Symfony (with an app,bin and vendor folder in it)
/Site1
/Site2
This way site1 and site2 use the same Symfony framework. In /Site1 I want:
/web
and in there I want app.php and app_dev.php as well as /web/AppBundle with all of the bundle files. I already figured out that I need to change in app.php require_once DIR.'/../Symfony/app/AppKernel.php'; in 2 places as per http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html
When I generated the bundle I did get the message "Checking that the bundle is autoloaded: FAILED" and that I should "Edit the composer.json file and register the bundle namespace in the "autoload" section"
I added "AppBundle": "/web/AppBundle" to the composer.json autoload section and in cygwin I run "composer -n install" It starts with saying that it is loading composer repositories and then it says "Installing dependencies (including require-dev)" and never goes past that.
What can I do to register this bundle that is not in the standard folder so that autoload picks it up? I am just getting the fact that the class could not be found in AppKernel.php
Thanks.
It's simple. Just don't do it! Use symfony as it is intended with its default directory structure.
Great two projects. If you have common code, extract it to an extra bundle and install it in both projects via composer.

Resources