Grails Asset-Pipeline system with 3rd party libs

前端 未结 5 2147
长情又很酷
长情又很酷 2021-02-07 04:59

Grails 2.4 is now using the Asset Pipeline for managing and processing static assets in Grails applications instead of the Resources system. Th

5条回答
  •  情话喂你
    2021-02-07 05:24

    Baxxabit's answer led me to my solution. I've been struggling with much the same thing, but wanting to make the most of the pipeline so that I can use the less-asset-pipeline plugin.

    Using bootstrap as an example, I created a vendor folder as a peer of the standard assets folders and then dropped the bootstrap files under there.

    application.js:

    //This is a javascript file with its top level require directives
    //= require jquery
    //= require bootstrap-3.1.1/javascript/bootstrap
    //= require_tree views
    //= require_self
    ...
    

    and application.css:

    /*
    *= require_self
    *= require main
    *= require mobile
    *= require bootstrap-3.1.1/stylesheets/bootstrap
    *= encoding UTF-8
    */
    

    To override the boostrap customization I can simply drop a customized variables.less file into ./grails-app/assets/vendor/bootstrap-3.1.1/stylesheets/variables.less. The first folder under assets is ignored when it comes to overriding files, thereafter the path needs to match whatever you put under vendor.

    This gives me this sort of hierarchy:

    grails-app/assets/
    ├── images
    ...
    ├── javascripts
    │   └── application.js
    ├── stylesheets
    │   ├── application.css
    │   ├── bootstrap-3.1.1
    │   │   └── stylesheets
    │   │       └── variables.less
    │   ├── errors.css
    │   ├── main.css
    │   └── mobile.css
    └── vendor
        └── bootstrap-3.1.1
            ├── javascript
            │   ├── bootstrap.js
            │   └── bootstrap.min.js
            └── stylesheets
                ├── alerts.less
    ...
                ├── variables.less
                └── wells.less
    

    I like the result. I've got the distributed package cleanly delineated and relatively easily upgradable, and I've got my changes to that package separated off into a clearly identifiable customization file.

    I've put an example using the sass-asset-pipeline plugin at https://github.com/ggascoigne/grails-pipeline-scss.

提交回复
热议问题