eriwen / gradle-js-plugin

Gradle plugin for working with JS
http://eriwen.github.io/gradle-js-plugin
Apache License 2.0
382 stars 113 forks source link

sourceMap sources path #78

Open tnbalu opened 10 years ago

tnbalu commented 10 years ago

Hi, I have created a minified file and sourcemap file.

In the sourcemap file sources path is absolute path "ie" d:/abcd/sdsd/sdsd/employee.js but it shoule be employee.js

Can you guide me how to change the path in sources.

Issue:- While it is running in test environment it will look for d://.../../employee.js

tnbalu commented 10 years ago

1) Source map annotation prefix.

The generated minified source file is not containing the map file referance e.g. //@ sourceMappingURL=simple.js.map

Thanks!

sameer7 commented 10 years ago

Same issue here with version 1.12.0

sameer7 commented 10 years ago

It seem like closure compiler itself is not adding map file reference.

djKianoosh commented 9 years ago

I see the same issue.. i digged down into the source and (without running it mind you) it looks like it uses the Google CompilerOptions object to configure this from JsMinifier.groovy:

If you can't wait for a fix to the plugin and just want to rewrite the sourcemap as a hack, you can do it in the doLast closure of the minifyJs task, something like: (my groovy-fu is rusty so feel free to make it better)

minifyJs {
    source = combineJs
    dest = file("${outputJsDir}/application.min.js")
    sourceMap = file("${outputJsDir}/application.min.map")
    closure {
        warningLevel = 'QUIET'
    }
    doLast {
        file("${outputJsDir}/application.min.js") << "\n//# sourceMappingURL=application.min.map"

        Map srcMap = new JsonSlurper().parseText( sourceMap.text )
        srcMap.sources = ["application.js"]
        sourceMap.withWriter("UTF-8") { it << new JsonBuilder(srcMap).toPrettyString() }
    }
}
tasks.minifyJs.dependsOn tasks.combineJs

Notes:

dparish commented 9 years ago

Thank you @djKianoosh that helped alot. For those that stumble upon this, fully qualify the class names:

    Map srcMap = new groovy.json.JsonSlurper().parseText( sourceMap.text )
    srcMap.sources = ["application.js"]
    sourceMap.withWriter("UTF-8") { it << new groovy.json.JsonBuilder(srcMap).toPrettyString() }
djKianoosh commented 9 years ago

@dparish ah yes, I assumed import groovy.json.* at the top; same difference :)