Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let minify = function(source, file) {
// Minify
source = uglifyJS.minify({
[file]: source
}, uglifyJSOptions).code
return source
}
getServiceWorkder(options).then(codes => {
// Adding additionalCode to ServiceWorker File
if(options.additionalCodeFile) {
const additionalCode = readFileSync(path.resolve(rootDir, options.additionalCodeFile), 'utf8');
codes += additionalCode;
}
const fileName = 'service-worker.js'
if (minify) {
const compressedCodes = {}
compressedCodes[fileName] = codes
codes = UglifyJS.minify(compressedCodes).code
}
const serviceWorkerFilePath = path.resolve(outDir, fileName)
writeFileSync(serviceWorkerFilePath, codes)
})
})
.then(sources => {
console.log("writing files...")
fs.writeFileSync(targetFile1, sources.noDeps);
fs.writeFileSync(targetFile2, sources.complete);
fs.writeFileSync(targetFile1.replace('.js', '.min.js'), uglifyjs.minify(sources.noDeps, {keep_fnames: true}).code);
fs.writeFileSync(targetFile2.replace('.js', '.min.js'), uglifyjs.minify(sources.complete, {keep_fnames: true}).code);
})
function minifyFilesBeforeCopy(content, $path) {
const result = UglifyJS.minify(content.toString());
if (result.error) {
console.error($path);
throw result.error;
}
return result.code;
}
function minify(path) {
let code = fs.readFileSync(path);
let mini = uglify.minify(code.toString());
if (mini.error) {
console.trace(mini.error);
throw mini.error;
}
return mini.code;
}
process.env.BUILD === 'production' && uglify({}, function (code) {
return minify(code, {
output: {
comments: 'some'
}
})
}),
prod && uglify({}, code => minify(code))
].filter((plugin) => plugin);
plugins.push(uglify({}, code => minify(code)));
}
plugins.push(uglify({}, code => minify(code)));
}
function minify(str, options) {
if (!options || typeof options !== 'object') options = {};
const result = uglify.minify(str, options);
if (result.error) {
throw result.error;
}
return result;
}