當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。