In my current project we're building native web components according to the v1 specification which we're currently webpacking in a single bundle comp-webcomponents.js
.
This is the entry point file for our current bundle:
import 'document-register-element';
import 'nodelist-foreach-polyfill';
import 'babel-polyfill';
import 'components/tabs/comp-tabs';
import 'components/workspace-switcher/workspace-switcher';
import 'components/table/comp-table';
import 'components/date/comp-date';
import 'components/datepicker/comp-datepicker';
import 'components/datetime/comp-datetime';
import 'components/decimal/comp-decimal';
import 'components/number/comp-number';
import 'components/editor/comp-editor';
import 'components/time/comp-time';
import 'components/input/comp-input';
import 'components/button/comp-button';
import 'components/toggle-button/comp-toggle-button';
import 'components/yearmonth/comp-yearmonth';
Some of the components have vendor dependencies like jQuery, datatables.net, jquery-ui, lodash etc.
Question 1: What steps would be required so other projects can selectively import single webcomponents?
Something like
import { compTable, compYearmonth } from "@comp-webcomponents";
Question 2: What would be required to make each web component an npm package which can be installed using a single namespace?
Something like
npm install --save @comp-webcomponents/comp-div
Example component:
class CompDiv extends HTMLDivElement {
constructor(...args) {
const self = super(...args);
self.property = null;
return self;
}
connectedCallback() {
console.log('connected CompDiv');
}
}
customElements.define('comp-div', CompDiv, { extends: 'div' });