-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
102 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
import { defineBuildConfig } from 'unbuild'; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
'src/index', | ||
], | ||
entries: ['src/index', 'src/vite', 'src/nuxt'], | ||
declaration: true, | ||
clean: true, | ||
rollup: { | ||
emitCJS: true, | ||
}, | ||
}); | ||
emitCJS: true | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export function hello() { | ||
return 'world'; | ||
} | ||
export * from './plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { NuxtModule } from '@nuxt/schema'; | ||
|
||
import { defineNuxtModule } from '@nuxt/kit'; | ||
|
||
import { UnpluginAnalytics, type Options } from './plugin'; | ||
|
||
const nuxtModule = defineNuxtModule<Options>({ | ||
meta: { | ||
// Usually the npm package name of your module | ||
name: 'unplugin-analytics/nuxt', | ||
// The key in `nuxt.config` that holds your module options | ||
configKey: 'analytics', | ||
// Compatibility constraints | ||
compatibility: { | ||
// Semver version of supported nuxt versions | ||
nuxt: '^3.0.0' | ||
} | ||
}, | ||
// Default configuration options for your module, can also be a function returning those | ||
defaults: {}, | ||
// Shorthand sugar to register Nuxt hooks | ||
hooks: {}, | ||
setup(options: Options = {}, nuxt) { | ||
// // install webpack plugin | ||
// nuxt.hook('webpack:config', async (config: any) => { | ||
// config.plugins = config.plugins || []; | ||
// config.plugins.unshift(UnpluginAnalytics.webpack(options)); | ||
// }); | ||
// // install vite plugin | ||
// nuxt.hook('vite:extendConfig', async (config: any) => { | ||
// config.plugins = config.plugins || []; | ||
// config.plugins.push(UnpluginAnalytics.vite(options)); | ||
// }); | ||
} | ||
}) as NuxtModule<Options>; | ||
|
||
export default nuxtModule; | ||
|
||
declare module '@nuxt/schema' { | ||
interface NuxtConfig { | ||
analytics?: Options; | ||
} | ||
|
||
interface NuxtOptions { | ||
analytics?: Options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createUnplugin } from 'unplugin'; | ||
|
||
import { type AnalyticsOptions, generate } from '@unplugin-analytics/core'; | ||
|
||
import { renderScriptTag } from '../../../vite-plugin-analytics/src/render'; | ||
|
||
export interface Options { | ||
/** | ||
* Whether inject scripts during development | ||
*/ | ||
dev?: boolean; | ||
|
||
analytics?: AnalyticsOptions; | ||
} | ||
|
||
export const UnpluginAnalytics = createUnplugin<Options | undefined>((options = {}) => { | ||
const tags = generate(options.analytics ?? []); | ||
|
||
return { | ||
name: 'unplugin-analytics', | ||
vite: { | ||
transformIndexHtml(_html, ctx) { | ||
if (options.dev && ctx.server) { | ||
return; | ||
} | ||
return tags.map(renderScriptTag).filter(Boolean); | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { UnpluginAnalytics } from './plugin'; | ||
|
||
export default UnpluginAnalytics.vite; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.