UNPKG

5.96 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.46.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 -s, --silent false supresses logs
82 -h, --help outputs this help message
83 -v, --version outputs version of harp
84
85 ╭───────────────────────────────────────────────────────────────────────────────╮
86 │ │
87 │ PROCESSING DATA │
88 │ .ejs -> .html _data.json - directory data │
89 │ .jade -> .html _data.js - dynamic build data │
90 │ .md -> .html │
91 │ .sass -> .css GENERATION │
92 │ .scss -> .css partial("_path/to/partial", { │
93 │ .cjs -> .js "title": "Hello World" │
94 │ .jsx -> .js }) │
95 │ │
96 ╰───────────────────────────────────────────────────────────────────────────────╯
97
98```
99
100### Lib Usage
101
102You may also use harp as a node library for compiling or running as a server.
103
104Serve up a harp application...
105
106```js
107var harp = require("harp")
108harp.server(projectPath [,args])
109server.listen(port, host)
110```
111
112**Or** compile harp application
113
114```js
115var harp = require("harp")
116harp.compile(projectPath [,outputPath] [, callback])
117```
118
119**Or** use as Connect/ExpressJS middleware
120
121```js
122
123```
124
125```js
126// Express
127var express = require("express");
128var harp = require("harp");
129var app = express();
130
131app.use(express.static(__dirname + "/public"));
132app.use(harp.mount(__dirname + "/public"));
133
134app.listen(port, host)
135```
136
137
138## License
139
140Copyright © 2012–2021 [Chloi Inc](http://chloi.io). All rights reserved.
141
142Permission 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:
143
144The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
145
146THE 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.