Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
map = JSON.parse(map);
// make source map sources relative to output
map.sources = map.sources.map(source => {
// webpack:///webpack:/// happens too for some reason
while (source.startsWith('webpack:///'))
source = source.substr(11);
if (source.startsWith('./'))
source = source.substr(2);
if (source.startsWith('webpack/'))
return '/webpack/' + source.substr(8);
return sourceMapBasePrefix + source;
});
}
if (minify) {
const result = terser.minify(code, {
compress: false,
mangle: {
keep_classnames: true,
keep_fnames: true
},
sourceMap: sourceMap ? {
content: map,
filename,
url: `${filename}.map`
} : false
});
// For some reason, auth0 returns "undefined"!
// custom terser phase used over Webpack integration for this reason
if (result.code !== undefined)
({ code, map } = { code: result.code, map: result.map });
}
booleans: false,
inline: 0,
keep_fargs: false,
hoist_props: false,
loops: false,
reduce_funcs: false,
unsafe: true,
unsafe_math: true,
}),
};
const { output } = await bundle.generate({
format: "iife",
});
const minJs = terser.minify(output[0].code, uglifyOpts).code;
var css = fs.readFileSync(__dirname + '/bootstrap-reboot.css', 'utf8').replace(/\/\*[\s\S]+?\*\/\s*/gm, '');
css += fs.readFileSync(__dirname + '/style.css', 'utf8');
const minCss = new CleanCSS({level: 2}).minify(css).styles;
const html = [
'',
'',
'',
'',
'',
'<title>Interactive Results</title>',
'',
'<style>',
minCss,</style>
['esm', 'cjs', 'umd'].forEach(suf => {
const file = fs.readFileSync(`dist/${lib}/${lib}.${suf}.js`, 'utf8');
const fileSM = fs.readFileSync(`dist/${lib}/${lib}.${suf}.js.map`, 'utf8');
const result = terser.minify(file, {
module: suf !== 'umd',
sourceMap: {
content: fileSM,
filename: `${lib}.${suf}.min.js`,
url: `${lib}.${suf}.min.js.map`,
},
compress: { unsafe: true, passes: 2, warnings: true, pure_funcs: ['Object.freeze'] },
mangle: { properties: { regex: /^_(?!_)(?!internal)/ } }
});
const target = `dist/${lib}/${lib}.${suf}.min.js`;
const targetSM = `dist/${lib}/${lib}.${suf}.min.js.map`;
fs.writeFileSync(target, result.code, 'utf8');
fs.writeFileSync(targetSM, result.map, 'utf8');
console.log('-', target);
});
});
minify(code) {
const { dev, dropConsole } = getConfigOptions();
let buildCode = code;
if (!dev) {
const result = terser.minify(buildCode, {
warnings: false,
compress: {
drop_console: dropConsole,
},
output: {
comments: false,
},
ie8: true,
safari10: true,
});
if (result.error) console.log(result.error);
buildCode = result.code;
}
fse.writeFileSync(this.savePath, buildCode);
}
}
async function compile(mode) {
await fs.mkdirs("./dist/");
await fs.saferRemove([distJs]);
await browserifyFiles(srcFile, distJs);
const distStat = await fs.stat(distJs);
console.log(`Browserified ${distJs} - ${distStat.size / 1000}kb`);
var content = await fs.readFile(distJs, "utf8");
const minContent = Terser.minify(content);
await fs.writeFile(distMin, minContent.code, "utf8");
const minStat = await fs.stat(distMin);
console.log(`Minified ${distMin} - ${minStat.size / 1000}kb`);
}
booleans: false,
inline: 0,
keep_fargs: false,
hoist_props: false,
loops: false,
reduce_funcs: false,
unsafe: true,
unsafe_math: true,
}),
};
const { output } = await bundle.generate({
format: "iife",
});
const minJs = terser.minify(output[0].code, uglifyOpts).code;
var css = fs.readFileSync(__dirname + '/bootstrap-reboot.css', 'utf8').replace(/\/\*[\s\S]+?\*\/\s*/gm, '');
css += fs.readFileSync(__dirname + '/style.css', 'utf8');
const minCss = new CleanCSS({level: 2}).minify(css).styles;
const html = [
'',
'',
'',
'',
'',
'<title>Interactive Results</title>',
'',
'<style>',
minCss,</style>
function minifyJS(content) {
return terser(content, terserOptions).code
}
.then(({ code }) => {
if (isProd) {
const minified =
(banner ? banner + '\n' : '') +
terser.minify(code, {
toplevel: true,
output: {
ascii_only: true
},
compress: {
pure_funcs: ['makeMap']
}
}).code
return write(file, minified, true)
} else {
return write(file, code)
}
})
}
function writeDocumentationJS(outputPath, environment, code) {
if (['demo', 'production'].includes(environment)) {
return fs.writeFile(
outputPath,
Terser.minify(code, {
compress: {
negate_iife: false,
sequences: 20
},
output: {
semicolons: false
}
}).code
);
}
return fs.writeFile(outputPath, code);
}
terser(code) {
return terser.minify(code).code;
}
"closure-compiler"(filename) {