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

@terse/webpack

v1.0.7

Published

Webpack simplified in a fluent API with presets & an escape hatch so you're not locked in.

Downloads

25

Readme

@terse/webpack

Join the chat at https://gitter.im/ericclemmons/terse-webpack

travis build version downloads MIT License

Webpack simplified in a fluent API with presets & an escape hatch so you're not locked in.


Why?

  • Webpack is powerful, but extremely complicated for newcomers to use.
  • Merging configuration objects is exceedingly difficult and error-prone.
  • Using Webpack on both the server & client is necessary once you leverage Webpack's APIs (e.g. require.context, require.ensure).
  • There are tons of configuration pitfalls that can negatively impact your build that you shouldn't have to know about.
  • It's a full-time job keeping up-to-date with the latest build optimizations.
  • Most React boilerplates have similar configuration, but no abstraction for composition.

Why Not?

  • You're comfortable with Webpack configuration.
  • You consider abstraction bad (e.g. "magic" or "indirection").
  • You have to get access to the "bare-metal" APIs.
  • TODO - Check Twitter for more cynical responses.

How?

This project attempts to solve these problems via:

  • Built on Webpack2, with the latest advancements.
  • Simple, fluent API that takes the guess-work out.
  • Escape hatch to copy/paste the generated, raw config.
  • Optional .presets for getting started quickly.
  • Functional reducers that you can override to customize the output.
  • Each action creates a new config, so you can easily compose them.

Upcoming features:

  • .presets:
    • .autoinstall() - Install missing dependencies.
    • .conventions() - Default input & output sources.
    • .hot() - Simplify HMR.
    • .offline() - Add offline support to your app.
    • .react() - Quickly get started with React.
  • terse-webpack CLI - Start coding without any initialization.
  • GUI - Get started on a new project with a few clicks.

Example

// webpack.config.js
module.exports = require("@terse/webpack").api()
  .entry("./src/client.js")
  .loader("babel", ".js", {
    exclude: /node_modules/,
    query: { cacheDirectory: true },
  })
  .modules("./lib")
  .output("build/client")
  .target("web")
  .when("development", function(api) {
    return api
      .entry({
        client: [
          "webpack-hot-middleware/client?reload=true&timeout=2000",
          "./src/client.js",
        ],
      })
      .plugin("npm-install-webpack-plugin")
      .plugin("webpack.HotModuleReplacementPlugin")
      .plugin("webpack.NoErrorsPlugin")
      .sourcemap("source-map")
    ;
  })
  .getConfig()
;
  1. Generates client.js in the build directory from ./src/client.js.
  2. Parses .js files (excluding node_modules) with Babel.
  3. Searches node_modules and ./lib for non-relative files.
  4. Outputs assets to ./build/client.
  5. Target platform is web (vs. node).
  6. When NODE_ENV is development: a. Override client.js to support HMR. b. Add npm-install-webpack-plugin to auto-install missing dependencies. c. Add HMR support. d. Enable source-map-style source maps (e.g. .map files).

Dependencies

I recommend using this against the latest Node + NPM v3.

Installation

npm install @terse/webpack

Usage

View the example.

Replace the contents of webpack.config.js (and others) with:

module.exports = require("@terse/webpack").api()
  ...
  .getConfig()
;

It's crucial to call .getConfig() to return the Webpack configuration.

With the upcoming .presets, it'll be as simple as:

module.exports = require("@terse.webpack").api()
  .presets("autoinstall", "hot", "react", "offline")
  .target("web")
  .getConfig()
;

API

  • .api([customFeatures[, customReducers]])

    Begins fluent interface, optionally accepted an array of custom features and custom reducers.

  • .alias(name[, pathOrName])

    Maps a package name (e.g. react) to another library (e.g. react-lite) or to a path (e.g. ./node_modules/react).

  • .context(path)

    Config files are relative to this folder. (Default: process.cwd())

  • .env(environment)

    Overrides NODE_ENV (defaults to development) the build is for.

  • .externals(...[Function, RegExp, String])

    Prevents Webpack from bundling matching resources.

  • .loader(name[, extensions = ".js"[, options]])

    Add a loader for the given extension(s) with the given settings.

  • .modules(path)

    Lookup non-relative (e.g. my-cool-lib) modules in this folder as well as node_modules.

  • .node(options)

    Override built-in Node constants & libs (e.g. __dirname, __filename)

  • .output(pathOrOptions)

    Set the output path, or specify the entire Webpack output configuration.

  • .plugin(name, ...args)

    Installed automatically with the given arguments.

  • .preLoader(name[, extensions = ".js"[, options]])

    Just like .loader, but is ran before all other loaders.

  • .sourcemap(type)

    Add a source map to the build.

  • .target(runtime)

    Either node or web.

  • .getConfig()

    Returns the Webpack configuration

    • .toString()

      Returns the Webpack configuration as a string.

  • .getState()

    Returns the normalized configuration (prior to reducing).

    • .toString()

      Returns a string of the normalized configuraiton.

License

MIT License 2016 © Eric Clemmons