Minify: Babili should strip license comments from source files

Created on 1 Feb 2017  路  4Comments  路  Source: babel/minify

I have license comments in all source files and, currently, Babili is producing such an output:

image

What I would like to have is a single license header at the top of the entire file (possibly added by some additional Webpack plugin or something) and no other license comments.

PS. I know that doesn't matter for gzipped size, but nevertheless, those comments are unnecessary.

question

All 4 comments

By default /licen(s|c)e|preserve/ comments are preserved. You can use shouldPrintComment of babel to remove all comments. http://babeljs.io/docs/usage/api/#options

Thanks.

I forgot to mention that I knew about that option. However, it's a bit inconvenient that Babili's preset doesn't configure Babel to clean up those comments because if you use Babili there's a huge chance that you don't want them.

It's not a big deal, of course, but it felt odd to me.

@boopathi I still don't understand how this to get this working?

main.js

/**
 * @license
 * Copyright (c) roydukkey. All rights reserved.
 * Licensed under the GNU General Public License, Version 3.0.
 */

console.log('test');

main.min.js

console.log("test");

Babel Config

{
    "presets": [
        [ "minify" ]
    ]
}

@boopathi I still don't understand how this to get this working?

@roydukkey, Yeah, it's pretty simply but it's not obvious from the documentation.

Here's what I'm using:

const preserveImportant = comment => /licen[sc]e|copyright|@preserve|^!/i.test(comment);
const minifyJs = { presets: ['minify'], shouldPrintComment: preserveImportant };
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bosens-China picture bosens-China  路  4Comments

Gustorn picture Gustorn  路  4Comments

curiousdannii picture curiousdannii  路  3Comments

callym picture callym  路  4Comments

boopathi picture boopathi  路  3Comments