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

@silexlabs/eleventy-plugin-concat

v1.0.11

Published

Eleventy plugin to bundle your scripts and styles

Downloads

1,224

Readme

eleventy-plugin-concat

Eleventy plugin to bundle your scripts and styles

This plugin is contributed by Internet 2000 web studio, it is used to create green websites with Silex website builder

Links

Overview

  1. Add the plugin to your .eleventy.js config
  2. Add data-concat attribute to <script>, <script src=, <style> and <link rel="stylesheet" href= which are in the page <head>
  3. After the site has been built by eleventy, the plugin will write new script.js and style.css files with the content of all the scripts and styles with data-concat
  4. The plugin will also change you HTML to load the new script and style in place of the old ones

Tip: this plugin works great with eleventy-plugin-helmet which makes it easy to group scripts of templates in HEAD

Features

This is the roadmap and feature list:

  • [x] Transform all generated pages after the build
  • [x] Concat inline scripts
  • [x] Concat loaded scripts from base url and get their content from file system
  • [x] Concat loaded third-party scripts and fetch their content
  • [x] Concat inline styles
  • [x] Concat loaded stylesheets from base url and get their content from file system
  • [x] Concat loaded third-party stylesheets and fetch their content

Example

page.njk (also works with liquid or other template language):

<!doctype html>
<html>
  <head>
    <script src="/site.js" data-concat></script>
    <script src="/page.js" data-concat></script>
    <script data-concat>
        console.log('concat')
    </script>
    <link rel="stylesheet" href="/site.css" data-concat />
    <link rel="stylesheet" href="/page.css" data-concat />
    <style data-concat>
        body { background: blue; }
    </style>
  </head>
</html>

Generated _site/page.html:

<!doctype html>
<html>
  <head>
    <script src="/script.js"></script>
    <link rel="stylesheet" href="/style.css" />
  </head>
</html>

Generated _site/script.js:

// ... content of site.js
// ... content of page.js
console.log('concat')

Generated _site/style.css:

/* ... content of site.css */
/* ... content of page.css */
body { background: blue; }

Usage

  1. Install the plugin using npm:

    npm install @silexlabs/eleventy-plugin-concat
  2. Add the plugin to your .eleventy.js config:

    const pluginConcat = require("@silexlabs/eleventy-plugin-concat")
    
    module.exports = (eleventyConfig) => {
      eleventyConfig.addPlugin(pluginConcat, {
        baseUrl: 'http://localhost:8080',
      })
    }
  3. Use the global data-concat attribute in your templates

Options

The default options are stored in src/defaults.js

| Name | Description | Default | | -- | -- | -- | | jsUrl | Function which takes the current page and returns the URL of the generated script (what you want the plugin to insert in your HTML) | page => \/js/${ basename(page.outputPath, '.html') }-concat.js`| | jsPath | Function which takes [the current page](https://www.11ty.dev/docs/data-eleventy-supplied/#page-variable) and returns the path of the generated script relative the output dir |page => `js/${ basename(page.outputPath, '.html') }-concat.js`| | jsSelector | Selector used to find the scripts to be concatenated in the HTML page | 'head script[data-concat]' | | jsAttributes | Attributes you want the plugin to add to the JS tag in your HTML, e.g.async| '' | | cssUrl | Function which takes [the current page](https://www.11ty.dev/docs/data-eleventy-supplied/#page-variable) and returns the URL of the generated stylesheet (what you want the plugin to insert in your HTML) |page => `/css/${ basename(page.outputPath, '.html') }-concat.css`| | cssPath | Function which takes [the current page](https://www.11ty.dev/docs/data-eleventy-supplied/#page-variable) and returns the path of the generated stylesheet relative to the output dir |page => `css/${ basename(page.outputPath, '.html') }-concat.css`| | cssSelector | Selector used to find the styles to be concatenated in the HTML page | 'head link[data-concat], head style[data-concat]' | | cssAttributes | Attributes you want the plugin to add to the CSS tag in your HTML, e.g.data-custom="abcd"| '' | | baseUrl | The URL where your site will be available, e.g.https://www.silex.me=>https://www.silex.me/js/test.jswill be read from file system in./js` | 'http://localhost:8080' |