Please I’m currently developing a component library for my component using vue.js(2.x) to be published on npm after I have run the build-library script in my package.json file I ended up with a 4MB dist folder, this happens as a result of the dependencies imported in my helpers file and this helper function was used in one of my components src/components/VdaAccount.vue
Please how can I drastically reduce the build size to KB?
here is the file in my helper function :
src/helpers/veridaHelper.ts
import { EnvironmentType, Network } from "@verida/client-ts";
import { EventEmitter } from "events";
import store from "store";
import { hasSession, VaultAccount } from "@verida/account-web-vault";
import { Profile, Connect } from "../interface";
const VUE_APP_VAULT_CONTEXT_NAME = "Verida: Vault";
const CONTEXT_NAME_IN_LOCAL_STORAGE = "AppContext";
const VUE_APP_VERIDA_TESTNET_DEFAULT_SERVER =
"https://db.testnet.verida.io:5002/";
const VUE_APP_LOGO_URL =
"https://assets.verida.io/verida_login_request_logo_170x170.png";
class VeridaHelpers extends EventEmitter {
private client: any;
public profile?: Profile;
public context: any;
private account: any;
public did?: string;
public connected?: boolean;
public contextName?: string;
constructor() {
super();
this.contextName = store.get(CONTEXT_NAME_IN_LOCAL_STORAGE);
}
public async connect({ contextName, logo }: Connect): Promise<void> {
this.account = new VaultAccount({
defaultDatabaseServer: {
type: "VeridaDatabase",
endpointUri: VUE_APP_VERIDA_TESTNET_DEFAULT_SERVER,
},
defaultMessageServer: {
type: "VeridaMessage",
endpointUri: VUE_APP_VERIDA_TESTNET_DEFAULT_SERVER,
},
vaultConfig: {
request: {
logoUrl: logo || VUE_APP_LOGO_URL,
},
},
});
if (!this.contextName) {
this.contextName = contextName;
store.set(CONTEXT_NAME_IN_LOCAL_STORAGE, contextName);
}
this.context = await Network.connect({
client: {
environment: EnvironmentType.TESTNET,
},
account: this.account,
context: {
name: contextName,
},
});
this.did = await this.account.did();
await this.initProfile();
if (this.context) {
this.connected = true;
}
this.emit("connected", this.connected);
}
private async initProfile(): Promise<void> {
const client = await this.context.getClient();
const profile = await client.openPublicProfile(this.did, VUE_APP_VAULT_CONTEXT_NAME);
const cb = async () => {
const data = await profile.getMany();
this.profile = data;
this.emit("profileChanged", this.profile);
};
profile.listen(cb);
await cb();
}
autoLogin() {
return hasSession(this.contextName as string);
}
}
const VeridaHelper = new VeridaHelpers();
export default VeridaHelper;
package.json
{
"name": "component-name",
"version": "0.1.0",
"private": false,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --report",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint",
"build-library": "vue-cli-service build --mode production --target lib --name vue-account ./src/install.ts "
},
"dependencies": {
"@verida/account-web-vault": "^1.1.8",
"@verida/client-ts": "^1.1.11",
"core-js": "^3.6.5",
"events": "^3.3.0",
"store": "^2.0.12",
"vue": "^2.6.11",
"vue-clipboard2": "^0.3.3",
"vue-spinner": "^1.0.4"
},
"devDependencies": {
"@types/events": "^3.0.0",
"@types/jest": "^24.0.19",
"@types/store": "^2.0.2",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-typescript": "~4.5.0",
"@vue/cli-plugin-unit-jest": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/eslint-config-typescript": "^7.0.0",
"@vue/test-utils": "^1.0.3",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^6.2.2",
"node-sass": "^4.12.0",
"prettier": "^2.2.1",
"sass-loader": "^8.0.2",
"typescript": "~4.1.5",
"vue-template-compiler": "^2.6.11"
}
}
src/install.js
import VdaAccount from './components/VdaAccount.vue';
import VdaLogin from './components/VdaLogin.vue';
export default {
install(Vue: any, options: any) {
Vue.component('vda-account', VdaAccount);
Vue.component('vda-login', VdaLogin);
}
};