babel/minify

SourceMap URL not appended when Babili is executed from JS API

オープン

#362 opened on 2017/01/04

 (0 件のコメント) (1 件のリアクション) (0 人の担当者)JavaScript (223 件のフォーク)batch import
help wanted

Repository metrics

Stars
 (4,377 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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));

コントリビューターガイド