GithubHelp home page GithubHelp logo

aelbore / rollup-plugin-inline-lit-element Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 0.0 1.7 MB

Rollup plugin to inline external styles in lit-element

JavaScript 24.15% TypeScript 75.85%
lit-element css styles lit-html rollup plugin inline-styles inline-css

rollup-plugin-inline-lit-element's Introduction

npm version License: MIT

rollup-plugin-inline-lit-element

Rollup plugin to inline external styles in lit-element, transpile decorators to native javascript (see Decorators)

Getting Started

git clone https://github.com/aelbore/rollup-plugin-inline-lit-element.git
npm install

Installation

  npm install --save-dev rollup-plugin-inline-lit-element

Examples

Setup

  • hello-world.css

    h1 {
      color: red;
    }
  • hello-world.js

    import { LitElement, html } from 'lit-element'
    import './hello-world.css'
    
    class HelloWorld extends LitElement {
    
      static get properties() {
        return {
          message: { type: String }
        }
      }
    
      render() {
        return html `<h1>Hello ${this.message}</h1>`
      }
    
    }
    
    customElements.define('hello-world', HelloWorld)  
  • rollup.config.js

    import minifyHTML from 'rollup-plugin-minify-html-literals';
    import resolve from 'rollup-plugin-node-resolve'
    
    import { terser } from 'rollup-plugin-terser'
    import { inlineLitElement } from 'rollup-plugin-inline-lit-element'
    
    export default {
      treeshake: true,
      input: 'src/hello-world.js',
      external: [],
      plugins: [
        minifyHTML(),
        inlineLitElement(),
        resolve(),
        terser()
      ],
      output: {
        sourcemap: true,
        globals: {},
        file: 'dist/hello-world.js',
        format: 'esm'
      }
    }  
  • output of your hello-world.js

     import { LitElement, html, css } from 'lit-element'
    
     class HelloWorld extends LitElement {
    
       static get styles() {
         return css `h1 { color: red; }`
       }
    
       static get properties() {
         return {
           message: { type: String }
         }
       }
    
       render() {
         return html `<h1>Hello ${this.message}</h1>`
       }
    
     }
    
     customElements.define('hello-world', HelloWorld)  

Support Sass

  npm install --save-dev node-sass

Use Lit-Element-Transpiler

git submodule init
git submodule update --remote

npm run link.transpiler

rollup-plugin-inline-lit-element's People

Contributors

aelbore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rollup-plugin-inline-lit-element's Issues

[QUESTION] Multiple shareable CSS

Does this support inlining multiple shareable CSS component?

/** common.css */
:host {
  display: block;
}

* {
  box-sizing: border-box;
}
/** button.css */
button {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  background: inherit;
  color: inherit;
  font: inherit;
  border: none;
}
/** Input */
...
import 'common.css';
import 'button.css';

...
/** Expected output */
...
static styles = [
  css`:host { display: block; }`,
  css`button { ... /** Truncate for brevity */ }`,
];
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.