From 6151243b1084406671743f22cad15a94bf3bbc69 Mon Sep 17 00:00:00 2001 From: Arcadio Quintero Date: Fri, 20 Dec 2024 11:53:01 -0500 Subject: [PATCH] feat(sdk-analytics) fix details building, add readme to the build, fix import in the example --- core-web/libs/sdk/analytics/README.md | 3 +-- core-web/libs/sdk/analytics/vite.config.mts | 23 +++++++++++++++++---- examples/nextjs/src/components/my-page.js | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/core-web/libs/sdk/analytics/README.md b/core-web/libs/sdk/analytics/README.md index d62334579ae..3b9908b9d4b 100644 --- a/core-web/libs/sdk/analytics/README.md +++ b/core-web/libs/sdk/analytics/README.md @@ -38,8 +38,7 @@ Wrap your application with the `DotContentAnalyticsProvider`: // Example configuration const analyticsConfig = { apiKey: 'your-api-key-from-dotcms-analytics-app', - server: 'https://your-dotcms-instance.com', - debug: false // Not required + server: 'https://your-dotcms-instance.com' }; function App() { diff --git a/core-web/libs/sdk/analytics/vite.config.mts b/core-web/libs/sdk/analytics/vite.config.mts index c0c201c89d4..247a5bf36a9 100644 --- a/core-web/libs/sdk/analytics/vite.config.mts +++ b/core-web/libs/sdk/analytics/vite.config.mts @@ -1,18 +1,31 @@ /// import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; import react from '@vitejs/plugin-react'; +import fs from 'fs'; import * as path from 'path'; import { defineConfig } from 'vite'; import dts from 'vite-plugin-dts'; +// Plugin simple para copiar README.md +const copyReadme = { + name: 'copy-readme', + writeBundle() { + fs.copyFileSync( + path.resolve(__dirname, 'README.md'), + path.resolve(__dirname, '../../../dist/libs/sdk/analytics/README.md') + ); + } +}; + export default defineConfig({ root: __dirname, - cacheDir: '../../../node_modules/.vite/libs/sdk/sdk-analytics', + cacheDir: '../../../node_modules/.vite/libs/sdk/analytics', plugins: [ react(), nxViteTsPaths(), - dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') }) + dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') }), + copyReadme ], // Uncomment this if you are using workers. @@ -23,7 +36,7 @@ export default defineConfig({ // Configuration for building your library. // See: https://vitejs.dev/guide/build.html#library-mode build: { - outDir: '../../../dist/libs/sdk/sdk-analytics', + outDir: '../../../dist/libs/sdk/analytics', emptyOutDir: true, reportCompressedSize: true, commonjsOptions: { @@ -41,7 +54,9 @@ export default defineConfig({ output: { exports: 'named', preserveModules: true, - preserveModulesRoot: 'src' + preserveModulesRoot: 'src', + entryFileNames: '[name].js', + chunkFileNames: '[name].js' } } } diff --git a/examples/nextjs/src/components/my-page.js b/examples/nextjs/src/components/my-page.js index cd3667a8084..42111c44c0c 100644 --- a/examples/nextjs/src/components/my-page.js +++ b/examples/nextjs/src/components/my-page.js @@ -17,6 +17,7 @@ import Header from "./layout/header/header"; import Navigation from "./layout/navigation"; import NotFound from "@/app/not-found"; +import { withExperiments } from "@dotcms/experiments"; import { usePageAsset } from "../hooks/usePageAsset"; /**