New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

rollup-plugin-import-lithtml

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-import-lithtml

A Rollup plugin to import lit-html from an external .html file, allowing the html to be separated from the JavaScript.

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
17
325%
Maintainers
1
Weekly downloads
 
Created
Source

rollup-plugin-import-lithtml

A Rollup plugin to import lit-html from an external .html file. This allows separation of the Javascript and HTML. The plugin will automatically add all directive imports meaning the html file can just deal with the markup.

Install

Using npm:

npm install rollup-plugin-import-lithtml --save-dev

Basic Usage

Create a rollup.config.js configuration file and import the plugin:

import importLitHtml from 'rollup-plugin-import-lithtml';

export default {
    input: 'src/index.js',
    output: {
        file: 'bundle.js',
        format: 'esm'
    },
    plugins: [
         importLitHtml()
    ],
}

Advanced Usage

Create a rollup.config.js configuration file and import the plugin:

import importLitHtml from 'rollup-plugin-import-lithtml';

export default {
    input: 'src/index.js',
    output: {
        file: 'bundle.js',
        format: 'esm'
    },
    plugins: [
         importLitHtml({
            include: '**/*.html',
            directives: ['ifDefined', 'unsafeHTML','unsafeSVG', 'when','classMap']
        })
    ],
    //other plugins go here
}

You can manually specifiy which lit-html directives your HTML files use.

The configuration above will import a HTML file like the following:

Test.html

<style>
    .color{
        color:red;
    }
</style>
<div class=${classMap(this.classes)}>
    Hello, ${this.name}
</div>

The above HTML file would be imported from a JavaScript file similar to this:

Test.js : lit-html

import template from './test.html';
import {render} from 'lit';

let htm = template.call({name: 'Joe', classes:{color:true}});
render(htm, document.body);

Test.js: Lit-Element web component

import template from './test.html';
import { LitElement } from 'lit';
import { property, customElement } from 'lit/decorators.js';

@customElement('hello-world')
export class HelloWorld extends LitElement {
    @property()
    classes = { color: true };
    @property()
    name = 'Joe Bloggs';
    
    render() {
        return template.call(this);
    }
}


Options

directives

Type: Array[directiveName : String] : Optional

Describes the list of directives to be imported, meaning that only the HTML need to go into the .HTML file. (no imports).
If not present, the plugin will import all directives.

Keywords

rollup-plugin

FAQs

Package last updated on 27 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts