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

tension

v0.0.6

Published

Universal application toolchain

Downloads

3

Readme

tension

Universal application toolchain

Motivation

Universal Javascript allows execution of a same code both on the client and the server. This approach saves development time dedicated to write application code capable of being rendered on client and server side.

On other hand, a lot of time is wasted to set up scripts/codes dedicated to manage the development process: call them the toolchain. Once done, it's difficult to adjust project structure without breaking the toolchain. It's even harder to maintain the same toolchain trough several projects.

The main purpose of tension is to provide a super interface on top of webpack2 to handle recurrent base configurations in universal applications.

Architecture

The architecture is originally based on the great react-universally's toolchain which offer a single run process to manage multiple bundle's hot development.

tension is a generic version of that toolchain with the minimum configurations for any web or node bundles. We tried to make its fingerprint as small as possible.

It work with a metafile - named tension.js by default - present in project root (beside the package.json). That metafile defines how webpack should create bundles from the source code.

A metafile must return a plain object where each key is a bundle declaration. Each bundle must specify at least the target type, the source path with the entry point and the output path (and the public path for the web target). Check the Metafile section to learn more about its structure.

A meta is intended to be read by the tension CLI. The CLI offer two main commands: one to start a hot development environment and another to make a build for production environment.

Installation

npm install tension --save-dev

Getting started

Requirements

  • node@^6.6.0
  • npm@^3.10.0
mkdir myapp
cd myapp
npm init
npm install tension --save-dev

Client bundle

We will start to discover how tension work by creating a client bundle. We will write its code into ./src/client and call its entry point index.js.

// mkdir -p ./src/client
// nano ./src/client/index.js

var MSG = 'Hello, world'
var main = () => document.getElementById('app').innerHTML = MSG

main()

Now we will create the tension.js metafile at our project root level and declare our client bundle.

// nano ./tension.js

module.exports = {
  client: {
    // our bundle target
    target: 'web',
    // our bundle source path
    srcPath: './src/client',
    // our client entry point (relative to the source path)
    entryIndex: 'index.js',
    // our public path used to serve our bundle
    publicPath: '/client/',
    // our bundle build path
    outputPath: './build/client'
  }
}

Okay let's launch a dev server to test our client bundle. We use the command dev provided by the tension CLI. The command dev takes the key which identify bundle metadata in the tension.js.

./node_modules/.bin/tension dev client

INFO metafile found: /home/steven/code/myapp/tension.js
INFO client Building bundle...
INFO client Build finished successfully
INFO client Hash: 0e6248de46f0cca1cd4d
...
INFO client ✓ Dev server is running at http://localhost:7331/client/
INFO ✓ Dev mode started

We can access to our client bundle at http://localhost:7331/client/index.js.

Well. It's better if we can test it in a web page. Let's do it. We use the staticPath which its content will be served as static files by the dev server.

mkdir ./public
echo '<html>
  <body>
    <div id="app"></div>
    <script src="/client/index.js"></script>
  </body>
</html>' > ./public/index.html
# add staticPath in tension.js
nano ./tension.js
// client: {
//   ...
//   outputPath: './build/client',
//   staticPath: './public'
// }
# launch the dev server
./node_modules/.bin/tension dev client

Open your browser to check if our fantastic script works: http://localhost:7331/client/. We can see "Hello, world".

Now we will test the hot reloading feature. Open our client entry point (./src/client/index.js) and add the following lines:

if (module.hot) {
  module.hot.accept(main)
}

Let's refresh the page under the browser. Now re-open our client entry point and change the var MSG value. Save the modification: that change is hot reloaded in the browser!

Under the hood, the dev server is provided by the great webpack-dev-server. In the metafile, the property devServer, under a web bundle, will be passed to the dev server API. So you can configure the dev server options as has describe in its documentation.

So if we want to use port 1337 for our dev server and disable hot reloading:

// nano ./tension.js

module.exports = {
  client: {
    target: 'web',
    // ...
    devServer: {
      port: 1337,
      hot: false
    }
  }
}

### Server bundle

TODO

CLI

TODO

  tension - Universal application toolchain

  Usage
    tension <command> [options] [flags]

  Commands
    analyze        Analyze build
    build          Build application
    clean          Clean build
    dev            Starts application in dev mode
    start          Starts application

  Options
    -e, --env      Environment name (defaults to "development")
    -m, --meta     Metafile path
    -r, --root,    Root path (defaults to the curent working directory)

  Flags
    --no-colors    Disable colored output
    -d, --debug    Enable debug output
    -v, --verbose  Enable verbose output

  Specials
    -h, --help     Show usage information (this message)
    -V, --version  Show current version (0.0.1)

Metafile

TODO

License

MIT