wro4j icon indicating copy to clipboard operation
wro4j copied to clipboard

Support for source map generation

Open bbergstrom opened this issue 12 years ago • 12 comments

I know there is an old ticket in your Google project, but wanted to get it into your more active Github space for discussion. https://code.google.com/p/wro4j/issues/detail?id=517

I have been tossing around ideas in my head of how to add support for generating source maps to wro4j, but am encountering some big issues. Thought I would start a discussion about this to see if there is a viable way to implement this.

References

  • https://github.com/ryanseddon/source-map/wiki/Source-maps%3A-languages%2C-tools-and-other-info
  • http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
  • https://github.com/mozilla/source-map

Dependencies

The first question is what information does the source map generation depend on? It needs to know the generated filename, which would be the group name possibly with a naming strategy. It needs to know about the original source files in each group, which are all in the model. It needs to know about the resulting group code files after all concatenation and processing is done. It also should be minimize aware, because the resulting code will differ based on minification. Or at the least, work only in non minified mode, because this feature is really for development, not production.

Design Ideas

Closure

The google closure compiler that is part of wro-extensions already supports source maps, lets take advantage of that.... but this is a processor that will only know of the source files(pre) or the concatenated source(post) and may not be the last processor in the chain. This processor could be extended to be run as both pre and post, persisting information between the two process calls for the mappings and require it to be the last JS processor in the chain. This doesn't do anything for CSS source maps from LESS/SASS.

LESS

LESS.js has support for generating source maps. But, it needs to know the source files. wro4j Less processors are required to run as post processors in order for mixins/variables to resolve across LESS files. Same issue as Closure, the post processors need to know about the source files.

New Processor

We could make a AbstractSourceMapProcessor, with a sub class for JS and CSS. This would need to run as pre and post, persisting information in the thread local context(or some other means) across the process calls to generate the mapping afte the post processing.
This would likely have to take advantage of the 'sections' part of the spec, so that the maps for each source file could be put together after the wro4j group concatenation. See Source Map Rev 3 doc section titled 'Index map: supporting post processing'. This is where I hit another problem. LessProcessor is required to run as a POST This could run similar to the RhinoLessProcessor, using the Mozilla Javascript based source-map library.

Problem Context

For some context on the problem I am solving. Our initial plan was to use 'exploded' mode from the taglib for development, which allows developers to see where the source is for generated CSS. https://github.com/ibsys/wro4j-taglib#style-syntax But, this doesn't work because we have multiple levels of LESS stylesheets which have variable/mixin dependencies(Bootstrap, product, client, site). This works out great when compiling server side using wro4j, but we need a less painful way to develop LESS.

  • Considered removing the LESS dependencies, but that causes us to lose a lot of the benefit of using Twitter Bootstrap.
  • Thought about modifying our WRO model, so that LESS is chained via CSS imports, which would work but makes LESS the exception in our WRO model and would cause us to always create duplicate WRO groups(one with LESS, one without).
  • Could extend the wro4j-taglib so when it detects LESS in exploded mode, to create a fake LESS wrapper stylesheet that imports all the less. The main problem with this is that the generated fake LESS wrapper will have to be at the end of all the tags on the page, which could affect behavior.

I look forward to your input on the topic.

bbergstrom avatar Feb 26 '13 16:02 bbergstrom

@bbergstrom thanks for such detailed description of the problem. I will think about it and will get back to you.

alexo avatar Feb 27 '13 16:02 alexo

+1 for this ticket. Any plan for this @alexo?

dominiclovell avatar Jun 01 '13 22:06 dominiclovell

Currently I'm focused on finishing issues for release 1.6.4. There are still issues and deffects which worth fixing before adding new features.

However, if there are anybody really interested in making this feature a priority, a contribution would help a lot.

Cheers, Alex

alexo avatar Jun 02 '13 07:06 alexo

Hi @alexo, I would be really interested about this new functionality. Is it still in your backlog ? Is it already planned for a future release ?

Thanks for this great project ! Martin.

mlb6 avatar Mar 31 '14 20:03 mlb6

@mlb6 it is on the backlog, but I can't really promise working on it anytime soon. However, I would gladly merge pull requests for this (or any other) issue from the backlog.

alexo avatar Mar 31 '14 21:03 alexo

+1

wmitchellUK avatar Jul 10 '14 18:07 wmitchellUK

+1 any news so far? Unfortunately I'm not that fit in Java to put the changes in by myself :( Maybe the easiest implementation is going for an option to enable source maps when the Closure Compiler is used?

marbetschar avatar Aug 19 '14 10:08 marbetschar

+1

mindhaq avatar Nov 20 '14 18:11 mindhaq

+1

3urdoch avatar Feb 04 '15 09:02 3urdoch

+1

Tunell avatar Feb 24 '15 12:02 Tunell

+1

codeturner avatar May 11 '15 21:05 codeturner

The project was migrated to a new location. The related issue is https://github.com/wro4j/wro4j/issues/517

alexo avatar May 12 '15 06:05 alexo