模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    convert-source-map [![Build Status][ci-image]][ci-url]

    社区公告
    1
    1
    0
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>convert-source-map [![Build Status][ci-image]][ci-url]</h2>

      <p>Converts a source-map from/to different formats and allows adding/changing properties.</p>

      <pre><code>
      var convert = require('convert-source-map');

      var json = convert
      .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
      .toJSON();

      var modified = convert
      .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
      .setProperty('sources', [ 'SRC/FOO.JS' ])
      .toJSON();

      console.log(json);
      console.log(modified);
      </code></pre>

      <pre><code>
      {"version":3,"file":"build/foo.min.js","sources":["src/foo.js"],"names":[],"mappings":"AAAA","sourceRoot":"/"}
      {"version":3,"file":"build/foo.min.js","sources":["SRC/FOO.JS"],"names":[],"mappings":"AAAA","sourceRoot":"/"}
      </code></pre>

      <h3>Upgrading</h3>

      <p>Prior to v2.0.0, the <code>fromMapFileComment</code> and <code>fromMapFileSource</code> functions took a String directory path and used that to resolve & read the source map file from the filesystem. However, this made the library limited to nodejs environments and broke on sources with querystrings.</p>

      <p>In v2.0.0, you now need to pass a function that does the file reading. It will receive the source filename as a String that you can resolve to a filesystem path, URL, or anything else.</p>

      <p>If you are using <code>convert-source-map</code> in nodejs and want the previous behavior, you'll use a function like such:</p>

      <pre><code>

      • var fs = require('fs'); // Import the fs module to read a file
      • var path = require('path'); // Import the path module to resolve a path against your directory
      • var conv = convert.fromMapFileSource(css, '../my-dir');
      • var conv = convert.fromMapFileSource(css, function (filename) {
      • return fs.readFileSync(path.resolve('../my-dir', filename), 'utf-8');
      • });
        </code></pre>

      <h3>API</h3>

      <h4>fromObject(obj)</h4>

      <p>Returns source map converter from given object.</p>

      <h4>fromJSON(json)</h4>

      <p>Returns source map converter from given json string.</p>

      <h4>fromURI(uri)</h4>

      <p>Returns source map converter from given uri encoded json string.</p>

      <h4>fromBase64(base64)</h4>

      <p>Returns source map converter from given base64 encoded json string.</p>

      <h4>fromComment(comment)</h4>

      <p>Returns source map converter from given base64 or uri encoded json string prefixed with <code>//# sourceMappingURL=...</code>.</p>

      <h4>fromMapFileComment(comment, readMap)</h4>

      <p>Returns source map converter from given <code>filename</code> by parsing <code>//# sourceMappingURL=filename</code>.</p>

      <p><code>readMap</code> must be a function which receives the source map filename and returns either a String or Buffer of the source map (if read synchronously), or a <code>Promise</code> containing a String or Buffer of the source map (if read asynchronously).</p>

      <p>If <code>readMap</code> doesn't return a <code>Promise</code>, <code>fromMapFileComment</code> will return a source map converter synchronously.</p>

      <p>If <code>readMap</code> returns a <code>Promise</code>, <code>fromMapFileComment</code> will also return <code>Promise</code>. The <code>Promise</code> will be either resolved with the source map converter or rejected with an error.</p>

      <p>#### Examples</p>

      <p><strong>Synchronous read in Node.js:</strong></p>

      <pre><code>
      var convert = require('convert-source-map');
      var fs = require('fs');

      function readMap(filename) {
      return fs.readFileSync(filename, 'utf8');
      }

      var json = convert
      .fromMapFileComment('//# sourceMappingURL=map-file-comment.css.map', readMap)
      .toJSON();
      console.log(json);
      </code></pre>

      <p>**Asynchronous rea</p>

      <hr>
      <p>你们厂里是怎么处理的?来评论区聊聊。</p>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors