Unverified Commit 121bd6a1 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure we match comment minify behavior between terser and swc (#68372)

Currently we are only strip all comments properly when `swcMinify:
false` is set although the default is to use `swcMinify` which can cause
confusion with these two modes not matching comments handling.

This updates the default to match comment stripping between the two and
also adds an experimental config to allow toggling this regardless of
which minifier is being used.

x-ref: [slack
thread](https://vercel.slack.com/archives/C0676QZBWKS/p1722444791037279)
x-ref: NEXT-3642
parent e9990a6a
......@@ -147,6 +147,9 @@ export class TerserPlugin {
compress: true,
mangle: true,
module: 'unknown',
output: {
comments: false,
},
}
)
......
/**
* My JSDoc comment that should be minified away
*
* @author Example One <example1@example.com>
* @author Example Two <example2@example.com>
* @copyright 2024 Vercel Inc
*/
class TestClass {
static text = 'hello world'
}
......
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: {},
})
......@@ -10,4 +12,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')
})
)
})
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment