diff --git a/packages/next/src/build/webpack/plugins/terser-webpack-plugin/src/index.ts b/packages/next/src/build/webpack/plugins/terser-webpack-plugin/src/index.ts index 96f847c2a94c4..771a4fde89e51 100644 --- a/packages/next/src/build/webpack/plugins/terser-webpack-plugin/src/index.ts +++ b/packages/next/src/build/webpack/plugins/terser-webpack-plugin/src/index.ts @@ -157,6 +157,9 @@ export class TerserPlugin { : {}), compress: true, mangle: true, + output: { + comments: false, + }, } ) diff --git a/test/production/terser-class-static-blocks/pages/index.tsx b/test/production/terser-class-static-blocks/pages/index.tsx index 0f01124d81306..19e0183d4c580 100644 --- a/test/production/terser-class-static-blocks/pages/index.tsx +++ b/test/production/terser-class-static-blocks/pages/index.tsx @@ -1,3 +1,10 @@ +/** + * My JSDoc comment that should be minified away + * + * @author Example One + * @author Example Two + * @copyright 2024 Vercel Inc + */ class TestClass { static text = 'hello world' } diff --git a/test/production/terser-class-static-blocks/terser-class-static-blocks.test.ts b/test/production/terser-class-static-blocks/terser-class-static-blocks.test.ts index 473f075cbe2a4..b47c11bbd5c1a 100644 --- a/test/production/terser-class-static-blocks/terser-class-static-blocks.test.ts +++ b/test/production/terser-class-static-blocks/terser-class-static-blocks.test.ts @@ -1,7 +1,9 @@ +import glob from 'glob' import { nextTestSetup } from 'e2e-utils' +import path from 'path' describe('terser-class-static-blocks', () => { - const { next } = nextTestSetup({ + const { next, isNextDeploy } = nextTestSetup({ files: __dirname, nextConfig: { swcMinify: false, @@ -11,4 +13,27 @@ describe('terser-class-static-blocks', () => { const $ = await next.render$('/') expect($('p').text()).toBe('hello world') }) + + if (!isNextDeploy) { + it('should have stripped away all comments', async () => { + const chunksDir = path.join(next.testDir, '.next/static') + const chunks = glob.sync('**/*.js', { + cwd: chunksDir, + }) + + expect(chunks.length).toBeGreaterThan(0) + + await Promise.all( + chunks.map(async (chunk) => { + expect( + await next.readFile(path.join('.next/static', chunk)) + ).not.toContain('/*') + + expect( + await next.readFile(path.join('.next/static', chunk)) + ).not.toContain('My JSDoc comment that') + }) + ) + }) + } })