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 browser and node applications and includes appropriate watch and reload workflows for each. It is designed with rapid application development in mind and requires little to no configuration to use. Hammer can scale from single application projects to multi library mono repositories via its command line paired with its built in task runner.
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.
This project is offered as is to anyone who may find it of use.
License MIT
Serve
Use the serve command to start a development server that reloads on 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 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 tasks, 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 builds in parallel. 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()Cli
Hammer provides the following command line 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 The es build targets.
--platform platform The target plaform.
--dist directory The target directory.
--port port The port to listen on.
--minify Minifies the output.
--sourcemap Generate sourcemaps.