當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript uglify-js.minify函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。