当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript prepack.prepackFromAst函数代码示例

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


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

示例1: transformAndSaveAst

function transformAndSaveAst(fullPath: string, ast: any, options: FableCompilerOptions, info: CompilationInfo) {
    // resolve output paths
    const outPath = getOutPath(fullPath, info) + ".js";
    const jsPath = join(options.outDir, outPath);
    const jsDir = Path.dirname(jsPath);
    ensureDirExists(jsDir);
    // set sourcemap paths
    const code: string | undefined = undefined;
    const babelOptions = Object.assign({}, options.babel) as Babel.TransformOptions;
    if (babelOptions.sourceMaps) {
        // code = fs.readFileSync(fullPath, "utf8");
        const relPath = Path.relative(jsDir, fullPath);
        babelOptions.sourceFileName = relPath.replace(/\\/g, "/");
        babelOptions.sourceMapTarget = Path.basename(outPath);
    }
    babelOptions.plugins = (babelOptions.plugins || [])
        .concat(getResolvePathPlugin(jsDir, options));
    // transform and save
    let result = Babel.transformFromAst(ast, code, babelOptions);
    if (options.prepack) {
        const prepack = require("prepack");
        result = prepack.prepackFromAst(result.ast, result.code, options.prepack);
    }
    fs.writeFileSync(jsPath, result.code);
    if (result.map) {
        fs.appendFileSync(jsPath, "\n//# sourceMappingURL=" + Path.basename(jsPath) + ".map");
        fs.writeFileSync(jsPath + ".map", JSON.stringify(result.map));
    }
    console.log(`fable: Compiled ${Path.relative(process.cwd(), fullPath)}`);
}
开发者ID:forki,项目名称:Fable,代码行数:30,代码来源:index.ts

示例2: transformAndSaveAst

function transformAndSaveAst(fullPath: string, ast: any, options: FableCompilerOptions) {
    // resolve output paths
    const outPath = getOutPath(fullPath) + ".js";
    const jsPath = Path.join(options.outDir, outPath);
    const jsDir = Path.dirname(jsPath);
    ensureDirExists(jsDir);
    // set sourcemap paths
    const code: string | undefined = undefined;
    if (options.babel && options.babel.sourceMaps) {
        // code = fs.readFileSync(fullPath, "utf8");
        const relPath = Path.relative(jsDir, fullPath);
        options.babel.sourceFileName = relPath.replace(/\\/g, "/");
        options.babel.sourceMapTarget = Path.basename(outPath);
    }
    // transform and save
    let result = Babel.transformFromAst(ast, code, options.babel);
    if (options.prepack) {
        const prepack = require("prepack");
        result = prepack.prepackFromAst(result.ast, result.code, options.prepack);
    }
    if (result && result.code) { fs.writeFileSync(jsPath, result.code); }
    if (result && result.map) { fs.writeFileSync(jsPath + ".map", JSON.stringify(result.map)); }
    console.log(`Fable compiled: ${fullPath}`);
}
开发者ID:davidtme,项目名称:Fable,代码行数:24,代码来源:index.ts


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