bertramdev / asset-pipeline

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

Unable to change script type to import JS dependency into Grails-app #323

Closed azdurov closed 4 months ago

azdurov commented 1 year ago

I am trying to connect the JS library as a module in Grails application. For this, I use the following format in the GSP: <asset:javascript src="myLibrary.js" type="module"/>

The "type" attribute is the usual one for the "script" tag. W3 specification

The error is on the following line: https://github.com/bertramdev/asset-pipeline/blob/45f2f332362402acec7d8ae1cdc8f1c719597581/asset-pipeline-grails/grails-app/taglib/asset/pipeline/grails/AssetsTagLib.groovy#L33

The "type" attribute with the value "text/javascript" is hard-coded into the string.

It is necessary to add a check for the presence of the attribute "type" in the "attrs" list: if (!attrs.containsKey('type')) And only in this case add "type="text/javascript"" to the generated string.

Example result code: outPw << '<script ' << (!attrs.containsKey('type') ? 'type="text/javascript"' : '') << ' src="' << assetPath(src: src, useManifest: useManifest) << queryString << '" ' << paramsToHtmlAttr(outputAttrs) << '></script>' << endOfLine

azdurov commented 1 year ago

@davydotcom , could you take a look? There is a proposal for a fix here.

davydotcom commented 4 months ago

@azdurov fixing for next release