Package Exports
- webcompiler
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (webcompiler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
webcompiler
Lint, type-check, compile, package and gzip JavaScript (ES6 + Flow static types + JSX), for the browser as well as NodeJS; lint, compile, auto-prefix, minify and gzip SASS.
Prerequisites
Important! Create a .flowconfig file at the root of your project with the following contents:
[ignore]
.*/invalidPackageJson/*
.*/build/*
.*/node_modules/.*/test/*
.*/node_modules/.*/spec/*
[include]
[libs]
[options]
suppress_comment=.*@noflow.*Installation
npm i webcompiler --saveExposes 3 main classes
DevServer - A lightweight development server that rapidly recompiles the JavaScript and SASS files when they are
edited and updates the page.
interface DevServer {
constructor(script: string, style: string, devDir: string, port: number = 3000, react: boolean = true);
watchSASS(watchDir: string);
watchJS();
run(watchDir: string);
}JS - lints, type-checks, compiles, packages, minifies and gzips JavaScript for the browser and NodeJS
interface JS {
constructor(lintRules: Object = {});
validate(inPath: string, lintPaths: Array<string>, callback: Function);
feDev(inPath: string, outPath: string, callback: Function, ...lintPaths: Array<string>);
feProd(inPath: string, outPath: string, callback: Function, ...lintPaths: Array<string>);
beFile(inPath: string, outPath: string, callback: Function, ...lintPaths: Array<string>);
beDir(inPath: string, outPath: string, callback: Function, ...lintPaths: Array<string>);
}SASS - lints, compiles, packages, adds vendor prefixes, minifies and gzips SASS for the browser
interface SASS {
constructor(excludeLinter: Array<string> = [], importOnceOptions: Object = {}, includePaths: Array<string> = []);
validate(inPath: string, lintPaths: Array<string>, callback: Function);
feDev(inPath: string, outPath: string, callback: Function, ...lintPaths: Array<string>);
feProd(inPath: string, outPath: string, callback: Function, ...lintPaths: Array<string>);
}Arguments
script- a full system path to a JavaScript filestyle- a full system path to a SASS filedevDir- a full system path to a directory in which to put any compiled development resourcesport- a port at which to start the dev serverreact- false to disable the react hot loader pluginwatchDir- the directory in which to watch for the changes in the SASS filesinPath- a full system path to the input file/directoryoutPath- a full system path to the output file/directorycallback- a callback function, executed after the successful compilationlintPaths- paths to files/directories to lint (the input file is included automatically)
Example usage
import {DevServer} from 'webcompiler';
import {join} from 'path';
const rootDir = join(__dirname, '..'),
devDir = join(rootDir, 'development'),
server = new DevServer(join(devDir, 'script.js'), join(devDir, 'app.scss'), devDir);
server.run(rootDir);Important!
The resulting JavaScript and CSS files from feProd are gzip compressed for performance
(see Gzip Components), so make sure to provide a
"Content-Encoding" header to the browser (e.g. res.setHeader('Content-Encoding', 'gzip');).
Additional info
- ESLint, babel-eslint, ESLint-plugin-Babel, ESLint-plugin-React and ESLint-plugin-Lodash are used to lint the JavaScript
- Facebook Flow is used to type-check the JavaScript
- Babel is used to compile the JavaScript
- webpack is used to package the JavaScript
- UglifyJS 2 is used to compress the JavaScript
- SCSS-Lint is used to lint SASS
- node-sass and Import Once are used to compile SASS
- PostCSS and Autoprefixer are used to automatically add the browser vendor prefixes to the generated CSS
- Clean-css is used to compress the CSS
- Watchman is used to watch for directory changes