File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ Usage in templates:
4040- {{ withVersion url }} -- appends ` '?v=' + version ` to the passed string
4141- {{ extend name options }} -- calls the function options.fn with content of block ** name** as param and adds it to named block
4242- {{ prefixScript url name }} -- add a script tag with version set to script block ** name**
43+ - {{ prefixModuleScript url name }} -- add a script tag with type module and with version set to script block ** name**
4344- {{ prefixStyle url name media }} -- add a style tag for named media type with version set to style block ** name**
4445- {{ render name }} -- used by a layout to render script and style blocks in appropriate places
4546
Original file line number Diff line number Diff line change @@ -87,6 +87,30 @@ module.exports = function headerContent(options) {
8787 _blocks [ blockName ] . push ( `<script src="${ url } "></script>` )
8888 } )
8989
90+ /** @function prefixModuleScript
91+ *
92+ * @param {string } url -- local path to script excluding proxyPrefixPath
93+ * @param {string } blockName -- (optional) name of script block to include with, defaults to 'scripts'
94+ *
95+ * @return output with {{ render blockName }}
96+ *
97+ * @example
98+ * {{prefixModuleScript '/path/to/script.js' 'scripts'}}
99+ */
100+ Handlebars . registerHelper ( 'prefixModuleScript' , function prefixModuleScript ( urlIn , blockNameIn ) {
101+ // Check params and give useful error message since stack traces aren't very useable in layouts
102+ if ( typeof urlIn !== 'string' ) {
103+ throw new Error ( '[prefixModuleScript] helper requires first parameter (url) to be a string. Got: ' + urlIn )
104+ }
105+
106+ const blockName = typeof blockNameIn === 'string' ? blockNameIn : 'scripts'
107+ _blocks [ blockName ] = _blocks [ blockName ] || [ ]
108+
109+ const url = `${ proxyPrefixPathUri } ${ urlIn } ?v=${ encodeURIComponent ( version ) } `
110+
111+ _blocks [ blockName ] . push ( `<script type="module" src="${ url } "></script>` )
112+ } )
113+
90114 /** @function prefixStyle
91115 *
92116 * @param {string } url -- local path to script excluding proxyPrefixPath
You can’t perform that action at this time.
0 commit comments