0

I need to import with condition. I am using below code and getting error.

if (window.location.hostname == 'sellbutton') {
  import serviceToUSe from '../public/service/sellbutton.com.json';
} else {
  import serviceToUSe from '../public/service/default.json';
}

1 Answer 1

1

I think you need to first declare an empty place to conditionally store the data after using require instead of importing:

//This might an object {} or array [] depending on your json data structure. 
var serviceToUSe = {};

if (window.location.hostname == 'sellbutton') {
  serviceToUSe = require('../public/service/sellbutton.com.json');
} else {
  serviceToUSe = require('../public/service/default.json');
}
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.