# last-step

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

Latest version **2.0.2** (published 2018-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install last-step
pnpm add last-step
yarn add last-step
bun add last-step
```

Provides the command `last-step`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2018-02-18 |
| First published | 2017-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6 |
| Dependencies | 21 |
| Unpacked size | 315.8 KB |
| Known vulnerabilities | 0 (+4 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Quan Gan |
| Maintainers | a9udn9u |
| Keywords | minify, last step, production ready, minify js, minify javascript, minify css, minify html, asset pipeline, asset bundler |

## Links

- npm: https://www.npmjs.com/package/last-step
- Repository: https://github.com/a9udn9u/last-step
- Homepage: https://github.com/a9udn9u/last-step#readme
- Issues: https://github.com/a9udn9u/last-step/issues
- npm.io page: https://npm.io/package/last-step

## Dependencies (21)

- [klaw](https://npm.io/package/klaw.md) ^2.1.1
- [less](https://npm.io/package/less.md) ^2.7.3
- [rollup](https://npm.io/package/rollup.md) ^0.54.1
- [chokidar](https://npm.io/package/chokidar.md) ^2.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^5.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [clean-css](https://npm.io/package/clean-css.md) ^4.1.9
- [node-sass](https://npm.io/package/node-sass.md) ^4.7.2
- [uglify-js](https://npm.io/package/uglify-js.md) ^3.3.10
- [babel-core](https://npm.io/package/babel-core.md) ^6.26.0
- [html-minifier](https://npm.io/package/html-minifier.md) ^3.5.8
- [babel-preset-env](https://npm.io/package/babel-preset-env.md) ^1.6.1
- [rollup-plugin-json](https://npm.io/package/rollup-plugin-json.md) ^2.3.0
- [rollup-plugin-babel](https://npm.io/package/rollup-plugin-babel.md) ^3.0.3
- [rollup-plugin-replace](https://npm.io/package/rollup-plugin-replace.md) ^2.0.0
- [less-plugin-npm-import](https://npm.io/package/less-plugin-npm-import.md) ^2.1.0
- [rollup-plugin-commonjs](https://npm.io/package/rollup-plugin-commonjs.md) ^8.2.6
- [rollup-plugin-node-globals](https://npm.io/package/rollup-plugin-node-globals.md) ^1.1.0
- [rollup-plugin-node-resolve](https://npm.io/package/rollup-plugin-node-resolve.md) ^3.0.2
- [rollup-plugin-node-builtins](https://npm.io/package/rollup-plugin-node-builtins.md) ^2.1.2
- [babel-plugin-external-helpers](https://npm.io/package/babel-plugin-external-helpers.md) ^6.22.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2018-02-18
- 2.0.1 — 2018-02-18
- 2.0.0 — 2018-02-15
- 0.1.2 — 2017-06-29
- 0.1.1 — 2017-03-31
- 0.1.0 — 2017-03-31
- 0.0.6 — 2017-03-28
- 0.0.5 — 2017-03-28
- 0.0.4 — 2017-03-28
- 0.0.3 — 2017-03-28
- 0.0.2 — 2017-03-27
- 0.0.1 — 2017-03-27

## 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:

* [HTMLMinifier](https://github.com/kangax/html-minifier) for HTML minification.
* [rollup.js](https://rollupjs.org/) for JavaScript combination.
* [Babel](https://babeljs.io/) for JavaScript transpiling.
* [UglifyJS2](https://github.com/mishoo/UglifyJS2) JavaScript minification.
* [Less](https://github.com/less/less.js) for LESS file processing.
* [SASS](https://github.com/sass/node-sass) for SASS file processing.
* [Clean CSS](https://github.com/jakubpawlowicz/clean-css) for CSS inline import and minification.

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

```bash
npm i -D last-step
```
or
```bash
yarn add -D last-step
```

## Usage

### Configure via .last-step.js

```javascript
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](src/processors)

### 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:

```javascript
{
    // 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](src/defaults.ts) is the default configuration.

RollupProcessor by default enabled the following plugins:

* [rollup-plugin-replace](https://github.com/rollup/rollup-plugin-replace)
* [rollup-plugin-node-globals](https://github.com/calvinmetcalf/rollup-plugin-node-globals)
* [rollup-plugin-node-builtins](https://github.com/nolanlawson/rollup-pulgin-node-builtins)
* [rollup-plugin-json](https://github.com/rollup/rollup-plugin-json)
* [rollup-plugin-node-resolve](https://github.com/rollup/rollup-plugin-node-resolve)
* [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel)
* [rollup-plugin-commonjs](https://github.com/rollup/rollup-plugin-commonjs)

They can be disabled by setting `plugins.[name]` to `false` in RollupJSProcessor options, see [here](src/processors/rollupjs.ts#L15-L23).

BabelProcessor uses [babel-preset-env](https://github.com/babel/babel-preset-env) by default.

## License

MIT

---
_Source: https://npm.io/package/last-step · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
