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

last-step

v2.0.2

Published

Make your project production ready by combining and minifying HTML/JS/CSS files.

Downloads

40

Readme

Last Step

What is it?

Last Step provides an easy way to combine, transform and minify HTML, JavaScript and CSS/LESS files. It glues other tools together to achieve this goal. Specifically, Last Step depends on the following projects:

Last Step v2 is a complete re-write, it's now easier to configure, has a simple plug-in system and comes with a build server that builds files when they are changed.

Configuration of v1 is not compatible with v2, hopefully it a simple conversion and will be simpler in v2.

Installation

npm i -D last-step

or

yarn add -D last-step

Usage

Configure via .last-step.js

module.exports = {
  // Source directory where source files are located
  sourceDir: 'src',
  // Target directory where processed files should be copy to
  targetDir: 'public',

  rules: [
    {
      // Source files, can be a regex pattern or string. Should be relative path in sourceDir
      sources: [/^.*$/],
      // Processors which will process matched source files.
      processors: [
        // Built-in copy processor, simply copies files
        new CopyProcessor()
      ]
    },
    {
      // This rule prevents certain files from been copied to targetDir
      // No processors means matched files will not be processed
      sources: [/(^|\/)(\.DS_Store|Thumbs\.db|\.git.*|\.cvs|.*~|.*\.swp)$/],
    },
    {
      // This rule processes HTML files
      sources: [/.*\.html?$/i],
      processors: [
        new HTMLMinifierProcessor()
      ]
    },
    {
      // This rule processes CSS files
      sources: [/.*\.css$/i],
      processors: [
        new CleanCSSProcessor()
      ]
    },
    {
      // This rule processes JavaScript files
      sources: [/.*\.(js|es6)$/i],
      // Files are chained through all processors so the output of the previous
      // processor will be the input of the next processor.
      processors: [
        new RollupJSProcessor(),
        new UglifyJSProcessor()
      ]
    }
  ]
}

Sources are matched against each rule in reverse order, so in the above configuration, a.css will match /.*\.css$/i, not the catch all /^.*$/.

There are a few other built-in processors: LESSProcessor and SASSProcessors which process .less and .sass files respectively. There is also an individual BabelProcessor for people want to use babel without rollup.

Default settings for each processor can be found in code: Click here

Build Project

In package.json, add a command:

  ...
  "scripts": {
    "build": "last-step",
    ...
  },
  ...

Then run npm run build.

For the above example configuration, if you have the following package layout:

(root) +-- package.json
       |-- .last-step.js
       |-- src/
       |   +-- script-1.js
       |   |-- script-2.js (imported by script-1.js)
       |   |-- workers/
       |   |   +-- worker-1.js
       |   |-- style-1.css
       |   |-- other-styles.css (imported by style-1.css)
       |   |-- index.html
       |   |-- sub-module/
       |   |   +-- sub-module.html
       |   +-- res.jpg
       +-- public/
           +-- (empty)

After build, you will have:

(root) +-- (contents unchanged)
       +-- public/
           +-- script-1.js (contents of both script-1.js and script-2.js)
           |-- workers/
           |   +-- worker-1.js (contents of worker-1.js and all its imports)
           |-- style-1.css (contents of both style-1.css and other-styles.css)
           |-- index.html
           |-- sub-module/
           |   +-- sub-module.html
           +-- res.jpg

npm run build -w will start a build server, it will watch for file changes in the configured sourceDir, when updates are detected, it will automatically do re-build of the changed files. It also handles file dependencies so your targetDir should be always up-to-date.

Command Line Arguments

-c [file] Override the default .last-step.js configuration file location.

-w Start the build server.

Plug-ins

Plug-ins are called Processor, all file processing functionalities are implemented as processors, including built-in processors. The processor interface is very simple:

{
    // Both input and output are strings of file paths.
    // Input is the file which needs to be processed.
    // Output is the file where processed contents should be written to.
    process(input, output) {
        // Process input, write results to output
        return {
            // If input file imported any dependencies, imported files should be returned.
            imports: <Set<string>>
        };
    }
}

That's it, for most built-in processors, all they do is read the file content, process it with an external tool (i.e., Babel), then write the results to file.

Default Behaviors

This is the default configuration.

RollupProcessor by default enabled the following plugins:

They can be disabled by setting plugins.[name] to false in RollupJSProcessor options, see here.

BabelProcessor uses babel-preset-env by default.

License

MIT