bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
193 stars 91 forks source link

Handlebars asset pipeline doesn't work correct because of develomentRuntime true/false (?) (Grails) #270

Open DontPlayTheGame opened 3 years ago

DontPlayTheGame commented 3 years ago

Hello, This caused me a lot of headache. During rewriting an old Grails project i used the same JavaScript code for my handlebars calls as in the old one. It worked fine, but as soon as i deployed the project on a test server i got always a JavaScript type error : "TypeError: Handlebars.Template is not a function". I tried a couple of things until i could discover why the code is working on localhost in the development mode but not on any other deployment stage. Maybe the problem is related to: https://stackoverflow.com/questions/64632219/grails-run-app-services-javascript-starting-with-node-env-line

Environment Information

Actual Behaviour

build.gradle:

assets {
    configOptions = [
            handlebars: [
                    templateRoot: 'handlebars',
                    templatePathSeperator: '/'
            ]
    ]
    minifyJs = true
    minifyCss = true
}

As long as I am runing a project in devlopment environment and alle the JavaScript assets are separeted like this:

<script type="text/javascript" src="/assets/handlebars/handlebars.runtime.min-v4.7.6.js?compile=false"></script>
<script type="text/javascript" src="/assets/application.js?compile=false" ></script>

the code: var hbTemplate = Handlebars.templates['handlebars/example'] is working fine.

Runing the project on the test or prod environment, where all the JavaScript assets are merged into one file, the above code is not working anymore. But instread that this code is working: var hbTemplate = Handlebars.templates.example;

I added then developmentRuntime = false to the asset {} part in my build.gradle so that I got alle the JavaScript assets merged into one file while the application was still running in the dev environment. With that the first code stopped working and the second one started working instead.

This is why I am thinking, that there is a bug how the asset pipe line is working with developmentRuntime = true/false

Example Application

https://github.com/DontPlayTheGame/assetpipeline-grails406 I included both typ of JavaScript code in the example. You can run the applikation in development environment and then just add developmentRuntime = false to the asset {} in your build.gradle or run the applcation with grails.env=test or grails.env=prod