Skip to content

Commit 91a3e77

Browse files
authored
Add Webpack Config (#5)
* add webpack config * 0.0.5 * add JSDelivr badge to README
1 parent 64de75b commit 91a3e77

File tree

6 files changed

+593
-25
lines changed

6 files changed

+593
-25
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![](https://img.shields.io/npm/v/@eppo/js-client-sdk)](https://www.npmjs.com/package/@eppo/js-client-sdk)
44
[![](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](https://eppo-exp.github.io/js-client-sdk/js-client-sdk.html)
5+
[![](https://data.jsdelivr.com/v1/package/npm/@eppo/js-client-sdk/badge)](https://www.jsdelivr.com/package/npm/@eppo/js-client-sdk)
56

67
This SDK is for client-side JS applications that run in a web browser. For server-side JS applications, use Eppo's [server-side Node JS SDK](https://github.com/Eppo-exp/node-server-sdk).
78

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "Eppo SDK for client-side JavaScript applications",
55
"main": "dist/index.js",
66
"files": [
@@ -11,13 +11,14 @@
1111
"lint": "eslint '**/*.{ts,tsx}' '**/*.d.{ts,tsx}' --cache",
1212
"lint:fix": "eslint --fix '**/*.{ts,tsx}' --cache",
1313
"lint:fix-pre-commit": "eslint -c .eslintrc.pre-commit.js --fix '**/*.{ts,tsx}' --no-eslintrc --cache",
14-
"prepare": "husky install",
14+
"prepare": "husky install && rm -rf dist/ && tsc && webpack && api-extractor run --local",
1515
"pre-commit": "lint-staged && tsc && yarn docs",
1616
"typecheck": "tsc",
1717
"test": "yarn test:unit",
1818
"test:unit": "NODE_ENV=test jest '.*\\.spec\\.ts'",
19-
"docs": "tsc && api-extractor run --local --verbose && api-documenter markdown -i ./temp -o ./docs"
19+
"docs": "api-documenter markdown -i ./temp -o ./docs"
2020
},
21+
"jsdelivr": "dist/eppo-sdk.js",
2122
"repository": {
2223
"type": "git",
2324
"url": "git+https://github.com/Eppo-exp/js-client-sdk.git"
@@ -33,6 +34,7 @@
3334
"@microsoft/api-documenter": "^7.17.17",
3435
"@microsoft/api-extractor": "^7.25.0",
3536
"@types/jest": "^28.1.1",
37+
"@types/md5": "^2.3.2",
3638
"@typescript-eslint/eslint-plugin": "^5.13.0",
3739
"@typescript-eslint/parser": "^5.13.0",
3840
"eslint": "^8.17.0",
@@ -45,12 +47,17 @@
4547
"jest": "^28.1.1",
4648
"jest-environment-jsdom": "^28.1.1",
4749
"prettier": "^2.7.1",
50+
"terser-webpack-plugin": "^5.3.3",
4851
"testdouble": "^3.16.6",
4952
"ts-jest": "^28.0.5",
50-
"typescript": "^4.7.3",
53+
"ts-loader": "^9.3.1",
54+
"typescript": "^4.7.4",
55+
"webpack": "^5.73.0",
56+
"webpack-cli": "^4.10.0",
5157
"xhr-mock": "^2.5.1"
5258
},
5359
"dependencies": {
54-
"axios": "^0.27.2"
60+
"axios": "^0.27.2",
61+
"md5": "^2.3.0"
5562
}
5663
}

src/eppo-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createHash } from 'crypto';
1+
import * as md5 from 'md5';
22

33
import { IAssignmentEvent, IAssignmentLogger } from './assignment-logger';
44
import { MAX_EVENT_QUEUE_SIZE, NULL_SENTINEL, SESSION_ASSIGNMENT_CONFIG_LOADED } from './constants';
@@ -147,7 +147,7 @@ export default class EppoClient implements IEppoClient {
147147
subjectKey: string,
148148
experimentConfig: IExperimentConfiguration,
149149
): string {
150-
const subjectHash = createHash('md5').update(subjectKey).digest('hex');
150+
const subjectHash = md5(subjectKey);
151151
return experimentConfig?.overrides[subjectHash];
152152
}
153153

src/shard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { createHash } from 'crypto';
1+
import * as md5 from 'md5';
22

33
import { IShardRange } from './experiment/variation';
44

55
export function getShard(input: string, subjectShards: number): number {
6-
const hashOutput = createHash('md5').update(input).digest('hex');
6+
const hashOutput = md5(input);
77
// get the first 4 bytes of the md5 hex string and parse it using base 16
88
// (8 hex characters represent 4 bytes, e.g. 0xffffffff represents the max 4-byte integer)
99
const intFromHash = parseInt(hashOutput.slice(0, 8), 16);

webpack.config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const path = require('path');
2+
3+
const TerserPlugin = require('terser-webpack-plugin');
4+
5+
module.exports = {
6+
entry: './src/index.ts',
7+
mode: 'production',
8+
devtool: 'inline-source-map',
9+
target: 'web',
10+
module: {
11+
rules: [
12+
{
13+
test: /\.tsx?$/,
14+
use: 'ts-loader',
15+
exclude: /node_modules/,
16+
},
17+
],
18+
},
19+
resolve: {
20+
extensions: ['.tsx', '.ts', '.js'],
21+
},
22+
output: {
23+
filename: 'eppo-sdk.js',
24+
library: {
25+
name: 'eppo',
26+
type: 'var',
27+
},
28+
path: path.resolve(__dirname, 'dist'),
29+
},
30+
optimization: {
31+
minimize: true,
32+
minimizer: [new TerserPlugin()],
33+
},
34+
};

0 commit comments

Comments
 (0)