A function that loads a JS file and transforms, bundles and compresses its content.
npm install rosid-handler-js
const handler = require('rosid-handler-js')
handler('main.js').then((data) => {})
handler('main.js', { optimize: true }).then((data) => {})
Add the following object to your rosidfile.json
, rosidfile.js
or routes array. rosid-handler-js
will transform, bundles and compresses all matching JS files in your source folder.
{
"name" : "JS",
"path" : "[^_]*.js",
"handler" : "rosid-handler-js"
}
// main.js
export default () => 'Hello World'
// main.js (output)
"use strict"
Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=function(){return"Hello World"}
filePath
{String}
Absolute path to file.opts
{?Object}
Options.optimize
{?Boolean}
- Optimize output. Defaults tofalse
.env
{?Object}
- Environment variables for loose-envify. Defaults to an object withNODE_ENV
set toproduction
whenoptimize
is enabled.browserify
{?Object}
- Browserify options. Defaults to an object withdebug
enabled.babel
{?Object}
- Babel options. Defaults to an object with the presets env and react.
{Promise<String|Buffer>}
The transformed file content.