Giter Site home page Giter Site logo

bennypowers / rollup-plugin-lit-css Goto Github PK

View Code? Open in Web Editor NEW
35.0 4.0 3.0 204 KB

Moved to https://github.com/bennypowers/lit-css

License: MIT License

rollup rollup-plugin bundling lit-element lit-html webcomponents css hacktoberfest lit css-files

rollup-plugin-lit-css's Introduction

rollup-plugin-lit-css's People

Contributors

bennypowers avatar dependabot[bot] avatar mgenware avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

rollup-plugin-lit-css's Issues

"Unexpected token" while compiling with Sass

Description

Combining rollup-plugin-lit-css and rollup-plugin-styles produces an "Unexpected token" error when mode is set to emit.

https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
lit-element (imported by src/MyComponent.ts)
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/MyComponent.scss (1:0)
1: .big-boi{background-color:#00f;color:red}
   ^
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

Reproduction

You can use the combination of the following files to reproduce this. If you'd prefer this in a different format please let me know.

rollup.config.js

import litcss from "rollup-plugin-lit-css";
import styles from "rollup-plugin-styles";
import typescript from "@rollup/plugin-typescript";

const distFolder = "dist";

export default [
  {
    input: ["index.ts"],
    output: {
      file: `${distFolder}/index.js`,
      format: "es",
      sourcemap: true,
    },
    plugins: [
      styles({
        mode: "emit",
        minimize: true,
      }),
      litcss({
        include: ["src/*.scss"],
      }),
      typescript(),
    ],
  },
];

index.ts

export { MyComponent } from './src/MyComponent.ts';

src/MyComponent.ts

import { CSSResult, html, LitElement, property } from "lit-element";
import componentStyles from "./MyComponent.scss";

export class MyComponent extends LitElement {
  static get styles(): CSSResult[] {
    console.log(componentStyles, typeof componentStyles);
    return [componentStyles];
  }

  @property({ type: String }) title = "Hey there";

  @property({ type: Number }) counter = 5;

  __increment() {
    this.counter += 1;
  }

  render() {
    return html`
      <h2>${this.title} Nr. ${this.counter}!</h2>
      <button @click=${this.__increment}>increment</button>
    `;
  }
}

src/MyComponent.scss

.big-boi {
    background-color: blue;
    color: red;
}

Workaround

You can workaround this by omitting litcss() and leveraging the css and unsafeCSS imports from lit-element.

static get styles(): CSSResult[] {
	return [
		css`
			${unsafeCSS(styles)}
		`
	];
}

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.