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

grunt-lemon

v0.1.1

Published

A plugin that inlines file imports.

Downloads

1

Readme

grunt-lemon (discontinued)

Build status npm version Dependencies

Deprecated in favor of grunt-inline-import.

This grunt plugin inlines file imports in individual files permanently. It's best suited for the prepublish phase. Restoring the affected files after publishing your module requires you to create a backup of said files. Take a look at the usage example for details.

If you are using rollup and rollup-plugin-string to inline text file imports during the bundling process, you'll be faced with a problem when you decide to publish your module as a library. In order to make full use of rollup's tree-shaking capabilities, you can't just publish your final bundle. It's important to expose your source files directly, but these files still use custom file imports and will cause errors for the end users of your library!

When life gives you lemons, squeeze the lemons and make lemonade.

In contrast to rollup-plugin-string which focuses on inlining text files, grunt-lemon allows you to inline files of various types.

Getting Started

This plugin requires Grunt >= 0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-lemon --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks("grunt-lemon");

Usage

The inlining process is destructive. Affected files will be changed permanently. Create a backup first!

Define which imports should be considered by defining the options.extensions and specify a source path src to the files that you wish to inline.

// src/my/text.txt
hello world
// src/index.js
import myModule from "my-module";
import text from "./my/text.txt";
// Gruntfile.js
lemon: {
  options: {
    extensions: {
      ".txt": "utf8"
    }
  },
  taskA: {
    src: "src/index.js"
  },
  ...
}
// src/index.js (inlined)
import myModule from "my-module";
const text = "hello world";

Glob

You may use glob patterns to inline a bunch of files at once.

lemon: {
  options: {
    extensions: {
      ".html": "utf8",
      ".css": "utf8"
    }
  },
  task: {
    src: "src/**/tpl.js"
  }
}

Options

  • Only those imports whose file extensions explicitly match one of the specified extensions will be considered. Each extension defines its own encoding.
  • If you don't want to use the const statement, simply set useVar to true.
  • You can set the encoding of the source files that will be parsed. Use one of the possible encoding values specified in node's Buffer class. The default encoding is utf8.
  • You may also provide glob options for the underlying glob mechanism.
lemon: {
  options: {
    // Global options.
    extensions: {
      ".html": "utf8",
      ".png": "base64"
    },
    encoding: "utf8",
    useVar: true,
    glob: { ... },
  },
  squeeze: {
    options: {
      // Local options.
      extensions: {
        ".glsl": "utf8"
      }
    },
    src: "src/index.js"
  }
}

Creating a Backup

In order to create a backup of specific files, you'll need tools for copying and deleting files. The following example uses the basic grunt plugins grunt-contrib-copy and grunt-contrib-clean.

// Gruntfile.js (copy setup)
copy: {
  backup: {
    expand: true,
    cwd: "src",
    src: "**/tpl.js",  // Copy all tpl files from src into a 
    dest: "backup",    // backup folder while maintaining directory structures.
    filter: "isFile"
  },
  restore: {
    expand: true,
    cwd: "backup",
    src: "**",         // Copy all backup files back into the 
    dest: "src",       // src folder, overwriting existing files.
    filter: "isFile"
  }
}
// Gruntfile.js (clean setup)
clean: {
  backup: ["backup"]  // Remove the backup files.
}
// Gruntfile.js (tasks)
grunt.registerTask("backup", ["restore", "copy:backup"]);
grunt.registerTask("restore", ["copy:restore", "clean:backup"]);
grunt.registerTask("prepublish", ["backup", "lemon"]);
grunt.registerTask("postpublish", ["restore"]);

Contributing

Maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

License

Zlib