Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
huangyingwen opened this issue Dec 19, 2016 · 1 comment
Open

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

huangyingwen opened this issue Dec 19, 2016 · 1 comment

Comments

@huangyingwen
Copy link

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 文件产生

@animabear
Copy link

animabear commented Aug 25, 2017

需要修改下 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;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants