Skip to content

Commit

Permalink
feat(sdk-analytics) fix details building sdk-analytics (#31002)
Browse files Browse the repository at this point in the history
### Proposed Changes
* Add Readme to build lib
* Fix import in the example
* Fix format build files

### Checklist
- [ ] Tests
- [ ] Translations
- [ ] Security Implications Contemplated (add notes if applicable)

### Additional Info
** any additional useful context or info **

### Screenshots
Original             |  Updated
:-------------------------:|:-------------------------:
** original screenshot **  |  ** updated screenshot **
  • Loading branch information
oidacra authored Dec 20, 2024
1 parent 7cc5143 commit 967088f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 1 addition & 2 deletions core-web/libs/sdk/analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
23 changes: 19 additions & 4 deletions core-web/libs/sdk/analytics/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
/// <reference types='vitest' />
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.
Expand All @@ -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: {
Expand All @@ -41,7 +54,9 @@ export default defineConfig({
output: {
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src'
preserveModulesRoot: 'src',
entryFileNames: '[name].js',
chunkFileNames: '[name].js'
}
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs/src/components/my-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down

0 comments on commit 967088f

Please sign in to comment.