UNPKG

1.57 kBMarkdownView Raw
1# rosid-handler-js
2
3[![Travis Build Status](https://travis-ci.org/electerious/rosid-handler-js.svg?branch=master)](https://travis-ci.org/electerious/rosid-handler-js) [![Coverage Status](https://coveralls.io/repos/github/electerious/rosid-handler-js/badge.svg?branch=master)](https://coveralls.io/github/electerious/rosid-handler-js?branch=master) [![Dependencies](https://david-dm.org/electerious/rosid-handler-js.svg)](https://david-dm.org/electerious/rosid-handler-js#info=dependencies)
4
5A function that loads a JS file and transforms, bundles and compresses its content.
6
7## Install
8
9```
10npm install rosid-handler-js
11```
12
13## Usage
14
15### API
16
17```js
18const js = require('rosid-handler-js')
19
20js('/src/main.js').then((data) => {})
21js('/src/main.js', { optimize: true }).then((data) => {})
22```
23
24### Rosid
25
26Add the following object to your `rosidfile.json`, `rosidfile.js` or [routes array](https://github.com/electerious/Rosid#routes). `rosid-handler-js` will transform, bundles and compresses all matching JS files in your source folder.
27
28```json
29{
30 "name" : "JS",
31 "path" : "[^_]*.js",
32 "handler" : "rosid-handler-js"
33}
34```
35
36```js
37// main.js
38export default () => 'Hello World'
39```
40
41```js
42// main.js (output)
43"use strict"
44Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=function(){return"Hello World"}
45```
46
47## Parameters
48
49- `filePath` `{String}` Absolute path to file.
50- `opts` `{?Object}` Options.
51 - `optimize` `{?Boolean}` - Optimize output. Defaults to `false`.
52
53## Returns
54
55- `{Promise}({String|Buffer})` The transformed file content.
\No newline at end of file