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

component-build

v1.2.2

Published

main logic for component's build command

Downloads

7,723

Readme

Component Build

This is a separate repo for the primary logic behind the component-build command. Feel free to fork this or use it as a baseline to create your own builder. This is a thin wrapper around component-builder2.

Some features included by default:

  • Scripts

    • ES6 Module support
    • Syntax error checking
    • JSON files and JSON syntax error checking
    • Templates as strings
    • Autorequires the bundle by default
    • Optional UMD wrap
    • Resolves the entry point of the bundle automatically
  • Styles

    • Automatic CSS autoprefixing
    • Rewrite CSS URLs/ against an arbitrary prefix
  • Files

    • Choose to copy or symlink files

API

var build = Build(tree, options)

var resolve = require('component-resolver');
var Build = require('component-build');

var write = fs.writeFileSync;

var options = {
  development: true,
  install: true,
}

resolve(process.cwd(), options, function (err, tree) {
  if (err) throw err;

  var build = Build(tree, options);

  build.scripts(function (err, string) {
    if (err) throw err;
    if (!string) return;
    write('build.js', string);
  })

  build.styles(function (err, string) {
    if (err) throw err;
    if (!string) return;
    write('build.css', string);
  })

  build.files(function (err) {
    if (err) throw err;
  })
})

options are passed to all builders and plugins. Options other than those supported by component-resolver and component-builder2 are:

  • prefix <''> - for rewriting URLs in CSS
  • browsers <''> - autoprefixer browser support
  • umd - wrap the build in a UMD build with name umd
  • autorequire - automatically require the entry point of the build

build.set(key, value)

Set or change an option after initialization.

build.set('development', false);

build.scripts(callback)

Builds the JS. Returns function (err, js) {} where js is the build string. If nothing was built, js === ''.

build.styles(callback)

Builds the CSS. Returns function (err, css) {} where css is the build string. If nothing was built, css === ''.

build.files(callback)

Builds the files. Returns function (err) {}.

build.scriptPlugins(build, options)

Optionally override the default plugins used for .js builds. build is a builder instance, and options are the options passed to Build. You may overwrite this entirely if you'd like:

var build = Build(tree, options);
build.scriptPlugins = function (build, options) {
  build
  .use('scripts',
    es6modules(options),
    plugins.js(options))
  .use('json',
    plugins.json(options))
  .use('templates',
    plugins.string(options));
};
build.scripts(function (err, js) {

});

You may also append or prepend plugins like so:

var defaults = build.scriptPlugins;
build.scriptPlugins = function (build, options) {
  build.use('templates', jade(options));
  defaults(build, options);
  build.use('jade', jade(options));
}

returning anything is NOT necessary. Do NOT call .end().

This method is available on both the constructor and the prototype:

var Build = require('component-build');
Build.scriptPlugins === Build.prototype.scriptPlugins;

build.stylePlugins(build, options)

Same as build.scriptPlugins(), but with .css.

build.filePlugins(build, options)

Same as build.scriptPlugins(), but with the files.

License

(The MIT License)

Copyright (c) 2014 segmentio <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.