babel/minify

SourceMap URL not appended when Babili is executed from JS API

开放

#362 创建于 2017年1月4日

 (0 条评论) (1 个反应) (0 位负责人)JavaScript (223 个派生)batch import
help wanted

仓库指标

星标
 (4,377 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Hi guys, I'm trying to use babili from JS API but I'm having a problem. If I use it from CLI in this way:

babel ./build/popper.js --inputSourceMap=./build/popper.js.map -s -o ./build/popper.min.js

The resulting popper.min.js file will have at its bottom the comment:

//# sourceMappingURL=popper.min.js.map

If, instead, I use it from JS:

const options = {
    presets: ['babili', 'stage-2'],
    comments: false,
    minified: true,
    compact: true,
    sourceMaps: true,
    inputSourceMap: JSON.parse(fs.readFileSync(`${input}.map`, { encoding: 'utf8' })),
};
const result = babel.transform(inputCode, options);

The resulting code has not the source map comment. Do you know what I'm doing wrong?

For reference, this is the whole script:

// Not working...

const argv = require('yargs').argv;
const babel = require('babel-core');
const fs = require('fs');
const path = require('path');

const input = path.resolve(process.cwd(), argv.i);
const output = path.resolve(process.cwd(), argv.o);
const outputMap = `${output}.map`;

const inputCode = fs.readFileSync(input, { encoding: 'utf8' });
const inputSourceMap = JSON.parse(fs.readFileSync(`${input}.map`, { encoding: 'utf8' }));

// Generate options
//=================
const options = {
    presets: [
        'babili',
        !!argv.es5 && ['es2015', { modules: false }],
        'stage-2',
    ],
    comments: false,
    minified: true,
    compact: true,
    sourceMaps: true,
    inputSourceMap,
};

options.presets = options.presets.filter(a => !!a);

// Transform code
//===============
const result = babel.transform(inputCode, options);

// Write output files
//===================
fs.writeFileSync(output, result.code);
fs.writeFileSync(outputMap, JSON.stringify(result.map));

贡献者指南