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 |
|
5 | A function that loads a JS file and transforms, bundles and compresses its content.
|
6 |
|
7 | ## Install
|
8 |
|
9 | ```
|
10 | npm install rosid-handler-js
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | const js = require('rosid-handler-js')
|
17 |
|
18 | js('/src/main.js', '/src', '/dist', {}).then(({ data, savePath }) => {})
|
19 | ```
|
20 |
|
21 | ## Example
|
22 |
|
23 | Add 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.
|
24 |
|
25 | ```json
|
26 | {
|
27 | "name" : "JS",
|
28 | "path" : "[^_]*.js",
|
29 | "handler" : "rosid-handler-js"
|
30 | }
|
31 | ```
|
32 |
|
33 | ```js
|
34 | // main.js
|
35 | export default () => 'Hello World'
|
36 | ```
|
37 |
|
38 | ```js
|
39 | // main.js (output)
|
40 | "use strict"
|
41 | Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=function(){return"Hello World"}
|
42 | ```
|
43 |
|
44 | ## Parameters
|
45 |
|
46 | - `filePath` `{String}` Absolute path to the requested file.
|
47 | - `srcPath` `{String}` Absolute path to the source folder.
|
48 | - `distPath` `{?String}` Absolute path to the export folder.
|
49 | - `route` `{Object}` The route which matched the request URL.
|
50 |
|
51 | ## Returns
|
52 |
|
53 | - `{Promise}({Object})`
|
54 | - `data` `{String | Buffer}` The transformed file content.
|
55 | - `savePath` `{?String}` Where to save the file when compiling. |
\ | No newline at end of file |