Saturday 29 April 2017

How to prevent Jade case when to transpile every case? PS: I'm using includes

I'm working on a very large project, using gulp, node, jade templates and bem notation. When trying to locally serve the app, I have one file causing it to take around 4 minutes to compile!! I noticed this file, if commented out, reduces the load time to 24 seconds!

The file in question (that I need to improve/refactor) has a case/when and includes lots of things. It seems that jade renders every include to javascript FIRST and then looks at what files we need or not based on the case... This is the file, is there a way to improve this? THANKS!!

// START sos-shopping-overlay/shopping-overlay

include ../../_bem

-var $prefix = 'sos-'

+bemto_scope({prefix: $prefix})
        +b.component
                .common-vertical-align
                        .common-vertical-align__content
                                +e.overlay
                                        +e.A.close(href="#", title="Close Overlay")

                                        case $sosType
                                                when 'dashboard'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__dashboard
                                                when 'deals'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__your-deal
                                                when 'deal-details'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__deal-details
                                                when 'sections'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__your-section
                                                when 'deck'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__your-deck
                                                when 'rooms'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__your-room
                                                when 'paymentPlan'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__payment-plan
                                                when 'mb-landing'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__mb-landing
                                                when 'mb-preselected-room'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__mb-preselected-room
                                                when 'mb-room-type'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__mb-room-type
                                                when 'mb-deal'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__mb-deal
                                                when 'mb-section'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__mb-section
                                                when 'mb-deck'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__mb-deck
                                                when 'mb-room'
                                                        include ../../components/ssc__shopping-step-container/shopping-step-container__mb-room
                                                default
                                                        h1 No step found


via Juanma Guerrero

No comments:

Post a Comment