2

I have a Vue js application made using the Vue cli 3. I am using sass loader and node-sass in my project.

If I have multiple subdomain for same code eg site1.mysite.com and site2.mysite.com how can I load a different css file depending on the subdomain?

I already have a JavaScript function in a file to return the subdomain value.

In my app.vue file I have a scss style section is there a way to access this function in the scss and then load the relevant CSS for the subdomain assuming that I have named the css/scss files in a structured way.

Example:

site1_theme.scss and site2_theme.scss in a root folder /assets/scss

Or is there a different way to do this?

Thanks in advance for your help.

1 Answer 1

1

Have yo tried using dynamic imports?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports

So something along the lines of:

if (domain === 'site1.mysite.com') {
    import('/assets/scss/site1_theme.scss');
} else {
    import('/assets/scss/site2_theme.scss');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.