I am currently developing a Vue 3 web application that is intended to be deployed for various customers, each with their own unique title, logo, and icon.
My goal is to customize the app for each customer by displaying their specific information in the TheFooter.vue
component.
An essential requirement is ensuring that when the app is built for a particular customer, no other customers' data should be present in the final built files within the /dist
folder after running npm run build
, due to privacy concerns.
Here are some approaches I have attempted:
- Creating a file named customers.js to export an object structured as follows:
const customers = {
CUSTOMER_A: {
title: 'Customer A',
logo: 'assets/customer_a_logo.png',
// additional sensitive data
},
CUSTOMER_B: {
title: 'Customer B',
logo: 'assets/customer_b_logo.png',
// additional sensitive data
}
export default const customer[process.env.VUE_APP_CURRENT_CUSTOMER]
Then, defining a key VUE_APP_CURRENT_CUSTOMER
in the .env
file with values such as CUSTOMER_A
, CUSTOMER_B
,...
And importing customer data into TheFooter.vue
as follows:
const customer = require('./customers.js').default
However, upon inspection of the final built JavaScript files in the
/dist
directory, it was observed that other customers' information remained accessible.
Utilizing Vue CLI modes, creating individual
.env.customer_x
files for each customer containing specific data, then referencing the current customer during the build process using the--mode
flag (e.g.
). However, managing numerous .env.customer_... files may become impractical. (Are there any potential drawbacks to this approach?)vue-cli-service build --mode customer_x
Using a json file (e.g. customers.json) and attempting to import it in
TheFooter.vue
like so:
import { process.env.VUE_APP_CURRENT_CUSTOMER } from './customers.json'
It appears impossible to include variables in the import statement, necessitating the use of environment variables (for CI/CD pipelines)
Do you have any suggestions or best practices for addressing this challenge?
Thank you in advance!