简体   繁体   English

有没有办法在 Nuxt 中为缩小的 JS 脚本标签添加属性?

[英]Is there any way to add an attribute to a minified JS script tags in Nuxt?

We have an app, that minifies all necessary JS files.我们有一个应用程序,可以缩小所有必要的 JS 文件。 The way nuxt minfies the JS scripts when the app renders inside <head> is something along these lines:当应用程序在<head>中呈现时,nuxt 缩小 JS 脚本的方式大致如下:

<script src="/_nuxt/cc2978d89512be6a8374.js" type="text/javascript"></script>

My q is quite simple, how can we add an attribute to this file?我的 q 很简单,我们怎样才能给这个文件添加一个属性呢? Essentially turn that line into:基本上把这条线变成:

<script someAttribute src="/_nuxt/cc2978d89512be6a8374.js" type="text/javascript"></script>

I've snooped around nuxt.config.js but can't seem to add it.我已经窥探了nuxt.config.js但似乎无法添加它。 I also checked the Nuxt docs and cannot find anything relvant, so any help would be greatly appreciated.我还检查了 Nuxt 文档,找不到任何相关内容,因此将不胜感激。 Thanks in advance!提前致谢!

Maybe this?也许这个?

  var scripts = document.querySelectorAll('scripts');
  var l = 0;
  while (l<scripts.length) {
    if (scripts[l].src = '/_nuxt/cc2978d89512be6a8374.js') {
      scripts[l].setAttribute('NAME', 'VALUE');
    }
    l++;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM