UNPKG

5.97 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- **Platform Documentation** - [harp.io/docs](https://harp.io/docs)
37- **Source Code** - [github.com/sintaxi/harp](https://github.com/sintaxi/harp)
38
39Authored and maintained by [@sintaxi](http://twitter.com/sintaxi).
40
41---
42
43### Installation
44
45 sudo npm install -g harp
46
47### Quick Start
48
49Start Harp server by pointing oit
50
51 mkdir ./public
52 harp ./public
53
54Your Harp application is now running at [http://localhost:9000](http://localhost:9000)
55You can now fill your project with ejs, jade, md, sass, scss files to be processed autmatically.
56
57Compile your project...
58
59 harp ./public ./build
60
61Yor dist folder is now ready to be published at a static host such as [Surge.sh](https://surge.sh)
62
63---
64
65## Documentation
66
67Harp can be used as a library or as a command line utility.
68
69### CLI Usage
70
71```
72
73 Harp 〜 Static Web Server v0.40.0
74
75 USAGE
76 harp <source> serves project locally
77 harp <source> <build> compiles for static host
78
79 OPTIONS
80 -p, --port 9000 server port to listen on
81 -h, --host 0.0.0.0 server host to answer to
82 -h, --help server/compile keep whitespace
83 -v, --version server/compile keep whitespace
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.