Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed Jan 4, 2024
1 parent 0164c90 commit 522f73e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-vercel-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@docusaurus/types": "3.0.0",
"@docusaurus/utils-validation": "3.0.0",
"@vercel/analytics": "^1.1.1",
"webpack": "^5.88.1",
"tslib": "^2.6.0"
},
"peerDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions packages/docusaurus-plugin-vercel-analytics/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
*/
import {inject} from '@vercel/analytics';

/* eslint-disable prefer-destructuring */
const VERCEL_ANALYTICS_DEBUG = process.env.VERCEL_ANALYTICS_DEBUG;
const VERCEL_ANALYTICS_MODE = process.env.VERCEL_ANALYTICS_MODE;

// todo fix type error
inject({
mode: 'production',
debug: false,
mode: VERCEL_ANALYTICS_MODE ?? 'production',
debug: VERCEL_ANALYTICS_DEBUG ?? false,
});
26 changes: 24 additions & 2 deletions packages/docusaurus-plugin-vercel-analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,38 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Plugin} from '@docusaurus/types';
import webpack from 'webpack';
import type {LoadContext, Plugin} from '@docusaurus/types';
import type {PluginOptions} from '@docusaurus/plugin-vercel-analytics';

export default function pluginVercelAnalytics(): Plugin {
export default function pluginVercelAnalytics(
context: LoadContext,
options: PluginOptions,
): Plugin {
const isProd = process.env.NODE_ENV === 'production';

const {debug, mode} = options;

return {
name: 'docusaurus-plugin-vercel-analytics',

getClientModules() {
return isProd ? ['./analytics'] : [];
},

configureWebpack() {
if (!isProd) {
return {};
}

return {
plugins: [
new webpack.EnvironmentPlugin({
VERCEL_ANALYTICS_DEBUG: debug,
VERCEL_ANALYTICS_MODE: mode,
}),
],
};
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

declare module '@docusaurus/plugin-vercel-analytics' {
export type PluginOptions = {
/**
* Turn debug mode on
*/
debug?: boolean;
/**
* TODO add description
*/
mode: 'auto' | 'development' | 'production';
};

export type Options = Partial<PluginOptions>;
}

0 comments on commit 522f73e

Please sign in to comment.