Revision 77fd48fc4d8e78d2c12eb542eca6b54bfb08f2a5 authored by Eric Prud'hommeaux on 31 March 2019, 11:28:28 UTC, committed by Eric Prud'hommeaux on 01 April 2019, 11:07:29 UTC
1 parent 16c16fb
browser-all.js
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const browserify = require("browserify")
const uglify = require("terser")
const packageGlobs = JSON.parse(
fs.readFileSync(__dirname + '/lerna.json', 'utf-8')
).packages.filter(
glob => glob !== "."
)
const directories = packageGlobs.reduce(
(list, path) => list.concat(glob.glob.sync(path)), []
).filter(dir => dir.indexOf('cli') === -1)
// https://github.com/browserify/browserify-handbook#using-the-api-directly
const res = directories.map(dir => {
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json')))
const baseName = pkg.main.replace(/\.js$/, '')
const mainPath = path.join(dir, baseName)
const outPath = path.join(dir, 'browser', baseName + '-browserify.js')
const outMinPath = path.join(dir, 'browser', baseName + '-browserify.min.js')
console.log(mainPath, "->", outPath)
let outStream = fs.createWriteStream(outPath)
let b = browserify(mainPath, {standalone: path.basename(baseName)}).bundle()
b.on('error', console.error)
// b.pipe(outStream)
const chunks = [];
b.on("data", function (chunk) {
chunks.push(chunk.toString());
outStream.write(chunk);
});
b.on("end", function () {
outStream.end();
let min = uglify.minify(chunks.join(''), {
"keep_classnames": true
});
let outMinStream = fs.createWriteStream(outMinPath);
outMinStream.write(min.code);
outMinStream.end();
});
})
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...