Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
Is vuejs app.js import path can be dynamic or in if else condition?

App.js

Original

import x from 'project/a'

can it be

var project = 'a'

if(project == 'a')
{
   import x from 'project/a'
}
else
{
   import x from 'project/b'
}

or could it use

var project = 'a'
var filepath = '';

if(project == 'a')
{
   filepath = 'project/a';
}
else
{
   filepath = 'project/b';
}

import x from filepath

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could either:

import both and do the conditional

Imagine one file with codes of projectA and projectB and conditional.

import initProjectA
import initProjectB

if (condition) {
  initProjectA()
} else {
  initProjectB()
}

this will be compiled down into something like:

function initProjectA() {
}

function initProjectB() {
}

if (condition) {
  //
}

dynamic imports:

This will produce 3 separate files: projectA, projectB, conditional.

import(module).then(importedModule => {
  importedModule.default() // assuming you did `export default`
})

conditional file will only load either one of them then execute it.

  • check if it should download projectA or projectB
  • once file is downloaded, execute it

You might have to change some configurations to be able to do dynamic imports. You can search for the topic "webpack dynamic imports" on Google.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!