grunt-traceur icon indicating copy to clipboard operation
grunt-traceur copied to clipboard

Having problems with source maps & gruntfile config

Open Jezternz opened this issue 10 years ago • 4 comments

Hi there,

I am having some trouble with sourcemaps, and was wondering if someone could take a look and help me work out what I need to change.

I have given my grunt file & output of my game.js file below, basically in my grunt file I copy the html + css files into a temp directory, then use traceur to compile down my es7 files to the same temp directory. Then when complete I copy them into an "out" directory. The end result is correct es5 files and correct source maps, but the source map url inside the game.js file is wrong and includes my temp directory, I am just wondering if anyone has any suggestions on removing this part of the url - apart from just using another plugin. Maybe I am using this wrong?

This is the line in game.js I want to not include my 'temp' directory - or 'out' directory for that matter.

//# sourceMappingURL=temp/script/game.map

GruntFile.js

'use strict';
module.exports = function(grunt) 
{
    var sourceFolder = "../source/";
    var tempFolder = "temp/";
    var destinationOutFolder = "../out/";
    grunt.initConfig({
        "clean":
        {
            "options": { "force": true },
            "temp": [ tempFolder ],
            "dev": [ destinationOutFolder ]
        },
        "copy":
        {
            "temp":
            {
                "files": [{ "expand": true, "cwd": sourceFolder, "src": ['**/**/*.html', '**/**/*.css'], "dest": tempFolder }]
            },
            "dev":
            {
                "files": [{ "expand": true, "cwd": tempFolder, "src": ['**/**/*.*'], "dest": destinationOutFolder }]
            },
        },
        "watch":
        {
            "options": { "livereload": true },
            "webfiles":
            {
                "options": { "atBegin": true, "spawn": true, "interrupt": false, "debounceDelay": 1000 },
                "tasks": ["default"],
                "files": [ sourceFolder + "**/**/*.*" ],
            }
        },
        "traceur": 
        {
            "options": 
            {
                "sourceMaps": true,
                "experimental": true,
                "moduleNaming": 
                {
                    "stripPrefix": "temp/script"
                },
                "copyRuntime": tempFolder+"/script/"
            },
            "custom": {
                "files": [{
                    "expand": true,
                    "cwd": sourceFolder,
                    "src": ['**/**/*.js'],
                    "dest": tempFolder
                }]
            }
        }
    });
    // grunt.loadNpmTasks....
    grunt.registerTask('default', [
        "clean:temp",
        "clean:dev",        
        "copy:temp",
        "traceur",
        "copy:dev",
        "clean:temp"
    ]);
};

Game.js

System.registerModule("game", [], function() {
  "use strict";
  var __moduleName = "game";
  var Game = function Game() {
    alert('get sourcemaps working!');
  };
  ($traceurRuntime.createClass)(Game, {}, {});
  ;
  return {get Game() {
      return Game;
    }};
});

//# sourceMappingURL=temp/script/game.map
//# sourceURL=../source/script/game.js

Jezternz avatar Jan 31 '15 04:01 Jezternz

I can tell you for sure that this plugin has no specific option for not writting that line in the output file. However there might be one traceur option that does that, maybe you could check there. I will take a look when I have some time

mciparelli avatar Jan 31 '15 23:01 mciparelli

Hi mciparelli, Thanks for the reply, my problem is not so much I do not want the url there, its more I want the url to be relative to a different to the directory I am running grunt from. (I want to remove the temp/ and ../source/ in my case.

Jezternz avatar Feb 01 '15 03:02 Jezternz

I'm not sure such thing is possible using Traceur. We rely the sourcemap line on Traceur, we do not write it ourselves, and I'd like to keep it like that. Checkout this conversation: https://github.com/google/traceur-compiler/issues/1676 maybe that can help you understand anything else about that line. If you ever detect an option that works with Traceur and helps you resolve your issue you can use it directly with this plugin.

mciparelli avatar Feb 04 '15 22:02 mciparelli

I'm seeing different results here. The transpiled source ends with a sourceMappingURL of the form <filename>.js.map; however (with sourceMaps:true) the mapping file is written to <filename>.map, without the source file extension.

The following change in tasks/traceur.js fixes that:

- sourceMapName = path.basename(src, path.extname(src)) + '.map';
+ sourceMapName = path.basename(src) + '.map'; // XXX

This is using:

laurie71 avatar Mar 28 '15 05:03 laurie71