@nuxtjs/partytown!npx nuxi@latest module add partytown
nuxt.config.ts 的 modules 部分export default defineNuxtConfig({
modules: ['@nuxtjs/partytown'],
})
type: 'text/partytown' 属性。<template>
<div>
<Script type="text/partytown" src="https://example.com/analytics.js" />
</div>
</template>
Partytown 支持多种选项,您可以在 nuxt.config.ts 文件中传入。
export default defineNuxtConfig({
// ...
partytown: {
/**
* When `true`, Partytown scripts are not minified. See https://partytown.builder.io/configuration
* on how to enable more logging.
*
* @default true in development
*/
debug: boolean
/**
* Path (relative to your base URL) where the Partytown library should be served from.
*
* @default '~partytown'
*/
lib: string
// For other options, see https://partytown.builder.io/configuration
},
})
export default defineNuxtConfig({
modules: ['@nuxtjs/partytown'],
partytown: {
forward: ['$crisp', '$crisp.push'],
},
app: {
head: {
script: [
// Insert your CRISP Script here e.g.:
{ innerHTML: 'window.$crisp = []; window.CRISP_WEBSITE_ID = "0000"' },
{ src: 'https://#/l.js', async: true, type: 'text/partytown' },
],
},
},
})
export default defineNuxtConfig({
modules: ['@nuxtjs/partytown'],
partytown: {
forward: ['dataLayer.push'],
},
app: {
head: {
script: [
// Insert your Google Tag Manager Script here
{ src: '-', async: true, type: 'text/partytown' },
],
},
},
})
export default defineNuxtConfig({
modules: ['@nuxtjs/partytown'],
partytown: {
forward: ['$plausible', '$plausible.push'],
},
app: {
head: {
script: [
{ innerHTML: 'window.$plausible = [];' },
// Update this
{
src: 'https://#/js/script.js',
defer: true,
type: 'text/partytown',
'data-domain': 'your-domains',
},
],
},
},
})
yarn prepare 生成类型存根。yarn dev 以开发模式启动 playground。