This project shows how to add vuejs 3 into salesforce.
Here are the steps that we will take:
- Making sure you have a Salesforce Org
- Installing Vuejs
- Setting up vuejs to work with Salesforce
- Deploying your vue app to Salesforce
- Any org you can create a domain and component should work. 1.1. You also need the My Domain. 1.1. Here is a quickly doc on how to do it.
- Create a folder called vue3withSalesforce
- mkdir vue3withSalesforce
- Access the folder and install vue3 using VueCli
- cd vue3withSalesforce
- npm install -g @vue/cli
- vue create vue-app
- I selected every option as default on vue installation.
- Testing your app
- cd vue-app
- npm run serve
- Changing Vue Configuration
- We also need to tell vue to change the path of the file.
- Create a file in the root(same place as you have the package.json) called vue.config.js
- Add this content in the vue.config.js
module.exports = { // options... publicPath: './', };
- Let’s compile and deploy the app to Salesforce
- In the vue-app folder build the app
- npm run build
- This command will create a dist folder
- npm run build
- Creating the static resource
- Go inside of dist folder in your Windows Explore or Finder
- Select all the files and zip/compress that
- Do NOT zip the dist folder, zip only the files
- You can give any name, Ex. vueapp
- Go to your salesforce org
- Setup >> Static Resources >> Import that file
- Now we need to create the Salesforce Container that will use that static file.
- Open the Developer Console
- File >> New >> Lightning Component
- Name: vueappbundle
- Enable the Lightning Page.
- Click on Submit.
- The component will open for you.
- Click on Component
- Add the code below <aura:component implements="flexipage:availableForAllPageTypes" access="global" > <lightning:container src="{!$Resource.vueapp + '/index.html'}" /> </aura:component>
- Add these styles to make your iframe responsive. /** Making the iFrame Responsive - Begin **/ .THIS.lightningContainer>iframe{ position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 100%; height: 100%; }
.THIS.lightningContainer { position: relative; overflow: hidden; width: 100%; padding-top: 56.25%; } /** Making the iFrame Responsive - End **/ 1. 2. Your component is ready to be added into a page.
Adding the Component in a Record Page.
- Go to Services App in Salesforce
- Click on Account Tab
- Select an Account
- Click on the Engine Icon close to your name, and click Edit Page.
- In your left menu, you will see your component
- Drag and drop your component and it should render.