How to use the terser.minify function in terser

To help you get started, we’ve selected a few terser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / ncc / src / index.js View on Github external
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 });
    }
github aurelia / aurelia / test / js-framework-benchmark / results-ui / src / build.js View on Github external
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>
github politie / sherlock / scripts / process-bundle.js View on Github external
['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);
    });
});
github 104corp / espack / lib / api / tasks / Task.js View on Github external
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);
  }
}
github mvdom / mvdom / scripts / build.js View on Github external
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`);

}
github krausest / js-framework-benchmark / results-ui / src / build.js View on Github external
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>
github standard-things / esm / script / publish.js View on Github external
function minifyJS(content) {
  return terser(content, terserOptions).code
}
github vuchan / vue-mfe / build / build.js View on Github external
.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)
      }
    })
}
github izelnakri / mber / lib / builders / build-documentation.js View on Github external
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);
}
github babel / minify / scripts / benchmark.js View on Github external
terser(code) {
    return terser.minify(code).code;
  }
  "closure-compiler"(filename) {

terser

JavaScript parser, mangler/compressor and beautifier toolkit for ES6+

BSD-2-Clause
Latest version published 19 days ago

Package Health Score

92 / 100
Full package analysis