npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-fuse

v0.0.1

Published

Merge separate HTML, CSS, and JavaScript files for a web component into a single web component file.

Downloads

6

Readme

gulp-fuse

Merge separate HTML, CSS, and JavaScript files for a web component into a single web component file.

It's looking like browser's will not be supporting HTML imports, so the alternative it to bundle all of your HTML, CSS, and JavaScript into a single JavaScript file and then to load that JavaScript file using the traditional script tag.

If you would rather not write HTML and CSS within JavaScript files, this module could be for you.

How it Works

  1. Put a script.js file, a style.css file, and a template.html file in the same directory.

  2. And you run this gulp task:

    const gulp = require('gulp');
    const fuse = require('gulp-fuse');
    
    gulp.task('fuse', function() {
        return gulp.src('./components/**/*')
            .pipe(fuse())
            .pipe(gulp.dest('./components'));
    });
  3. A new JavaScript file (with the same name as it's containing directory) will be produced with the HTML, CSS, and JavaScript merged.

Note: If you prefer you can still put your css within your template.html file.

Example

There is a working example within the components directory. Note the following:

  1. Each component has it's own folder.
  2. Each component's folder contains a template.html file and optionally a script.js and/or style.css file.
  3. Each component's folder will have a fused file with the same name as the folder my-component.js after fusing occurs.

script.js

(function (template) {
    'use strict';

    class MyComponent extends HTMLElement {

        constructor() {
            super();
            let shadowRoot = this.attachShadow({mode: 'open'});
            shadowRoot.innerHTML = template;
        }

    }

    window.customElements.define('my-component', MyComponent);

})(/* FUSE */);

style.css

div {
    font-weight: bold;
}

template.html

<template>
  <style>/* FUSE */</style>

  <div>My Custom Web Component</div>
</template>

Options

  • fuseScript - The string or regular expression to match in the script file to indicate where to merge in the template file content. Defaults to /* FUSE */.

  • fuseTemplate - The string or regular expression to match in the template file to indicate where to merge in the css file content. Defaults to /* FUSE */.

  • out - A string or a function that defines the name of the fused file that will be created. If a function is provided then the function will receive the current directory path and the function should return a string that represents the fused file's output name. Defaults to the name of its parent directory.

  • script - The name of the file within a directory that will contain the unfused JavaScript. Defaults to script.js.

  • style - The name of the file within a directory that will contain the unfused CSS. Defaults to style.css.

  • template - The name of the file within a directory that will contain the unfused HTML. Defaults to template.html.

Example

const path = require('path');
const gulp = require('gulp');
    const fuse = require('gulp-fuse');

    gulp.task('fuse', function() {
        return gulp.src('./components/**/*')
            .pipe(fuse({
                fuseScript: '/* FUSE */',
                fuseTemplate: '/* FUSE */',
                out: function(dirpath) {
                    return path.basename(dirpath);
                },
                script: 'script.js',
                style: 'style.css',
                template: 'template.html'
            }))
            .pipe(gulp.dest('./components'));
    });