本文整理汇总了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)}`);
}
示例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}`);
}