简体   繁体   English

如何将外部.js文件添加到index.html? (VueJS2)

[英]How do I add an external .js file to my index.html? (VueJS2)

So I have two external Javascript files for handling the animations and triangulation of vectors for a background animation. 因此,我有两个外部Javascript文件,用于处理背景动画的动画和矢量的三角剖分。 Now, in a normal html/css/js project I would just include those two .js files in a <script src="fileLoc.."></script> before the end of the </body> tag in my regular index.html file. 现在,在普通的html / css / js项目中,我将在常规index.html </body>标记末尾的<script src="fileLoc.."></script>包含这两个.js文件<script src="fileLoc.."></script> index.html文件。 My question is, how do I include those two .js files into my VueJS2 project's index.html file? 我的问题是,如何将这两个.js文件包含到VueJS2项目的index.html文件中? Just puttin <script> tags before the </body> end does absolutely nothing. 只是将</body>末尾的<script>标记放在绝对不起作用。

Thanks in advance 提前致谢

You can add another entry point and give it a name using webpack chain in your vue.config.js . 您可以在vue.config.js使用webpack chain添加另一个entry点并为其命名。 This will automagically be inserted in your index.html file: 这将自动插入到您的index.html文件中:

// vue.config.js

module.exports = {
  chainWebpack: (config) => {
    config
      .entry('delaunay')
      .add('src/assets/delaunay.js')
      .end()
  }
}

This should work for you in practice. 实际上,这应该对您有用。

in your js file you can do this: 在您的js文件中,您可以执行以下操作:

import delaunay from './src/assets/delaunay.js'
import bg from './src/assets/bg.js'

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

相关问题 如何将文件 vuejs 组件导入 index.html? - how can I import a file vuejs component into index.html? 如何在React样板中的index.html上添加外部JS? - How to add external JS on index.html in React boilerplate? 如何在不触及index.html的情况下将外部javascript标记添加到Ember JS应用程序? - How can I add an external javascript tag to an Ember JS app without touching the index.html? 如何将contact.handlebars添加为index.html而不是contact.html的链接? - How do I add contact.handlebars as a link to my index.html instead of contact.html? 如何在 react js 中的 index.html 文件中添加条件 - How to add condition in index.html file in react js 如何将 js 文件链接到 Node.js web 服务器中的 index.html? - How do I link a js file to index.html in a Node.js web server? Vue.js。如何在 index.html 文件中获取当前 url? - Vue js. How do I get current url in index.html file? 如何链接回index.html上的选项卡? - How do I link back to a tab on my index.html? 如何使用 JavaScript 在我的 index.html 文件中嵌入 API 调用? - How do I embed an API call in my index.html file using JavaScript? 如何在 index.html 文件中定义变量? (window.parentPage = true;) - How do I define a variable in my index.html file? (window.parentPage = true;)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM