Skip to content
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

Remove all whitespace related to comments #68

Open
wll8 opened this issue Sep 13, 2021 · 2 comments
Open

Remove all whitespace related to comments #68

wll8 opened this issue Sep 13, 2021 · 2 comments

Comments

@wll8
Copy link

wll8 commented Sep 13, 2021

Remove all whitespace related to comments

Source code:

const obj = {
  // Here are some code comments
  name: `js`,
  /**
   * Here are some code comments
   */
  v: `es6`,
}

Conversion options:

  • strip-comments@2.0.1
const outStr = strip(str, {
  preserveNewlines: false,
});

Actual output:

const obj = {
  
  name: `js`,
    v: `es6`,
}

Note: v There is a blank character before the key, but it is not in the source code. Is this a bug?

Expected output:

const obj = {
  name: `js`,
  v: `es6`,
}
@MattBuilt1
Copy link

I know this is really old, but in case anyone else comes across it. I couldn't get the preserveNewlines: false to work so added this:

const cleanScript = strip(script).replace(/[\r\n]+/gm, '\n');

More on the regex here: https://www.geeksforgeeks.org/how-to-remove-all-line-breaks-from-a-string-using-javascript/

@wll8
Copy link
Author

wll8 commented Jun 15, 2023

Try this tool: remove-comments

  • Supports batch processing of files using the glob method
  • Delete single-line multi-line comments from html, js, json, css/text
  • Keep the layout/format of the original document
  • Delete lines with only comments
  • Compatible with css3, json5, es6
  • Support mixed content, such as js/css in html/vue

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

2 participants