Skip to content

Commit

Permalink
Merging Standard and Embed client
Browse files Browse the repository at this point in the history
- both clients are now merged into the single module
- export `AMPClientFactory` now contains two methods - `create()` and `createEmbed()`
- optimized bundle size with `lodash-webpack-plugin`
  • Loading branch information
tg666 committed Dec 13, 2023
1 parent 3501482 commit 1f0c55e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 68 deletions.
4 changes: 1 addition & 3 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export { ClientFactory as default } from './src/client/standard/client-factory.mjs';
export { ClientFactory as AMPClientFactory } from './src/client/standard/client-factory.mjs';
export { ClientFactory as EmbedAMPClientFactory } from './src/client/embed/client-factory.mjs';
export { ClientFactory as default } from './src/client/client-factory.mjs';
13 changes: 13 additions & 0 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@babel/preset-env": "^7.23.5",
"babel-loader": "^8.3.0",
"eslint": "^8.55.0",
"lodash-webpack-plugin": "^0.11.6",
"path": "^0.12.7",
"terser-webpack-plugin": "^5.3.9",
"webpack": "^5.89.0",
Expand All @@ -43,7 +44,6 @@
"src",
"index.mjs",
"dist/amp-client.min.js",
"dist/amp-client.standalone.min.js",
"dist/amp-client.embed.min.js"
"dist/amp-client.standalone.min.js"
]
}
26 changes: 26 additions & 0 deletions src/client/client-factory.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pkg from '../../package.json';
import { ClientVersion } from './client-version.mjs';
import { Client as StandardClient } from './standard/client.mjs';
import { Client as EmbedClient } from './embed/client.mjs';

const semver = pkg.version;

export class ClientFactory {
static create(options = {}) {
return new StandardClient(
new ClientVersion(semver, `standard@${semver}`),
options,
);
}

static createEmbed(options = {}) {
return new EmbedClient(
new ClientVersion(semver, `embed@${semver}`),
options,
);
}

static get version() {
return semver;
}
}
18 changes: 0 additions & 18 deletions src/client/embed/client-factory.mjs

This file was deleted.

18 changes: 0 additions & 18 deletions src/client/standard/client-factory.mjs

This file was deleted.

13 changes: 2 additions & 11 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@ const path = require('path');
module.exports = {
mode: 'development',
entry: {
standard: {
clientFactory: {
import: './index.mjs',
filename: 'amp-client.js',
library: {
type: 'var',
name: 'AMPClientFactory',
export: 'AMPClientFactory',
export: 'default',
}
},
embed: {
import: './index.mjs',
filename: 'amp-client.embed.js',
library: {
type: 'var',
name: 'AMPClientFactory',
export: 'EmbedAMPClientFactory',
}
}
},
output: {
path: path.resolve(__dirname, 'demo'),
Expand Down
22 changes: 6 additions & 16 deletions webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const LodashWebpackPlugin = require('lodash-webpack-plugin');

const config = {
mode: 'production',
Expand Down Expand Up @@ -33,6 +34,9 @@ const config = {
new TerserWebpackPlugin(),
],
},
plugins: [
new LodashWebpackPlugin(),
],
};

const defaultConfig = Object.assign({}, config, {
Expand All @@ -43,7 +47,7 @@ const defaultConfig = Object.assign({}, config, {
library: {
type: 'var',
name: 'AMPClientFactory',
export: 'AMPClientFactory',
export: 'default',
},
}
});
Expand All @@ -56,7 +60,7 @@ const standaloneConfig = Object.assign({}, config,{
library: {
type: 'var',
name: 'AMPClientFactory',
export: 'AMPClientFactory',
export: 'default',
},
},
externals: {
Expand All @@ -65,21 +69,7 @@ const standaloneConfig = Object.assign({}, config,{
}
});

const embedConfig = Object.assign({}, config, {
name: 'embed',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'amp-client.embed.min.js',
library: {
type: 'var',
name: 'AMPClientFactory',
export: 'EmbedAMPClientFactory',
},
}
});

module.exports = [
defaultConfig,
standaloneConfig,
embedConfig,
];

0 comments on commit 1f0c55e

Please sign in to comment.