Created
March 21, 2019 11:43
-
-
Save fallen90/e701ad39c49144efaffeffe394e4151b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var glob = require('glob'); | |
var mkdirp = require('mkdirp'); | |
var ncc = require('@zeit/ncc'); | |
var dist = path.join(__dirname, 'dist'); | |
var distRoutes = path.join(dist, 'routes'); | |
var src = path.join(__dirname, 'src'); | |
var srcRoutes = path.join(src, 'routes'); | |
// check if src exists | |
console.log(` | |
Building route files | |
`) | |
if (fs.existsSync(src)) { | |
// list all files in directory | |
glob(path.join(srcRoutes, '/**/*.js'), function (err, files) { | |
if (!err) { | |
files.forEach(file => { | |
const base = file.replace(srcRoutes, ''); | |
const completePath = path.join(dist, base); | |
const outputDir = path.dirname(completePath); | |
mkdirp(outputDir, err => { | |
if (!err) { | |
console.log('Compiling ==>', base); | |
ncc(file, { | |
// provide a custom cache path or disable caching | |
cache: false, | |
minify: false, // default | |
sourceMap: false, // default | |
sourceMapRegister: false, // default | |
watch: false // default | |
}).then(({ code }) => { | |
fs.writeFileSync(completePath, code); | |
if (fs.existsSync(completePath)) { | |
console.log('Output ==>', completePath); | |
} | |
}) | |
} | |
}); | |
}) | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment