Skip to content

Commit

Permalink
✨ feat: Add package version to the CdnClient class
Browse files Browse the repository at this point in the history
  • Loading branch information
honzabubenik committed Mar 17, 2024
1 parent 5d60c36 commit 1a90771
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"typedoc": "^0.25.12",
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-missing-exports": "^2.2.0",
"unplugin-replace": "^0.2.1",
"vite": "^5.1.6",
"vite-bundle-visualizer": "^1.1.0",
"vite-plugin-dts": "^3.7.3",
Expand Down
2 changes: 2 additions & 0 deletions src/cdn/cdn-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class CdnClient {

protected context: Context;

public static version = '__CLIENT_VERSION__';

protected constructor(options: CdnClientOptions) {
const metafileContext: MetafileContext = new MetafileContext(options);
const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);
Expand Down
33 changes: 14 additions & 19 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from 'vite';
import { resolve } from 'node:path';
import dts from 'vite-plugin-dts'; // Generate index.d.ts file
import terser from '@rollup/plugin-terser'; // Minify output
import Replace from 'unplugin-replace/vite'; // Replace variables in files
import pkg from './package.json';

const banner: string = `/* ${pkg.name}@${pkg.version}
Expand All @@ -24,42 +25,29 @@ export default defineConfig({
sourcemap: true,
rollupOptions: {
output: [
// Node ES Module
{
format: 'esm',
entryFileNames: 'localazy-cdn-client.js',
banner,
},
{
format: 'esm',
entryFileNames: 'localazy-cdn-client.min.js',
banner,
plugins: [
terser(),
],
},
// Node CommonJS
{
format: 'cjs',
dir: 'dist/node',
entryFileNames: 'localazy-cdn-client.cjs',
banner,
},
// Browser ES Module
{
format: 'cjs',
dir: 'dist/node',
entryFileNames: 'localazy-cdn-client.min.cjs',
format: 'esm',
entryFileNames: 'localazy-cdn-client.min.js',
banner,
plugins: [
terser(),
],
},
{
format: 'umd',
dir: 'dist/browser',
entryFileNames: 'localazy-cdn-client.umd.js',
banner,
name: 'LocalazyCDN',
esModule: false,
},
// Browser UMD + JS CDNs
{
format: 'umd',
dir: 'dist/browser',
Expand All @@ -81,5 +69,12 @@ export default defineConfig({

plugins: [
dts({ rollupTypes: true }),

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Replace({
values: {
__CLIENT_VERSION__: pkg.version,
},
}),
],
});

0 comments on commit 1a90771

Please sign in to comment.