Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@silexlabs/eleventy-plugin-concat

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@silexlabs/eleventy-plugin-concat

Eleventy plugin to bundle your scripts and styles

  • 1.0.11
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
323
increased by27.17%
Maintainers
2
Weekly downloads
 
Created
Source

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

  • The plugin on npm (@silexlabs/eleventy-plugin-concat)
  • Github repo

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:

  • Transform all generated pages after the build
  • Concat inline scripts
  • Concat loaded scripts from base url and get their content from file system
  • Concat loaded third-party scripts and fetch their content
  • Concat inline styles
  • Concat loaded stylesheets from base url and get their content from file system
  • 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

NameDescriptionDefault
jsUrlFunction 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``
jsPathFunction which takes the current page and returns the path of the generated script relative the output dirpage => \js/${ basename(page.outputPath, '.html') }-concat.js``
jsSelectorSelector used to find the scripts to be concatenated in the HTML page'head script[data-concat]'
jsAttributesAttributes you want the plugin to add to the JS tag in your HTML, e.g. async''
cssUrlFunction which takes the current page 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``
cssPathFunction which takes the current page and returns the path of the generated stylesheet relative to the output dirpage => \css/${ basename(page.outputPath, '.html') }-concat.css``
cssSelectorSelector used to find the styles to be concatenated in the HTML page'head link[data-concat], head style[data-concat]'
cssAttributesAttributes you want the plugin to add to the CSS tag in your HTML, e.g. data-custom="abcd"''
baseUrlThe URL where your site will be available, e.g. https://www.silex.me => https://www.silex.me/js/test.js will be read from file system in ./js'http://localhost:8080'

Keywords

FAQs

Package last updated on 02 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc