Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda