two-files.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var convert = require('convert-source-map');
  3. var combine = require('..');
  4. var foo = {
  5. version : 3,
  6. file : 'foo.js',
  7. sourceRoot : '',
  8. sources : [ 'foo.coffee' ],
  9. names : [],
  10. mappings : ';AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ',
  11. sourcesContent : [ 'console.log(require \'./bar.js\')\n' ] };
  12. var bar = {
  13. version : 3,
  14. file : 'bar.js',
  15. sourceRoot : '',
  16. sources : [ 'bar.coffee' ],
  17. names : [],
  18. mappings : ';AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ',
  19. sourcesContent : [ 'console.log(alert \'alerts suck\')\n' ] };
  20. var fooComment = convert.fromObject(foo).toComment();
  21. var barComment = convert.fromObject(bar).toComment();
  22. var fooFile = {
  23. source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + fooComment
  24. , sourceFile: 'foo.js'
  25. };
  26. var barFile = {
  27. source: '(function() {\n\n console.log(alert(\'alerts suck\'));\n\n}).call(this);\n' + '\n' + barComment
  28. , sourceFile: 'bar.js'
  29. };
  30. var offset = { line: 2 };
  31. var base64 = combine
  32. .create('bundle.js')
  33. .addFile(fooFile, offset)
  34. .addFile(barFile, { line: offset.line + 8 })
  35. .base64();
  36. var sm = convert.fromBase64(base64).toObject();
  37. console.log('Combined source maps:\n', sm);
  38. console.log('\nMappings:\n', sm.mappings);