pull-minify-js

0.8.0 • Public • Published

pull-minify-js

Minify JavaScript files or buffers inside a pull-stream

Minifies streamed JavaScript files using uglify-js

const pull = require('pull-stream')
const { read, write } = require('pull-files')
const minify = require('pull-minify-js')
 
pull(
  read([ 'index.js', 'test.js' ], { cwd: __dirname }),
  minify({
    mangle: true,
    toplevel: true
  }),
  write(__dirname + '/out', err => {
    // done
  })
)

Use minify.buffer if you are streaming JavaScript buffers instead

pull(
  readFile(__dirname + '/foo.js'),
  minify.buffer({ mangle: true, toplevel: true }),
  writeFile(__dirname + '/out.js')
)

Install

npm install --save pull-minify-js
yarn add pull-minify-js

Usage

minify(options?)

A stream that maps each JavaScript file to the minified version. See uglify-js's options further configuration.

pull(
  read([ 'index.js', 'lib/**/*.js' ], { cwd: __dirname }),
  bundle('app.js', [ 'es2040' ]),
  uglify({ ...options }),
  write(__dirname + '/out', err => {
    // ...
  })
)

You can make it map all files regardless of extensions, by passing strict: false

minify({ strict: false, ... })

minify.buffer(options?)

The base implementation that compiles buffer to buffer, instead of file to file. Options are the same

pull(
  readFile(__dirname + '/foo.js'),
  minify.buffer({ ...options }),
  writeFile(__dirname + '/foo.min.js')
)

Maintained by Jamen Marz (See on Twitter and GitHub for questions & updates)

Install

npm i pull-minify-js

DownloadsWeekly Downloads

2

Version

0.8.0

License

none

Last publish

Collaborators

  • npm