C. V.
C. V.

Reputation: 71

Assetic assets with only dumped files

We have started to use Bower (via SpBower) for managing our js and css libs, before realizing it was not possible to install Bower on our current prod server.

The idea is not to generate files on the prod server, but to dump the prod files on dev environment and upload these dumped files. But even in prod mode, Assetic is looking for the source files and bower registers these vendor files, so Assetic throw this exception

(Twig_Error_Syntax(code: 0): An exception has been thrown during the compilation 
of a template (\"There is no \"jquery_js\" asset.\")

Where jquery_js is called after Bower registration in this way

    {% javascripts output='js/vendor-1.js'
        '@jquery_js'
        '@jquery_ui_js'
        '@chartjs_js'
        '@Chart_StackedBar_js_js' %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}

Is there a way to tell assetic to ignore the assets (jquery_js, jquery_ui_js...) to only look at the output file (vendor-1.js) ? I could not find anything in Symfony2 cookbook.


Below are the Assectic and Sp Bower sections in config.yml

assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ProjectBundle ]
    filters:
        cssrewrite: ~

sp_bower:
    assetic:
        nest_dependencies: false
    bundles:
        ProjectBundle:
            asset_dir: ../../public/vendor
            cache:
                id: ~
                directory: ../../public/vendor/cache

And in config_dev.yml

assetic:
    use_controller: false

As well as the content of the bower.json file

{
    "name": "ProjectBundle",
    "dependencies": {
        "jquery": "~2.0",
        "jquery.countdown": "~2.0", 
        "jquery-ui": "~1.11",
        "bootstrap": "~3.0",
        ...
    }
}

Upvotes: 1

Views: 331

Answers (1)

C. V.
C. V.

Reputation: 71

I've found a work around, not very nice but that solves our problem.

The idea is to use sp_bower only on dev env so to put it only in config_dev.yml and manually specifying the named assets on prod env so in config_prod.yml.

We don't have to actually put the correct path to the source file since we won't generate the output files on prod (but use uploaded ones), we can even use a fake js file (for example a file named prodDumpAlert.js) containing for example an alert explaining what's going on.

So the config_dev.yml would look like that :

imports:
    - { resource: config.yml }

assetic:
    assets:
        jquery_js:
            inputs:
                - '@ProjectBundle/Resources/public/utils/prodDumpAlert.js'
        jquery_ui_js:
            inputs:
                - '@ProjectBundle/Resources/public/utils/prodDumpAlert.js'
        chartjs_js:
            inputs:
                - '@ProjectBundle/Resources/public/utils/prodDumpAlert.js'
...

Upvotes: 1

Related Questions