1.2.0 • Published 4 years ago

html-scoped-component-importer v1.2.0

Weekly downloads
69
License
MIT
Repository
github
Last release
4 years ago

Build Status

#html-scoped-component-importer

This is a simple tool to let you create and dynamically import scoped components. All you need is a html element with the data-component attribute and it will be imported and initialized.

Index

Installation

yarn

yarn add html-scoped-component-importer

npm

npm install --save html-scoped-component-importer

Usage

webpack config

module.exports = {
  ...
  resolve: {
    alias: {
      COMPONENTS: path.resolve(__dirname, '{your components folder}'),
    }
  }
  ...
}

main.js

import { ComponentDispatcher } from 'html-scoped-component-importer';

const compDispatcher = new ComponentDispatcher();
compDispatcher.createAsyncComponents();

ExampleComponent.js

export default class ExampleComponent {
  constructor(element) {
    super(element);
    element.innerHTML = element.dataset.component;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Title</title>
  <script async="async" defer="defer" src="main.js"></script>
</head>

<body>
  <div data-component="ExampleComponent"></div>
</body>
1.2.0

4 years ago

1.1.6

4 years ago

1.1.4

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago