Creating web components with lit-element, leveraging rollup, postcss, and the tailwind framework for packaging

I have been attempting to package a functional web component that was developed using the lit-element/lit-html with the tailwind framework utilizing the postcss plugin from the rollup packager.

Upon conducting a rollup, I discovered the compiled js and html files in the dist/ target folder, but unfortunately, the css file generated by postcss was missing. I have tried numerous approaches without achieving success...

dist/index.js 
dist/index.html
dit/webcomponents-loader.js

The code is accessible for testing purposes:

https://gitlab.univ-rouen.fr/sreycoyrehourcq/web-components.git

Here is my postcss.config.js:

module.exports = {
    plugins: [
        require("tailwindcss"),
        require("postcss-import"),
    ]
}

I also attempted running without loading the postcss configuration file.

My rollup.config.js:

import postcss from 'rollup-plugin-postcss'
import postcssImport from 'postcss-import';

import copy from 'rollup-plugin-copy';
import typescript from '@rollup/plugin-typescript';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import path from 'path'

const extensions = ['.js', '.jsx', '.ts', '.tsx', '.mjs'];
const outputDir = './dist/';

export default {
    input: './src/index.ts',
    output: {
        dir: outputDir,
        sourcemap: true,
        format: 'esm',
    },
    plugins: [
        resolve({ extensions }),
        commonjs(),
        typescript(),
        copy({
            targets: [
                { src: './src/index.html', dest: outputDir },
                { src: './node_modules/@webcomponents/webcomponentsjs/bundles/', dest: outputDir },
                {
                    src: './node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js',
                    dest: outputDir
                }
            ]
        }),
        postcss({
            plugins: [
                postcssImport()
            ],
            config: {
                path: "./postcss.config.js",
            },
            extract: path.resolve('dist/main.css'),
            module: false
        })
    ]
}

I experimented with including this block as well:

postcss({
    config: false,
    plugins: [
        tailwind(),
        postcssImport()
    ],
    extract: true,
    module: false
}),

My main.css:

@import "tailwindcss/base";

@import "tailwindcss/components";

@import "tailwindcss/utilities";

Here is my package.json:

    {
  "scripts": {
    "build": "rollup -c rollup.config.js",
    "start:build": "yarn run build && es-dev-server --root-dir dist --app-index index.html --compatibility none --open"
  },
  "devDependencies": {
    "@rollup/plugin-node-resolve": "^8.4.0",
    "@webcomponents/webcomponentsjs": "^2.4.4",
    "rollup-plugin-html": "^0.2.1",
    "rollup-plugin-postcss": "^3.1.3"
  },
  "dependencies": {
    "@rollup/plugin-typescript": "^5.0.2",
    "es-dev-server": "^1.57.1",
    "lit-element": "^2.3.1",
    "postcss-import": "^12.0.1",
    "postcss-nested": "^4.2.3",
    "postcss-preset-env": "^6.7.0",
    "rollup-plugin-commonjs": "^10.1.0",
    "rollup-plugin-copy": "^3.3.0",
    "rollup-plugin-node-resolve": "^5.2.0",
    "tailwindcss": "^1.6.0",
    "typescript": "^3.9.7"
  }
}

Answer №1

Make sure to include main.css in your ./src/index.ts file and then execute the command yarn build.

...
import "./checkable-elements";
import "./hover-target";

// import main.css
import "./main.css";
...

After running the build process, you can find the generated main.css file listed below:

$ tree dist/ -L 1
dist/
├── bundles
├── index.html
├── index.js
├── index.js.map
├── main.css
└── webcomponents-loader.js

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Clicking on the image in Angular does not result in the comments being displayed as expected

I find it incredibly frustrating that the code snippet below is not working as intended. This particular piece of code was directly copied and pasted from an online Angular course I am currently taking. The objective of this code is to display a card view ...

The browser failed to display the SVG image, and the console log indicated that the promise was rejected, with the message "false."

I'm struggling to understand why my SVG isn't showing up on the screen. The console log is displaying "false," which I believe indicates that a promise was rejected Here is the TypeScript file I am working with: export class PieChartComponent im ...

A guide on integrating a vue-concurrency Task Creator with argument support

I've been grappling with my Vue 3 / TypeScript app and the vue-concurrency library. Everything is nearly in place, but configuring a Task Creator to accept arguments has proven to be quite challenging. Following the Task Creators pattern outlined in ...

WebStorm is not auto-completing the Emotion Styled Components

