Package Exports
- @sinclair/hammer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sinclair/hammer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Install
$ npm install @sinclair/hammer -gUsage
Create an index.html file
<!DOCTYPE html>
<html>
<head>
<link href="index.css" rel="stylesheet" />
<script src="index.tsx"></script>
</head>
<body>
<img src="banner.png" />
</body>
</html>Run Hammer
$ hammer build index.htmlDone
Overview
Hammer is a build tool for browser and node applications. It provides a unified command line interface for developing both browser and node applications and includes appropriate watch and reload workflows for each. Hammer also provides support for linking local library dependencies taken by browser and node applications as well as the ability to create project automation tasks.
Hammer was written to consolidate several disparate tools related to monitoring node processes (nodemon), building from HTML (parcel), mono repository support (lerna, nx) and project automation (gulp, grunt). It takes esbuild as its only dependency and is as much concerned with build performance as it is with dramatically reducing the number of development dependencies required for modern web application development.
License MIT
Serve
Use the serve command to start a development server that reloads on file save.
<!DOCTYPE html>
<html>
<head>
<script src="index.tsx"></script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>$ hammer serve index.htmlRun
Use the run command to start node scripts that reload on file save.
$ hammer run index.ts
$ hammer run "index.ts arg1 arg2" # use quotes to pass argumentsTasks
Hammer provides support for running tasks to automate build workflow. To use, create a hammer.ts file in the current working directory. You can call any exported function from the task command.
export function print(message: string) {
console.log(message)
}$ hammer task print "Hello World"You can use tasks to orchestrate concurrent workflows. The following starts serve and run processes in parallel.
import { shell } from '@sinclair/hammer'
export async function start(dist = 'target') {
await shell([
`hammer serve apps/website/index.html --dist ${dist}/website`,
`hammer run apps/server/index.ts --dist ${dist}/server`
])
}$ hammer task startLibs
Use tsconfig.json path aliasing to link local library packages that are shared between multiple applications. Consider the following directory structure.
/apps
/server
index.ts ───────────┐
/website │
index.html │
index.ts ───────────┤ depends on
/libs │
/shared │
index.ts <──────────┘
tsconfig.jsonTo allow website and server to import shared. Configure tsconfig.json as follows.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@libs/shared": ["libs/shared/index.ts"],
}
}
}The server and website applications can import with the following.
import { X } from '@libs/shared'
const x = new X()Command Line Interface
Hammer provides the following CLI interface.
Commands:
$ hammer build <file or folder> <...options>
$ hammer watch <file or folder> <...options>
$ hammer serve <file or folder> <...options>
$ hammer run <script> <...options>
$ hammer task <task> <...arguments>
$ hammer version
$ hammer help
Options:
--target <...targets> Sets the ES targets.
--platform platform Sets the platform.
--dist path Sets the output directory.
--port port The port to listen on when serving.
--minify Minifies the bundle.
--sourcemap Generate sourcemaps.