问题
there is this cool feature Source Maps in html5. In my Symfony2 project I use jQuery mobile which uses this feature (I use the BmatznerJQueryMobileBundle for integration).
In my <head>
i do following:
{% javascripts
'@BmatznerJQueryBundle/Resources/public/js/jquery.min.js'
'@BmatznerJQueryMobileBundle/Resources/public/js/jquery.mobile.min.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
This works fine for the js files, but Chrome gets an 404 error trying to get the source maping file. Does anybody know how to solve this?
The Source Mapping in the jquery.mobile.min.js file looks like this and is also in the same directory.
//# sourceMappingURL=jquery.mobile-1.4.2.min.map
error:
回答1:
The problem with your example is that you are combining two sources into one, and from two different locations. If you look at the generated script tags in your dev environment, you'll see that the two routes are something like:
<script src="/js/ed5a632_jquery.min_1.js"></script>
<script src="/js/ed5a632_jquery.mobile.min_2.js"></script>
Assetic does not create matching routes for source maps, so these files now have invalid sourceMappingURL
values - hence your 404.
One solution is to export the source maps (and sources) to a location relative to the dynamic routes using the assetic.assets
configuration:
ref: https://github.com/symfony/symfony/pull/848
e.g. config.yml
assetic:
assets:
map1:
input: "%kernel.root_dir%/../src/path/to/jquery.min.map"
output: js/jquery.min.map
src1:
input: "%kernel.root_dir%/../src/path/to/jquery.js"
output: js/jquery.js
This will ensure the sourceMappingURL is hit, but it's a bit of a mess having all this separate from your template code.
If you can live with two separate assets in your production site, a much simpler solution is to just reference the two assets individually, e.g.
<script src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
<script src="{{ asset('bundles/bmatznerjquerymobile/js/jquery.mobile.min.js') }}"></script>
After running the assets:install
console command, these scripts should link just fine to the source maps and source files.
来源:https://stackoverflow.com/questions/24172391/source-mapping-with-assetic-in-symfony2