UNPKG

5.9 kBMarkdownView Raw
1# Harp
2
3> zero-configuration web server with built in pre-processing
4
5### What is Harp?
6
7Harp is a static web server that also serves Jade, Markdown, EJS, Less, Stylus, Sass, and CoffeeScript **as** HTML, CSS, and JavaScript without any configuration. It supports the beloved layout/partial paradigm and it has flexible metadata and global objects for traversing the file system and injecting custom data into templates. Optionally, Harp can also compile your project down to static assets for hosting behind any valid HTTP server.
8
9### Why?
10
11Pre-compilers are becoming extremely powerful and shipping front-ends as static assets has many upsides. It's simple, it's easy to maintain, it's low risk, easy to scale, and requires low cognitive overhead. I wanted a lightweight web server that was powerful enough for me to abandon web frameworks for dead simple front-end publishing.
12
13### Features
14
15- easy installation, easy to use
16- fast and lightweight
17- robust (clean urls, intelligent path redirects)
18- built in pre-processing
19- first-class layout and partial support
20- built in LRU caching in production mode
21- can export assets to HTML/CSS/JS
22- does not require a build steps or grunt task
23- fun to use
24
25### Supported Pre-Processors
26
27- [EJS](https://ejs.co/)
28- [Jade](http://jade-lang.com/)
29- [Markdown](http://daringfireball.net/projects/markdown/) (Unsanitized)
30- [Sass (SCSS)](http://sass-lang.com/)
31- [Sass](http://sass-lang.com/)
32
33### Resources
34
35- **Server Documentation** - [harpjs.com/docs/](http://harpjs.com/docs/)
36- **Source Code** - [github.com/sintaxi/harp](https://github.com/sintaxi/harp)
37
38Authored and maintained by [@sintaxi](http://twitter.com/sintaxi).
39
40---
41
42### Installation
43
44 sudo npm install -g harp
45
46### Quick Start
47
48Start Harp server by pointing oit
49
50 mkdir ./public
51 harp ./public
52
53Your Harp application is now running at [http://localhost:9000](http://localhost:9000)
54You can now fill your project with ejs, jade, md, sass, scss files to be processed autmatically.
55
56Compile your project...
57
58 harp ./public ./build
59
60Yor dist folder is now ready to be published at a static host such as [Surge.sh](https://surge.sh)
61
62---
63
64## Documentation
65
66Harp can be used as a library or as a command line utility.
67
68### CLI Usage
69
70```
71
72 Harp 〜 Static Web Server v0.40.0
73
74 USAGE
75 harp <source> serves project locally
76 harp <source> <build> compiles for static host
77
78 OPTIONS
79 -p, --port 9000 server port to listen on
80 -h, --host 0.0.0.0 server host to answer to
81 -h, --help server/compile keep whitespace
82 -v, --version server/compile keep whitespace
83
84 ╭───────────────────────────────────────────────────────────────────────────────╮
85 │ │
86 │ PROCESSING DATA │
87 │ .ejs -> .html _data.json - directory data │
88 │ .jade -> .html _data.js - dynamic build data │
89 │ .md -> .html │
90 │ .sass -> .css GENERATION │
91 │ .scss -> .css partial("_path/to/partial", { │
92 │ .cjs -> .js "title": "Hello World" │
93 │ .jsx -> .js }) │
94 │ │
95 ╰───────────────────────────────────────────────────────────────────────────────╯
96
97```
98
99### Lib Usage
100
101You may also use harp as a node library for compiling or running as a server.
102
103Serve up a harp application...
104
105```js
106var harp = require("harp")
107harp.server(projectPath [,args])
108server.listen(port, host)
109```
110
111**Or** compile harp application
112
113```js
114var harp = require("harp")
115harp.compile(projectPath [,outputPath] [, callback])
116```
117
118**Or** use as Connect/ExpressJS middleware
119
120```js
121
122```
123
124```js
125// Express
126var express = require("express");
127var harp = require("harp");
128var app = express();
129
130app.use(express.static(__dirname + "/public"));
131app.use(harp.mount(__dirname + "/public"));
132
133app.listen(port, host)
134```
135
136
137## License
138
139Copyright © 2012–2021 [Chloi Inc](http://chloi.io). All rights reserved.
140
141Permission 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:
142
143The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
144
145THE 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.