Parcel: Prevent parcel from strippings comments on specific lines in source file?

Created on 4 Sep 2018  ยท  1Comment  ยท  Source: parcel-bundler/parcel

โ” Question

How to prevent parcel from strippings comments from specific lines in source file?

๐Ÿ”ฆ Context


I am creating a website which contains a code editor. The code editor will have some code in it by default. I would rather not encode the code into a string (in order to pass it into the editor.session.setValue() function) using an online encoder. Instead, I would like to just write the code and use the .toString() in order to get a string representation of the code. However, parcel build will strip out the comments, which is problematic, because I need the comments.

๐Ÿ’ป Code Sample

Ideal Code:

let afunc = () => {
   //Print hello world - this comment will not be removed 
    console.log("hello world")
}
editor.session.setValue(afunc.toString())

What actually happens in the above example is that the comment is removed.

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel |
| Node |
| npm/Yarn |
| Operating System |

Waiting Question

Most helpful comment

Parcel supports customizing terser options, see possible options here https://github.com/fabiosantoscode/terser#output-options

An example to not remove comments:

.terserrc

{
  "output": {
    "comments": "put some regex here"
  }
}

>All comments

Parcel supports customizing terser options, see possible options here https://github.com/fabiosantoscode/terser#output-options

An example to not remove comments:

.terserrc

{
  "output": {
    "comments": "put some regex here"
  }
}
Was this page helpful?
0 / 5 - 0 ratings