rosid-handler-js-next

Load, transform, bundle and compress modern JS

Usage no npm install needed!

<script type="module">
  import rosidHandlerJsNext from 'https://cdn.skypack.dev/rosid-handler-js-next';
</script>

README

rosid-handler-js-next

Travis Build Status Coverage Status Dependencies

A function that loads a JS file and transforms, bundles and compresses its content.

Install

npm install rosid-handler-js-next

Usage

API

const handler = require('rosid-handler-js-next')

handler('main.js').then((data) => {})
handler('main.js', { optimize: true }).then((data) => {})

Rosid

Add the following object to your rosidfile.json, rosidfile.js or routes array. rosid-handler-js-next will transform, bundles and compresses all matching JS files in your source folder.

{
  "name"    : "JS",
  "path"    : "[^_]*.js",
  "handler" : "rosid-handler-js-next"
}
// main.js
export default () => 'Hello World'
// main.js (output)
"use strict"
Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=function(){return"Hello World"}

Parameters

  • filePath {String} Absolute path to file.
  • opts {?Object} Options.
    • optimize {?Boolean} - Optimize output. Defaults to false.
    • replace {?Object} - Variables for @rollup/plugin-replace. Defaults to an object with process.env.NODE_ENV set to production when optimize is enabled.
    • babel {?Object} - Variables for @rollup/plugin-babel. Defaults to an object with the presets env and react.
    • nodeGlobals {?Boolean} - Enable to disable rollup-plugin-node-globals. Defaults to false.
    • rollupInput {?Object} - Input variables for rollup.js.
    • rollupOutput {?Object} - Output variables for rollup.js.

Returns

  • {Promise<String|Buffer>} The transformed file content.