Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fs = require('fs');
const mkdir = require('mk-dirs');
const pretty = require('pretty-bytes');
const { minify } = require('terser');
const sizer = require('gzip-size');
const pkg = require('./package');
const ESM = fs.readFileSync('src/index.js', 'utf8');
const regexparam = require('regexparam').toString();
mkdir('dist').then(() => {
// Copy as is for ESM
fs.writeFileSync(pkg.module, ESM);
// Mutate (im|ex)ports for CJS
const CJS = regexparam.replace('function ', 'function convert ').concat(
ESM.replace(`import convert from 'regexparam';`, '')
.replace(/export default/, 'module.exports =')
);
fs.writeFileSync(pkg.main, CJS);
// Minify & print gzip-size
const { code } = minify(CJS, { toplevel:true, compress:{ passes:10 } });
console.log(`> gzip size: ${pretty(sizer.sync(code))}`);
const fs = require('fs');
const mkdir = require('mk-dirs');
const pretty = require('pretty-bytes');
const { minify } = require('terser');
const sizer = require('gzip-size');
const pkg = require('../package');
const ESM = fs.readFileSync('src/index.js', 'utf8');
const regexparam = require('regexparam').toString();
mkdir('dist').then(() => {
// Copy as is for ESM
fs.writeFileSync(pkg.module, ESM);
// Mutate (im|ex)ports for CJS
const CJS = ESM.replace(
`import toRegExp from 'regexparam';`,
`var toRegExp = require('regexparam');`
).replace(/export default/, 'module.exports =')
fs.writeFileSync(pkg.main, CJS);
// Mutate again for UMD prep :: inline dependency
const INLINED = regexparam.replace('function ', 'function toRegExp').concat(
CJS.replace(`var toRegExp = require('regexparam');`, '')