• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript uglify-js.minify函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中uglify-js.minify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript minify函数的具体用法?TypeScript minify怎么用?TypeScript minify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了minify函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: runUglifyInternal

function runUglifyInternal(uglifyJsConfig: UglifyJsConfig): uglify.MinifyOutput {
  return uglify.minify(uglifyJsConfig.sourceFile, {
    compress: uglifyJsConfig.compress,
    mangle: uglifyJsConfig.mangle,
    outSourceMap: uglifyJsConfig.outSourceMap
  });
}
开发者ID:Kode-Kitchen,项目名称:ionic-app-scripts,代码行数:7,代码来源:uglifyjs.ts


示例2: minify

  function minify(js: string): void {
    const js_map = rename(js, {ext: '.js.map'})
    const min_js = rename(js, {ext: '.min.js'})
    const min_js_map = rename(js, {ext: '.min.js.map'})

    const minify_opts = {
      output: {
        comments: /^!|copyright|license|\(c\)/i
      },
      sourceMap: {
        content: read(js_map)! as any,
        filename: basename(min_js),
        url: basename(min_js_map),
      },
    }

    const minified = uglify.minify(read(js)!, minify_opts)

    if (minified.error != null) {
      const {error: {message, line, col}} = minified as any
      throw new Error(`${js}:${line-1}:${col}: ${message}`)
    }

    write(min_js, minified.code)
    write(min_js_map, minified.map)
  }
开发者ID:HuntJSparra,项目名称:bokeh,代码行数:26,代码来源:scripts.ts


示例3: generate

async function generate(rootDir: string) {

    const pbconfigPath = path.join(rootDir, 'pbconfig.json');
    if (!(await fs.existsAsync(pbconfigPath))) {
        if (await fs.existsAsync(path.join(rootDir, 'protobuf'))) {
            const pbconfigPath = path.join(rootDir, 'protobuf', 'pbconfig.json')
            if (!await (fs.existsAsync(pbconfigPath))) {
                await fs.writeFileAsync(pbconfigPath, pbconfigContent, 'utf-8');
            }
            await generate(path.join(rootDir, 'protobuf'));
        }
        else {
            throw '请首先执行 pb-egret add 命令'
        }
        return;
    }
    const pbconfig: ProtobufConfig = await fs.readJSONAsync(path.join(rootDir, 'pbconfig.json'));
    const tempfile = path.join(os.tmpdir(), 'pbegret', 'temp.js');
    await fs.mkdirpAsync(path.dirname(tempfile));
    const output = path.join(rootDir, pbconfig.outputFile);
    const dirname = path.dirname(output);
    await fs.mkdirpAsync(dirname);
    const protoRoot = path.join(rootDir, pbconfig.sourceRoot);
    const fileList = await fs.readdirAsync(protoRoot);
    const protoList = fileList.filter(item => path.extname(item) === '.proto')
    if (protoList.length == 0) {
        throw ' protofile 文件夹中不存在 .proto 文件'
    }
    await Promise.all(protoList.map(async (protofile) => {
        const content = await fs.readFileAsync(path.join(protoRoot, protofile), 'utf-8')
        if (content.indexOf('package') == -1) {
            throw `${protofile} 中必须包含 package 字段`
        }
    }))




    const args = ['-t', 'static', '-p', protoRoot, protoList.join(" "), '-o', tempfile]
    if (pbconfig.options['no-create']) {
        args.unshift('--no-create');
    }
    if (pbconfig.options['no-verify']) {
        args.unshift('--no-verify');
    }
    await shell('pbjs', args);
    let pbjsResult = await fs.readFileAsync(tempfile, 'utf-8');
    pbjsResult = 'var $protobuf = window.protobuf;\n$protobuf.roots.default=window;\n' + pbjsResult;
    await fs.writeFileAsync(output, pbjsResult, 'utf-8');
    const minjs = UglifyJS.minify(pbjsResult);
    await fs.writeFileAsync(output.replace('.js', '.min.js'), minjs.code, 'utf-8');
    await shell('pbts', ['--main', output, '-o', tempfile]);
    let pbtsResult = await fs.readFileAsync(tempfile, 'utf-8');
    pbtsResult = pbtsResult.replace(/\$protobuf/gi, "protobuf").replace(/export namespace/gi, 'declare namespace');
    pbtsResult = 'type Long = protobuf.Long;\n' + pbtsResult;
    await fs.writeFileAsync(output.replace(".js", ".d.ts"), pbtsResult, 'utf-8');
    await fs.removeAsync(tempfile);

}
开发者ID:bestdpf,项目名称:protobuf-egret,代码行数:59,代码来源:index.ts


