如何为自定义过滤器[Bootstrap,JQuery]配置Symfony2和Assetic设置?

时间:2015-07-08 22:01:29

标签: node.js symfony less assetic yui-compressor

我一直在研究Symfony2,并且在Assetic编译器和过滤器中出现了一些问题。 有谁知道如何使它在Windows平台上运行,因为几乎每个例子都响应* nix环境?

.exe的路由是否应具有以下格式: C:\\....\\,为了完成对Java.exeNode.exe

的访问权限

* nix的路径为:/usr/bin/local

或者作为Symfony风格:/../../

接受哪种选择?

1 个答案:

答案 0 :(得分:1)

这些设置对我有用:

  1. Windows 8.1(x64)
  2. PhpStorm 8.0
  3. NodeJs v0.10.35
  4. Symfony 2.7 (最近更新)
  5. 我想与其他人分享。 这些对于实现结果非常有帮助:

    Use Twitter Bootstrap in Symfony2 with Composer

    Symfony 2 and Bootstrap 3 Assetic Config and Base HTML Template

    Twitter Bootstrap glyphicons font's not found when using assetic in prod on Symfony2

    composer.json

        "twbs/bootstrap": "dev-master",
        "oyejorge/less.php": "~1.5",
        "bmatzner/jquery-ui-bundle": "*",
        "bmatzner/jquery-bundle": "dev-master",
        "twbs/bootstrap-sass": "~3.3.0"  (note: optional)
    

    parameters.yml

    #Assetic parameters
    
    java_dir: "C:\\Program Files\\Java\\jre1.8.0_40\\bin\\java.exe"
    node_dir: "C:\\Program Files\\nodejs\\node.exe"
    node_modules: "C:\\Users\\fraballi\\AppData\\Roaming\\npm\\node_modules"
    yui_jar: "%kernel.root_dir%\Resources\java\yuicompressor-2.4.8.jar"
    cssembed: "%kernel.root_dir%\Resources\java\cssembed-0.4.5.jar"
    less_php: "%kernel.root_dir%/../vendor/oyejorge/less.php/lessc.inc.php"
    

    config.yml

    # Assetic Configuration
    
    assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    java: %java_dir%"
    filters:
        cssrewrite: ~
        less:
            node: %node_dir%
            node_paths: [%node_modules%]
            apply_to:   "\.less$"
        yui_css:
            jar: "%yui_jar%"
        yui_js:
            jar: "%yui_jar%"
        cssembed:
            jar: "%cssembed%"
    assets:
        jquery_js:
            inputs:
                - '%kernel.root_dir%/../vendor/bmatzner/jquery-bundle/Bmatzner/JQueryBundle/Resources/public/js/jquery.min.js'
            filters: [?yui_js]
        bootstrap_js:
            inputs:
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/dist/js/bootstrap.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/affix.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/alert.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/button.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/carousel.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/collapse.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/dropdown.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/modal.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/popover.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/scrollspy.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/tab.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/tooltip.js'
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/js/transition.js'
            filters: [?yui_js]
        bootstrap_less:
            inputs:
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/less/bootstrap.less'
            filters: [less]
        bootstrap_fonts_woff:
            inputs:
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.woff'
            output: fonts/glyphicons-halflings-regular.woff
        bootstrap_fonts_ttf:
            inputs:
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.ttf'
            output: fonts/glyphicons-halflings-regular.ttf
        bootstrap_fonts_svg:
            inputs:
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.svg'
            output: fonts/glyphicons-halflings-regular.svg
        bootstrap_fonts_eot:
            inputs:
                - '%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.eot'
            output: fonts/glyphicons-halflings-regular.eot
    

    的命令

    php app/console --env=dev cache:clear
    php app/console --env=dev cache:clear --no-debug
    php app/console --env=dev assets:install web --no-debug
    php app/console --env=dev assetic:dump --no-debug
    

    枝条

    {% block stylesheets %}
        {% stylesheets '@bootstrap_less' combine=true %}
        <link href="{{ asset_url }}" rel="stylesheet" type="text/css"/>
        {% endstylesheets %}
    {% endblock %}
    
    {% block javascripts %}
        {% javascripts '@jquery_js' '@bootstrap_js' filter='?yui_js' combine=true %}
        <script src="{{ asset_url }}"></script>
        {% endjavascripts %}
    {% endblock %}