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

tilt-assets

v0.0.2

Published

Asset pipeline request handler

Downloads

125

Readme

tilt-assets Build Status

Tiny asset pipeline

Install

npm i tilt-assets -S

Usage

var pipeline = asset({
  dirs: 'test/assets/'
});

var server = http.createServer((req, res) => {
  console.log('Incoming request', req.url);

  if (/\.css$/.test(req.url)) return pipeline.handle(req, res);
  if (/\.js/.test(req.url)) return pipeline.handle(req, res);

  res.end('foo');
});

server.listen(3000);

Options

  • dirs Glob directory patters (must end with a "/". Default: app/assets/)
  • baseURL Base URL removed from the incoming request URL (Default: '/assets/')

Browserify

Browserify is the default handler for .js files.

You can further configure browserify transforms with a package.json browserify.transform field.

For instance, to configure browserify to compile into ES6, make sure you've installed the babelify transform and babel-preset-es2015.

"browserify": {
  "transform": [
    ["babelify", { "presets": "es2015" }]
  ]
}

Note: Presets and plugins need to be installed as separate modules.

Other browserify options can be configured using browserify field.

For instance, to add a source map to the end of the bundle:

"browserify": {
  "debug": true
}

PostCSS

PostCSS is the default handler for .css files.

You can configure PostCSS plugins with a package.json postcss.use field.

"postcss": {
  "use": ["autoprefixer", "cssnano"]
}

Plugin configuratons can be defined using plugin names as keys.

"postcss": {
  "use": ["autoprefixer", "cssnano"],

  "autoprefixer": {
    "browsers": "> 5%"
  },

  "cssnano": {
    "discardComments": false
  }
}

Note: PostCSS plugins need to be installed as separate modules. For the above example to work, you'd need to install autoprefixer and cssnano.

Additionnaly, other postcss configuration options can be specified using package.json postcss field.

For instance, to add a source map to the end of the file:

"postcss": {
  "map": true
}

API

Asset

new Asset.

var instance = new asset.Asset();
assert.ok(instance.options);
assert.ok(instance instanceof asset.Asset);
assert.equal(instance.dirs, 'app/assets/');

Compiles JS into ES6.

var stream = fs.createWriteStream('test/assets/main.output.js');
this.assets.browserify(path.join(__dirname, 'assets/main.js'), stream, (err) => {
  if (err) return done(err);
});
stream.on('finish', () => {
  fs.readFile(stream.path, 'utf8', (err, js) => {
    if (err) return done(err);
    assert.ok(/classCallCheck/.test(js));
    done();
  });
});

Compiles CSS using postcss / autoprefixer.

var stream = fs.createWriteStream('test/assets/main.output.css');
this.assets.postcss(path.join(__dirname, 'assets/main.css'), stream, (err) => {
  if (err) return done(err);
});
stream.on('finish', () => {
  fs.readFile(stream.path, 'utf8', (err, css) => {
    if (err) return done(err);
    assert.ok(/display: flex/.test(css));
    assert.ok(/display: -ms-flexbox;/.test(css));
    assert.ok(/display: -webkit-box;/.test(css));
    done();
  });
});

HTTP handler

Renders foo.

request(this.server)
  .get('/')
  .expect('foo')
  .end(done);

Renders js.

request(this.server)
  .get('/main.js')
  // Check basic output
  .expect(/return App/)
  // Check ES6 compilation
  .expect(/classCallCheck/)
  .end(done);

Renders css.

request(this.server)
  .get('/main.css')
  // Check basic output
  .expect(/display: flex/)
  // Check autoprefixer output
  .expect(/display: -ms-flexbox/)
  .expect(/display: -webkit-box/)
  .end(done);