Answer the question
In order to leave comments, you need to log in
How to build different js bundles using Common Components (ES6 modules) if these modules have external dependencies?
I don’t understand how to use common es6 modules (from my own module library, for example) when you need to build 2 different js bundles from them (for example, for the desktop and mobile versions of the site). In a situation where these shared modules have external dependencies .
Let's say we need to implement a button repainting in blue when clicking on it.
The structure of the modules in a simplified form is as follows:
// ===== mainMobile.js - главная точка входа
import Button from './button.js';
let colorMain = 'blue';
new Button(document.querySelector('.button'));
export { colorMain }
// ===== button.js
import { colorMain } from './mainMobile.js';
export default class Button {
constructor(elem) {
this.elem = elem;
this.elem.addEventListener('click', () => { this.paint(); })
}
paint() {
this.elem.classList.add(`button_${colorMain}`);
}
}
// ===== mainDesktop.js - главная точка входа
import Button from './button.js';
let colorMain = 'green';
new Button(document.querySelector('.button'));
export { colorMain }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question