Symfony

73 readers
1 users here now

A community for Symfony, the PHP web application framework. https://symfony.com/

founded 2 years ago
MODERATORS
1
 
 

I'm posting this in case it helps anyone, but also for a sanity check (anyone has a better solution?).

My issue - using 3rd party packages and SCSS (and the solution in the docs)

Using Bootstrap as an example:

Running php bin/console importmap:require bootstrap doesn't import SCSS.

The easy provided alternative is installing as Composer package with composer require twbs/bootstrap, and importing the SCSS from there. This happens to work for Bootstrap, but may not be an option for others (there may not be a composer package)

My alternative

CSS

  1. Install (at least these) third party packages using npm like usual.
  2. In the app's SCSS file, import using the relative path to the node_modules's bootstrap: @import '../../../node_modules/bootstrap/scss/bootstrap';

JS

  1. In config/packages/asset_mapper.yaml add the path specifically for the third-party package to be included. My file is looking like this:
framework:
    asset_mapper:
        # The paths to make available to the asset mapper.
        paths:
            - assets/
            - node_modules/bootstrap/dist/js
        excluded_patterns:
            - 'assets/styles/scss/**/*'
        missing_import_mode: strict

when@prod:
    framework:
        asset_mapper:
            missing_import_mode: warn

  1. In importmap.php add the path ( and with entrypoint set to true). This only works because of the previous step.

return [
    'app' => [
        'path' => './assets/app.js',
        'entrypoint' => true,
    ],
    // ...
    'bootstrap' => [
        'path' => './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
        'entrypoint' => true,
    ],
];
  1. Import in the template as usual
{% block importmap %}
    {{ importmap([
        'bootstrap',
        'app',
    ]) }}
{% endblock %}
2
3
 
 

It's a shame when specific channels die that sh/would do well. So, let's start posting again in /c/symfony and get some activity going again!

4
3
submitted 7 months ago* (last edited 7 months ago) by Olissipo@programming.dev to c/symfony@programming.dev
 
 

Twig 3.15 was released a few weeks ago and includes an impressive list of new features and improvements. This two-part blog post highlights the most important ones.

Edit: Part 2

5
6
7
8
9
10
11
12
13
 
 

The link in the post is 7.0.6

14
15
16
17
18
19
20
21
22
23