localvoid / autoprefixer_transformer

Dart `pub` transformer that parses css and adds vendor prefixes to CSS rules
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

Cannot open file error for source maps #2

Open danschultz opened 9 years ago

danschultz commented 9 years ago

When running pub build the transformer errors when it tries to open the source map.

I'm using autoprefixer version 5.1.0.

dan$ pub build
Loading source assets... 
Loading di/module_transformer and autoprefixer_transformer transformers... 
Building isomorphic_dart... 
Build error:
Transform  on isomorphic_dart|isomorphic_dart|web/styles/main.css threw error: Cannot open file, path = '/var/folders/w5/9yzcfn6d5pnd7bvj0qlnw0580000gq/T/autoprefixer-transformer-42yfxC/main.css.map' (OS Error: No such file or directory, errno = 2)
dart:io/file_impl.dart 354                 _File.open.<fn>
dart:async/zone.dart 1155                  _RootZone.runUnary
dart:async/future_impl.dart 484            _Future._propagateToListeners.handleValueCallback
dart:async/future_impl.dart 567            _Future._propagateToListeners
dart:async/future_impl.dart 358            _Future._completeWithValue
dart:async/future_impl.dart 412            _Future._asyncComplete.<fn>
dart:async/schedule_microtask.dart 41      _asyncRunCallbackLoop
dart:async/schedule_microtask.dart 48      _asyncRunCallback
dart:isolate-patch/isolate_patch.dart 96   _runPendingImmediateCallback
dart:isolate-patch/isolate_patch.dart 143  _RawReceivePortImpl._handleMessage

dart:isolate  _RawReceivePortImpl._handleMessage
danschultz commented 9 years ago

Looks like version 5.1.0 inlines the source maps as a data uri.

Running autoprefixer -m -o main.prefixed.css main.css will output:

.movie-detail .poster-image {
  min-width: 200px;
  width: 200px;
}

.movie-detail .poster-image:empty {
  height: 300px;
}
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0VBQ0UsMkJBQTBCO0VBQzFCLHNCQUFjO0VBQWQsdUJBQWM7RUFBZCxzQkFBYztFQUFkLGVBQWM7RUFDZCwwQkFBd0I7RUFBeEIsaUNBQXdCO01BQXhCLH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bGlkIGdyZXk7XG4gIHBhZGRpbmctcmlnaHQ6IDAuNWVtO1xufVxuXG4ubW92aWUtbWV0YTpub3QoOmZpcnN0LWNoaWxkKSB7XG4gIHBhZGRpbmctbGVmdDogMC41ZW07XG59XG5cbi5tb3ZpZS1tZXRhLWl0ZW1zLCAubW92aWUtY3JlZGl0IHtcbiAgbWFyZ2luOiAwLjc1ZW0gMDtcbn1cblxuLnBvc3Rlci1pbWFnZSB7XG4gIGJhY2tncm91bmQtY29sb3I6IGxpZ2h0Z3JleTtcbiAgZGlzcGxheTogaW5saW5lLWJsb2NrO1xuICBtYXJnaW4tcmlnaHQ6IDFlbTtcbn1cblxuLnBvc3Rlci1pbWFnZSBpbWcge1xuICB3aWR0aDogMTAwJTtcbn1cblxuLm1vdmllLXN1bW1hcnkgLnBvc3Rlci1pbWFnZSB7XG4gIG1pbi13aWR0aDogNzVweDtcbiAgd2lkdGg6IDc1cHg7XG59XG5cbi5tb3ZpZS1zdW1tYXJ5IC5wb3N0ZXItaW1hZ2U6ZW1wdHkge1xuICBoZWlnaHQ6IDEwOHB4O1xufVxuXG4ubW92aWUtZGV0YWlsIC5wb3N0ZXItaW1hZ2Uge1xuICBtaW4td2lkdGg6IDIwMHB4O1xuICB3aWR0aDogMjAwcHg7XG59XG5cbi5tb3ZpZS1kZXRhaWwgLnBvc3Rlci1pbWFnZTplbXB0eSB7XG4gIGhlaWdodDogMzAwcHg7XG59Il19 */

There's an option --no-inline-map that doesn't inline the source maps.

danschultz commented 9 years ago

According to the change log, they started to inline source maps starting with version 4.

I find this default a bit puzzling as it increases the size of the outputted CSS, and would require separate options for dev/production builds. Would seem better to just output a separate map file by default and have clients decide if they wanted to load source maps or not. I couldn't find anything in their issue tracker that describes the motivation behind this change.

I'll submit a PR that adds --no-inline-map when calling autoprefixer.

localvoid commented 9 years ago

I am not sure why they've started to inline source maps, but it is way much easier to implement transformers that doesn't need to search for existing source maps. Right now, this transformer can find existing source maps only when they have the same base path as css file. I'd prefer to get rid of temp directories, etc, and just use inline source maps everywhere. Do we really need to support source maps that aren't inlined and also generate "no-inline" version?

localvoid commented 9 years ago

I've uploaded new version to pub with your PR, but I really want to remove support for source maps that aren't inlined. It is possible just to implement one more transformer that will work as a last step in css transformations, it will remove inline css and generate two separate files .css and .map.

danschultz commented 9 years ago

I think the implementation you have at dccdd0f7971445b8448f9ba4fbe2e3e788d9bc99 (v0.3) is a good default. I'd still like to have the option of generating a separate source map file for debugging CSS in production.

How did you see the additional transformer as working?

localvoid commented 9 years ago

Just simple transformer that reads .css files and if it finds inline source map, it will remove it and create .map file. Something like this: https://github.com/localvoid/source_map_transformer

So we can just use inline source maps everywhere in our css pipeline:

transformers:
- sass
- autoprefixer_transformer:
    browsers:
    - "last 2 versions"
- clean_css_transformer:
    source_map: true
- source_map_transformer:
    source_map: true