Skip to content

Problem with sourcemaps #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tonygustafsson opened this issue May 9, 2015 · 5 comments
Closed

Problem with sourcemaps #7

tonygustafsson opened this issue May 9, 2015 · 5 comments

Comments

@tonygustafsson
Copy link

When I use sourcemaps in less, I get Unexpected token error in source-map-consumer.js:20.

@lukeapage
Copy link
Member

Please can you provide more information?

@XhmikosR
Copy link
Contributor

I'm not sure the current code does what it's supposed to...:

            if (sourceMap) {
                var sourceMapURL = sourceMap.getSourceMapURL();
                css += sourceMap.getCSSAppendage();
            }

sourceMapURL is assigned but never used.

@rjgotten
Copy link

I'm not sure the current code does what it's supposed to

It doesn't.

There's a lot of needlessly complicated (and partially incomplete!) manual processing where sourcemap JSON is turned back into objects and sources and sourcesContent arrays are being manually merged, when all you need to do is wrap the input map into a SourceMapConsumer and apply that to the source map generator using applySourceMap:

process : function ( css, extra ) {
  var
    options    = this.options,
    sourceMaps = extra.sourceMap,
    inputMap   = sourceMaps && sourceMaps.getExternalSourceMap(),
    output;

  options.processImport = false;

  if ( typeof options.keepSpecialComments === "undefined" ) {
    options.keepSpecialComments = "*";
  }

  if ( typeof options.rebase === "undefined" ) {
    options.rebase = false;
  }

  if ( typeof options.advanced === "undefined" ) {
    options.advanced = false;
  }

  if ( inputMap ) {
    // Strip existing source map URL, or it may end up in sourcesContent.
    css = css.replace( /\/\*\# sourceMappingURL=.*\*\/$/, "" );
  }

  var output = new CleanCSS( options ).minify( css );

  if ( inputMap ) {
    output.sourceMap.applySourceMap(
      new SourceMapConsumer( inputMap ),
      sourceMaps.getOutputFileName() || ""
    );

    sourceMaps.setExternalSourceMap( output.sourceMap.toString());
    output.styles += sourceMaps.getCSSAppendage();
  }

  return output.styles;
}

@XhmikosR
Copy link
Contributor

@rjgotten: please submit a PR and ping me.

@Badestrand
Copy link

Any progress? I can't use this plugin as well as it messes with the source map path somehow (Error: ENOENT: no such file or directory, open '[root-dir]/bundle.css.map').

BenLubar added a commit to BenLubar/less-plugin-clean-css that referenced this issue Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants