headScripts
- Type:
Array
- Default:
[]
配置 <head>
里的额外脚本,数组项为字符串或对象。
大部分场景下用字符串格式就够了,比如:
export default {
headScripts: [
`alert(1);`,
`https://a.com/b.js`,
],
}
会生成 HTML,
<head>
<script>alert(1);</script>
<script src="https://a.com/b.js"></script>
</head>
如果要使用额外属性,可以用对象的格式,
export default {
headScripts: [
{ src: '/foo.js', defer: true },
{ content: `alert('你好');`, charset: 'utf-8' },
],
}
会生成 HTML,
<head>
<script src="/foo.js" defer></script>
<script charset="utf-8">alert('你好');</script>
</head>