Svelte bundle.js 很大,充满了@license 注释,即使在生产模式下也是如此

Svelte bundle.js is large, full of @license comments, even in production mode

>npm run build 在一个中等大小的 Svelte 项目上生成一个大的 public/build/bundle.js 文件。 Javascript 代码被最小化为一系列单行代码

function(t){return new qr((function(e){...

但在每一行之间(有时在中间)都是一个很大的许可证注释块

 * @license
 * Copyright 2018 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 ... 9 more lines
 * limitations under the License.

日期各不相同,2017-2019。还有一些 Microsoft 许可证。代码中散布着大约 70 个这样的许可证,使其膨胀到 800kb。

我没有弄乱汇总配置或任何东西。 这是 package.json 个相关部分:

"scripts": {
    "build": "rollup -c",
    "dev": "rollup -c -w",
    "start": "sirv public"
  },
  "devDependencies": {
    "@rollup/plugin-commonjs": "^11.0.0",
    "@rollup/plugin-node-resolve": "^7.0.0",
    "rollup": "^1.20.0",
    "rollup-plugin-livereload": "^1.0.0",
    "rollup-plugin-svelte": "^5.0.3",
    "rollup-plugin-terser": "^5.1.2",
    "svelte": "^3.0.0",
    "svelte-mui": "^0.3.3"
  },

我试过删除 node_modules 并重做 npm install 但没有效果。我 运行 Windows 10 如果重要的话。

Svelte 官方模板使用 terser 进行缩小,在生产模式下 运行 (npm run build)。

显然,默认情况下,terser 保留许可注释(来自他们的 docs):

--comments [filter]         Preserve copyright comments in the output. By
                            default this works like Google Closure, keeping
                            JSDoc-style comments that contain "@license" or
                            "@preserve". You can optionally pass one of the
                            following arguments to this flag:
                            - "all" to keep all comments
                            - `false` to omit comments in the output
                            - a valid JS RegExp like `/foo/` or `/^!/` to
                            keep only matching comments.
                            Note that currently not *all* comments can be
                            kept when compression is on, because of dead
                            code removal or cascading statements into
                            sequences.

由于您发布的评论示例包含 @license 标签,我坚信这就是原因。

您应该能够通过在 Rollup 配置中向 terser 插件添加选项来删除这些评论(不知道这样做的合法性):

        production && terser({ output: { comments: false } })