示例4: getUglifiedSize

/** Returns the size of a uglify minified file in kilobytes */
function getUglifiedSize(filePath: string) {
  let fileContent = readFileSync(filePath, 'utf-8');

  let compressedFile = uglifyJs.minify(fileContent, {
    fromString: true
  });

  return Buffer.byteLength(compressedFile.code, 'utf8') / 1000;
}
开发者ID:Promact,项目名称:md2,代码行数:10,代码来源:payload.ts


示例5: MinifyJS

export function MinifyJS(outputFile: string): string
{
    let outputFileMinified = outputFile.substr(0, outputFile.length - 2) + "min.js";

    let result = UglifyJS.minify([outputFile]);

    writeToFile(outputFileMinified, result.code);
    return result.code;
}
开发者ID:Kasperki,项目名称:NodeBlog,代码行数:9,代码来源:MinifyFiles.ts


示例6: compact

export function compact(text: string, options?: uglify.MinifyOptions): string {
   const output = uglify.minify(text, options);
   if (output.error) {
      log.error(output.error);
      return text;
   } else {
      return output.code;
   }
}
开发者ID:Trail-Image,项目名称:blog,代码行数:9,代码来源:view.ts


示例7: transform_uglify

function transform_uglify(file) {
    try {
        file.raw = uglify.minify(file.raw, {
            fromString: true,
            compress: {
                dead_code: true,
            }
        }).code;
    } catch(e) {}
}
开发者ID:streamich,项目名称:portable,代码行数:10,代码来源:transform-uglify.ts


示例8: uglifyFile

/** Minifies a JavaScript file using UglifyJS2. Also writes sourcemaps to the output. */
function uglifyFile(inputPath: string, outputPath: string) {
  let sourcemapOut = `${outputPath}.map`;
  let result = uglify.minify(inputPath, {
    preserveComments: 'license',
    outSourceMap: sourcemapOut
  });

  writeFileSync(outputPath, result.code);
  writeFileSync(sourcemapOut, result.map);
}
开发者ID:jcannata,项目名称:material2,代码行数:11,代码来源:package-build.ts


示例9: uglifyJsFile

export function uglifyJsFile(inputPath: string, outputPath: string) {
  const sourcemapOut = `${outputPath}.map`;
  const result = uglify.minify(inputPath, {
    outSourceMap: sourcemapOut,
    output: {
      comments: 'some'
    }
  });

  writeFileSync(outputPath, result.code);
  writeFileSync(sourcemapOut, result.map);
}
开发者ID:Chintuz,项目名称:material2,代码行数:12,代码来源:minify-sources.ts


示例10: _transform

 _transform(file: File, encoding: string, callback: FileCB): void {
   if (file.contents && file.path.endsWith('.js')) {
     try {
       let contents = file.contents.toString();
       contents = uglify.minify(contents, UglifyOptions).code;
       file.contents = new Buffer(contents);
     } catch (err) {
       logger.warn(`Unable to uglify file ${file.path}`);
       logger.debug(err);
     }
   }
   callback(null, file);
 }
开发者ID:chuckh,项目名称:polymer-build,代码行数:13,代码来源:uglify-transform.ts



注:本文中的uglify-js.minify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript ui.topmost函数代码示例发布时间:2022-05-25
下一篇:
TypeScript uglify-es.minify函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap