add nextjs with approuter example
This commit is contained in:
parent
7c9dc72df1
commit
90317d71d3
18 changed files with 623 additions and 2040 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -14,9 +14,6 @@ coverage
|
|||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
|
@ -27,4 +24,6 @@ yarn-error.log*
|
|||
# turbo
|
||||
.turbo
|
||||
|
||||
dist
|
||||
# bundler output
|
||||
dist
|
||||
.next
|
5
examples/next-with-approuter/next-env.d.ts
vendored
Normal file
5
examples/next-with-approuter/next-env.d.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
4
examples/next-with-approuter/next.config.js
Normal file
4
examples/next-with-approuter/next.config.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {}
|
||||
|
||||
module.exports = nextConfig
|
21
examples/next-with-approuter/package.json
Normal file
21
examples/next-with-approuter/package.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "next-with-approuter",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "20.5.7",
|
||||
"@types/react": "18.2.21",
|
||||
"@types/react-dom": "18.2.7",
|
||||
"next": "13.4.19",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"typescript": "5.2.2",
|
||||
"@aptabase/next": "*"
|
||||
}
|
||||
}
|
11
examples/next-with-approuter/src/app/layout.tsx
Normal file
11
examples/next-with-approuter/src/app/layout.tsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
)
|
||||
}
|
9
examples/next-with-approuter/src/app/page.tsx
Normal file
9
examples/next-with-approuter/src/app/page.tsx
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { getName } from '@aptabase/next'
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main>
|
||||
Hello from Next.js App Router: {getName()}
|
||||
</main>
|
||||
)
|
||||
}
|
27
examples/next-with-approuter/tsconfig.json
Normal file
27
examples/next-with-approuter/tsconfig.json
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
2435
package-lock.json
generated
2435
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,7 @@
|
|||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"examples/*",
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
|
@ -11,9 +12,8 @@
|
|||
"format": "prettier --write \"**/*.{ts,tsx,md}\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "latest",
|
||||
"turbo": "latest",
|
||||
"turboversion": "^0.1.0"
|
||||
"prettier": "3.0.3",
|
||||
"turbo": "1.10.13"
|
||||
},
|
||||
"engines": {
|
||||
"npm": ">=7.0.0",
|
||||
|
@ -23,6 +23,5 @@
|
|||
"singleQuote": true,
|
||||
"tabWidth": 2,
|
||||
"printWidth": 120
|
||||
},
|
||||
"packageManager": "yarn@1.22.5"
|
||||
}
|
||||
}
|
||||
|
|
47
packages/next/package.json
Normal file
47
packages/next/package.json
Normal file
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "@aptabase/next",
|
||||
"version": "0.0.1",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
"description": "Next.js SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./dist/index.js",
|
||||
"import": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/aptabase/aptabase-js.git",
|
||||
"directory": "packages/js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/aptabase/aptabase-js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/aptabase/aptabase-js",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "rollup -c ./rollup.config.mjs",
|
||||
"watch": "rollup -c ./rollup.config.mjs -w",
|
||||
"prepublishOnly": "npm run build",
|
||||
"pretest": "npm run build"
|
||||
},
|
||||
"files": [
|
||||
"README.md",
|
||||
"LICENSE",
|
||||
"dist",
|
||||
"package.json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-replace": "5.0.2",
|
||||
"@rollup/plugin-typescript": "11.1.3",
|
||||
"rollup": "3.28.1",
|
||||
"@rollup/plugin-terser": "0.4.3",
|
||||
"tslib": "2.6.2",
|
||||
"typescript": "5.2.2"
|
||||
}
|
||||
}
|
38
packages/next/rollup.config.mjs
Normal file
38
packages/next/rollup.config.mjs
Normal file
|
@ -0,0 +1,38 @@
|
|||
import replace from '@rollup/plugin-replace';
|
||||
import terser from '@rollup/plugin-terser';
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import pkg from './package.json' assert { type: 'json' };
|
||||
|
||||
const plugins = [
|
||||
terser(),
|
||||
replace({
|
||||
'env.PKG_VERSION': pkg.version,
|
||||
preventAssignment: true,
|
||||
}),
|
||||
typescript({
|
||||
tsconfig: './tsconfig.json',
|
||||
moduleResolution: 'node',
|
||||
}),
|
||||
];
|
||||
|
||||
const cjs = {
|
||||
input: './src/index.ts',
|
||||
output: {
|
||||
dir: './dist',
|
||||
entryFileNames: '[name].js',
|
||||
format: 'cjs',
|
||||
},
|
||||
plugins,
|
||||
};
|
||||
|
||||
const es = {
|
||||
input: './src/index.ts',
|
||||
output: {
|
||||
dir: './dist',
|
||||
entryFileNames: '[name].mjs',
|
||||
format: 'es',
|
||||
},
|
||||
plugins,
|
||||
};
|
||||
|
||||
export default [cjs, es];
|
3
packages/next/src/index.ts
Normal file
3
packages/next/src/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function getName() {
|
||||
return "next"
|
||||
}
|
16
packages/next/tsconfig.json
Normal file
16
packages/next/tsconfig.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES5",
|
||||
"strict": true,
|
||||
"allowJs": true,
|
||||
"esModuleInterop": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"types": ["@types"]
|
||||
},
|
||||
"declaration": true,
|
||||
"declarationDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": ["./"]
|
||||
}
|
3
packages/web/.gitignore
vendored
3
packages/web/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
node_modules
|
||||
dist
|
||||
.DS_Store
|
|
@ -13,11 +13,7 @@ A tiny SDK (1 kB) to instrument your web app with Aptabase, an Open Source, Priv
|
|||
Install the SDK using your preferred JavaScript package manager
|
||||
|
||||
```bash
|
||||
pnpm add @aptabase/web
|
||||
# or
|
||||
npm add @aptabase/web
|
||||
# or
|
||||
yarn add @aptabase/web
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
@ -27,9 +23,9 @@ First you need to get your `App Key` from Aptabase, you can find it in the `Inst
|
|||
Initialized the SDK using your `App Key`:
|
||||
|
||||
```js
|
||||
import { init } from "@aptabase/web";
|
||||
import { init } from '@aptabase/web';
|
||||
|
||||
init("<YOUR_APP_KEY>"); // 👈 this is where you enter your App Key
|
||||
init('<YOUR_APP_KEY>'); // 👈 this is where you enter your App Key
|
||||
```
|
||||
|
||||
The init function also supports an optional second parameter, which is an object with the `appVersion` property.
|
||||
|
@ -39,10 +35,10 @@ It's up to you to decide what to get the version of your app, but it's generally
|
|||
Afterwards you can start tracking events with `trackEvent`:
|
||||
|
||||
```js
|
||||
import { trackEvent } from "@aptabase/web";
|
||||
import { trackEvent } from '@aptabase/web';
|
||||
|
||||
trackEvent("connect_click"); // An event with no properties
|
||||
trackEvent("play_music", { name: "Here comes the sun" }); // An event with a custom property
|
||||
trackEvent('connect_click'); // An event with no properties
|
||||
trackEvent('play_music', { name: 'Here comes the sun' }); // An event with a custom property
|
||||
```
|
||||
|
||||
A few important notes:
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
"scripts": {
|
||||
"build": "rollup -c ./rollup.config.mjs",
|
||||
"watch": "rollup -c ./rollup.config.mjs -w",
|
||||
"prepublishOnly": "yarn build",
|
||||
"pretest": "yarn build"
|
||||
"prepublishOnly": "npm run build",
|
||||
"pretest": "npm run build"
|
||||
},
|
||||
"files": [
|
||||
"README.md",
|
||||
|
@ -38,10 +38,10 @@
|
|||
],
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-replace": "5.0.2",
|
||||
"@rollup/plugin-typescript": "11.1.0",
|
||||
"rollup": "3.21.6",
|
||||
"@rollup/plugin-terser": "0.4.1",
|
||||
"tslib": "2.5.0",
|
||||
"typescript": "5.0.4"
|
||||
"@rollup/plugin-typescript": "11.1.3",
|
||||
"rollup": "3.28.1",
|
||||
"@rollup/plugin-terser": "0.4.3",
|
||||
"tslib": "2.6.2",
|
||||
"typescript": "5.2.2"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue