JSCompiler

JSCompiler

new JSCompiler(optionsopt)

Source:

A JavaScript compiler

Example
import {JSCompiler} from 'webcompiler';
// or - import {JSCompiler} from 'webcompiler/lib/JSCompiler';
// or - var JSCompiler = require('webcompiler').JSCompiler;
// or - var JSCompiler = require('webcompiler/lib/JSCompiler').JSCompiler;
import {join} from 'path';

const srcDir = join(__dirname, 'src'),
  libDir = join(__dirname, 'lib');

const compiler = new JSCompiler();

// compile for the browser
compiler.fe(join(srcDir, 'script.js'), join(libDir, 'script.js'));

// compile for Node.js
compiler.be(join(srcDir, 'script.js'), join(libDir, 'script.js'));

// compile entire directories for Node.js (non-JavaScript files are simply copied over)
compiler.be(srcDir, libDir);
Parameters:
Name Type Attributes Default Description
options JSCompilerConfig <optional>
{}

configuration object

Extends

Methods

be(inPath, outPath, callbackopt) → {void}

Source:

Compiles a JavaScript file or a directory for the back end. Non-JavaScript files are simply copied over.

If inPath is a directory, outPath has to be also.

Parameters:
Name Type Attributes Default Description
inPath string

the input file/directory path

outPath string

the output file/directory path

callback function <optional>
function () {}

a callback function

Returns:
Type
void

fe(inPath, outPath, callbackopt)

Source:

Compiles, bundles (in production mode also minifies and g-zips) a JavaScript file for the front end.

Parameters:
Name Type Attributes Default Description
inPath string

the input file path

outPath string

the output file path

callback function <optional>
function () {}

a callback function

(protected) save(inPath, outPath, data, callback)

Source:
Inherited From:

G-zips the program if necessary and writes the results to disk.

Skips the final write if the contents of the file have not changed since the previous write. Which adds a little overhead at compile time, but at the same time does not alter the last modified timestamp of the file unnecessarily.

Good news for someone who is using that timestamp for public cache invalidation.

Parameters:
Name Type Description
inPath string

the input path

outPath string

the output path

data ProgramData

processed application code with source maps

callback function

a callback function