fex-team/fis-parser-babel-6.x

sourceMaps: true 配置没有产生 .map 文件

Opened this issue · 1 comments

sourceMaps: true 配置没有产生 .map 文件
fis.match('{*.jsx,*:jsx}', { parser: fis.plugin('babel-6.x', { sourceMaps: true }), rExt: '.js' });

https://github.com/fex-team/fis3-demo/tree/master/use-react
换成 babel-6.x .map 文件产生

需要修改下 fis-parser-babel-6.x

module.exports = function(content, file, conf) {
    // 添加 useBabel 配置项,如果 useBabel 为 false 则不进行编译
    if (file.useBabel === false) {
        return content;
    }

    conf = fis.util.extend({
        presets: [
            preset2015,
            presetstage3,
            react
        ]
    }, conf);

    // 添加 jsx 的 html 语言能力处理
    if (fis.compile.partial && file.ext === '.jsx') {
        content = fis.compile.partial(content, file, {
            ext: '.html',
            isHtmlLike: true
        });
    }

    var sourceMapRelative = conf.sourceMapRelative;

    if (sourceMapRelative) {
        delete conf.sourceMapRelative;
    }

    // 出于安全考虑,不使用原始路径
    // conf.filename = file.subpath;

    var result = babel.transform(content, conf);

    // 添加resourcemap输出
    if (result.map) {
        var mapping = fis.file.wrap(file.dirname + '/' + file.filename + file.rExt + '.map');
        mapping.setContent(JSON.stringify(result.map, null, 4));
        var url = sourceMapRelative ? ('./' + file.basename + '.map').replace('jsx', 'js') :
            mapping.getUrl(fis.compile.settings.hash, fis.compile.settings.domain);
        result.code = result.code.replace(/\n?\s*\/\/#\ssourceMappingURL=.*?(?:\n|$)/g, '');
        result.code += '\n//# sourceMappingURL=' + url + '\n';
        file.derived.push(mapping);
    }

    return result.code;
};