enjoy-source-map

2019-06-12 admin

enjoy-source-map是什么

什么是enjoy-source-map,Generate source-map for templates and merge

enjoy-source-map使用教程帮助文档

enjoy-source-map build status

NPM

将含有内联sourcemap的文件合并、模板替换,保持原有对应关系.

var combline = require('enjoy-source-map');

//读取源代码
var content = fs.readFileSync(path.resolve(__dirname, "index.js"), {
    encoding: "utf8"
});

//读取模板
var Tpl = fs.readFileSync(path.resolve(__dirname, "inner-mod.tpl"), {
    encoding: "utf8"
});

//babel转换源代码(需配置sourceMaps:'line')
var source =  babel.transform(content, {...}).code;

content = combline.overWriteTlp(Tpl,{
    content:source
});

console.log(content);
// index.js
function(__inner_require__, exports, module) {
    'use strict';

    var _babelPolyfill = require("babel-polyfill@6/lib/index.js");

    var _babelPolyfill2 = babelHelpers.interopRequireDefault(_babelPolyfill);

    var _enjoyWebSupportElong = require("enjoy-web-support-elong@0.2/index.js");

    var _enjoyWebSupportElong2 = babelHelpers.interopRequireDefault(_enjoyWebSupportElong);

    var _main = __inner_require__(1 /*main.js*/ );

    var _main2 = babelHelpers.interopRequireDefault(_main);

    _enjoyWebSupportElong2.default.React.render(_enjoyWebSupportElong2.default.React.createElement(_main2.default), document.getElementsByTagName("div")[0]);

}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9qaWUvRG9jdW1lbnRzL2Vsb25nL2Vuam95VGVzdC93ZWIvaDUvX2J1aWxkL2luZGV4LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0NBQUE7O0NBRUE7Ozs7Q0FDQTs7OztDQUNBOzs7O0NBRUEsK0JBQUEsQUFBTSxNQUFOLEFBQVksT0FBTywrQkFBQSxBQUFNLE1BQU4sQUFBWSxxQkFBL0IsVUFBb0QsU0FBQSxBQUFTLHFCQUFULEFBQThCLE9BQWxGLEFBQW9ELEFBQXFDIiwiZmlsZSI6ImJ1bmRsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyIndXNlIHN0cmljdCc7XG5cbmltcG9ydCBCYWJlbFBvbHlmaWxsIGZyb20gXCJiYWJlbC1wb2x5ZmlsbFwiO1xuaW1wb3J0IEVuam95IGZyb20gXCJlbmpveS13ZWItc3VwcG9ydC1lbG9uZ1wiO1xuaW1wb3J0IE1haW4gZnJvbSBcIi4vbWFpblwiO1xuXG5FbmpveS5SZWFjdC5yZW5kZXIoRW5qb3kuUmVhY3QuY3JlYXRlRWxlbWVudChNYWluKSwgZG9jdW1lbnQuZ2V0RWxlbWVudHNCeVRhZ05hbWUoXCJkaXZcIilbMF0pO1xuIl19

API

overWriteTlp(tpl, data)

模板替换

var content = combline.overWriteTlp(Tpl,{
    content:source
});

overWriteJoin(codes,jo = ‘,\n’)

数组合并

var codes = [code1,code2];
var mods = combline.overWriteJoin(codes);

overWriteReplace(target,regexp|substr, newSubstr|function)

replace替换

var content = combline.overWriteReplace(codes,/(p1)(p2)/g,function(match, p1, p2){
        return [p1, p2].join(' - ');
    });

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-67134.html

文章标题:enjoy-source-map

回到顶部