While using @emotion/styled in WebStorm, I have noticed that there is no Intellisense for autocomplete within my style object. However, Typescript does seem to be checking to some extent: const StepTimer = styled.button({ borderRadius: 50, height: &ap ...

Expanding the session object with express-session

Seeking assistance with TypeScript and Express session integration. I've been exploring ways to extend my session object, specifically through merging typings based on the documentation provided: In my types/session.d.ts file, I have the following i ...

Trouble arises when trying to test an Angular service that relies on abstract class dependencies

Currently, I am working on a service that has a dependency on another service, which in turn relies on two abstract classes as dependencies. (ThemeConfigService -> (SettingsService -> SettingsLoader, NavigationLoader)) During testing, the failure oc ...

Navigating through keys within a mapped Type in Typescript

Are there alternative methods for iterating through object keys, transforming values, and ensuring the resulting type maintains the same keys as the input? const env = { KEY_1: "VALUE_1", KEY_2: "ANOTHER_VALUE_2" }; function mapV ...

Produce new lines of code using the vscode.window.activeTextEditor.edit method in Visual Studio Code

Hey everyone, I'm currently working on a vscode extension that can automatically generate template code based on the language you are using when you click a button. However, there seems to be an issue with the formatting of the generated code as it do ...

Is there a way to customize the Color Palette in Material UI using Typescript?

As a newcomer to react and typescript, I am exploring ways to expand the color palette within a global theme. Within my themeContainer.tsx file, import { ThemeOptions } from '@material-ui/core/styles/createMuiTheme'; declare module '@mate ...

Vue encountered a double loading issue when utilizing a library compiled with Webpack

I am facing an issue with my TypeScript library of Vue components that gets compiled into a single JS file using Webpack. The problem arises when the TypeScript project consuming this library also depends on Vue. Upon running the application, I noticed tha ...

Is it possible to dynamically name keys in objects using template literals in Typescript?

Can the scenario below be achieved? type test = <T extends string>(key: T, object: { [`${T}`]: number }) => void ^^^^^^^^ I am aware that we can assign type literal values using that syntax, but af ...

I am looking to append a new value to an array within the state in React

development environment ・ react ・ typescript In this setup, state groups are stored as arrays. If you want to add a group to the array of groups when the onClickGroups function is called, how should you go about implementing it? interface ISearc ...

Oops! The type error is indicating that you tried to pass 'undefined' where a stream was required. Make sure to provide an Observable, Promise, Array, or Iterable when working with Angular Services

I've developed various services to interact with different APIs. The post services seem to be functioning, but an error keeps popping up: ERROR TypeError: You provided 'undefined' where a stream was expected. Options include Observable, ...

Locating items within an array of objects using Angular 6 with TypeScript or JavaScript

I have the following code in my HTML template for my Angular 6 application. <div *ngIf ="conversation.participants[conversation.updatedBy.toLowerCase()].firstName">somedata </div> My goal is to search within the participants array object base ...

Enrolling a new plugin into a software repository

I have 5 unique classes: ConfigManager ForestGenerator TreeCreator NodeModifier CustomPlugin My goal is to create an npm module using TypeScript that incorporates these classes. The main feature I want to implement is within the ConfigManager clas ...

Tips for dragging a column in ngx-datatable to scroll the horizontal scroll bar in Angular 4

Is there a way to make the horizontal scroll bar move when dragging the column header of ngx-datatable in Angular 4? I have a situation where the first column should trigger the movement of the horizontal scroll bar when dragged from left to right. Any s ...

Utilize the npm module directly in your codebase

I am seeking guidance on how to import the source code from vue-form-generator in order to make some modifications. As a newcomer to Node and Javascript, I am feeling quite lost. Can someone assist me with the necessary steps? Since my Vue project utilize ...

Playing around with TypeScript + lambda expressions + lambda tiers (AWS)

Having trouble importing modules for jest tests in a setup involving lambdas, lambda layers, and tests. Here is the file structure: backend/ ├─ jest.config.js ├─ package.json ├─ babel.config.js ├─ layers/ │ ├─ tsconfig.json │ ├ ...

Tips on customizing the selected icon color in Material-UI's BottomNavigationAction styling

I'm facing an issue with Material-UI styled components and could use some assistance. My goal is to create a BottomNavigation bar in React using Material-UI v5 where the selected option's icon displays in red (#f00) while the unselected icons sho ...

Rendering a Nativescript component once the page has been fully loaded

I'm currently working on integrating the WikitudeArchitectView into my TypeScript code. I've successfully registered the element in the main.ts TypeScript file: var architectView = require("nativescript-wikitudearchitectview"); registerElement ...