Better build process (#1248)
* Remove gulp, replace with custom scripts * Symlink entire dirs where possible (fixes #1232) * Significantly speed up subsequent builds (fixes #1238) * Watch process now observes new/removed files, not only changed * Add ignoreMask, exclude all files with names starting with a # * Better logging during builds * Update travis.yml to use new, non-gulp-based build
This commit is contained in:
parent
3259b63081
commit
b53fabbb58
19 changed files with 1149 additions and 1607 deletions
56
scripts/babel-worker.js
Normal file
56
scripts/babel-worker.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* global onmessage: true, postMessage: false */
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const babel = require('babel-core');
|
||||
const multimatch = require('multimatch');
|
||||
const options = JSON.parse(fs.readFileSync('.babelrc'));
|
||||
const cluster = require('cluster');
|
||||
|
||||
/* exported onmessage */
|
||||
async function babelWorker(ev) {
|
||||
const t1 = Date.now();
|
||||
const sourcefile = ev.file;
|
||||
const outfile = path.join('build', sourcefile);
|
||||
const postError = (error) => {
|
||||
process.send({
|
||||
sourcefile,
|
||||
outfile,
|
||||
error
|
||||
});
|
||||
};
|
||||
|
||||
var isSkipped = false;
|
||||
var transformed;
|
||||
|
||||
try {
|
||||
let contents = await fs.readFile(sourcefile, 'utf8');
|
||||
if (sourcefile === 'resource/react-dom.js') {
|
||||
// patch react
|
||||
transformed = contents.replace(/ownerDocument\.createElement\((.*?)\)/gi, 'ownerDocument.createElementNS(DOMNamespaces.html, $1)');
|
||||
} else if ('ignore' in options && options.ignore.some(ignoreGlob => multimatch(sourcefile, ignoreGlob).length)) {
|
||||
transformed = contents;
|
||||
isSkipped = true;
|
||||
} else {
|
||||
try {
|
||||
transformed = babel.transform(contents, options).code;
|
||||
} catch (error) { return postError(`Babel error: ${error}`);}
|
||||
}
|
||||
|
||||
await fs.outputFile(outfile, transformed);
|
||||
const t2 = Date.now();
|
||||
process.send({
|
||||
isSkipped,
|
||||
sourcefile,
|
||||
outfile,
|
||||
processingTime: t2 - t1
|
||||
});
|
||||
} catch (error) { return postError(`I/O error: ${error}`); }
|
||||
}
|
||||
|
||||
module.exports = babelWorker;
|
||||
|
||||
if (cluster.isWorker) {
|
||||
process.on('message', babelWorker);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue