How can I remove License comment from the bundle generated by js.Build?

I’m trying to handle assets via Hugo pipes, but I found that there is a license comment in the final bundle.
How can I remove it?

Why would you want to?

2 Likes

I want to exclude all comments from the bundle, in order to reduce bundle size.
I used webpack for building assets, it provides an option extractComments for doing that.
So I hope that Hugo could provide a similar option.

Using postcss helps.

1 Like

I just realised that you asked for js.Build, not CSS. So, I don’t think you can remove comments with the current esbuild setup in Hugo. If it would be automatically remove all inline comments it would probably not remove /*! */ comments.

But you could move to Babel and there in the babelrc config just write

{
  comments: false
}

and all should be good.

1 Like

In most cases you are violating the license by removing it. That’s why most minifiers retain the license by default. Go find those extra bytes somewhere else.

3 Likes

Thanks for your reminding, I just Google it, found a post Is it legal and ethical to remove license notices from third-party. I didn’t think about it before. I’ll preserve those license’s comments.

Thanks for your reply, I decided to preserve those comments for obeying the license.

ESBuild does have an option for this esbuild - API

… but Hugo does not expose it.

3 Likes

If you use them for your private project there is nothing to obey. If you sell your theme or publish it you will have to include the license into the files shipped (also depending on the license type, some don’t even require that), NOT the final product that will be deployed on the servers of your customers. I can’t think of any license right now that demands me to have its license string inside of the actual files when I use it.

It’s something different if a theme author requires you to have a back link to their site if you use their theme for free or any other explicit license requirement.

Could Hugo expose this option(linked)? Currently, the final bundle contains too many licenses comments. I think linked would be better.

---- JS CODE ----
/*!
  * Bootstrap base-component.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap data.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap dropdown.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap event-handler.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap manipulator.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap modal.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap offcanvas.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap selector-engine.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */
/*!
  * Bootstrap tab.js v5.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  */

I’m maintaining a theme(under MIT license), and I use some third-party packages, such as Bootstrap, FontAwesome. I’m confused by this. Is it legal that store the licenses somewhere else instead of the bundle? Such as append those licenses to LICENSE.txt. If so, should I also publish the LICENSE.txt(static/LICENSE.txt), so that anyone can access the LICENSE.txt on the sites using my theme?

As long as you have the original files of Bootstrap and FontAwesome in your project (not so sure about the Font Awesome license) you are good to go because they contain the license. If you only “ship” the compiled version of your JS and CSS you either add a section to your Readme or the License with a note where you copy the full license of the library used.

I am trying to find a sample of that in the wild.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.