Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

190
Views
Import file in webpack only if file exists in ES6 syntax

Basically, I need to get variable from file, otherwise to get variable from default file.

I see best solution as:

import { variable } from "file.js"; // if variable exists
import { variable } from "default.js"; // otherwise import variable from default

But if file.js not exists I get an error. And its expecting, but not needs for me in this case. Is it possible to fix it with webpack and just ignore this import if file not exists?

An import() statement isn't fit because I need import on build stage, not dynamic import at runtime.

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs