本文整理匯總了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}`);
}