-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
de00222
commit eed3cec
Showing
3 changed files
with
44 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 34 additions & 13 deletions
47
test/production/terser-class-static-blocks/terser-class-static-blocks.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
import glob from 'glob' | ||
import { nextTestSetup } from 'e2e-utils' | ||
import path from 'path' | ||
|
||
createNextDescribe( | ||
'terser-class-static-blocks', | ||
{ | ||
describe('terser-class-static-blocks', () => { | ||
const { next, isNextDeploy } = nextTestSetup({ | ||
files: __dirname, | ||
nextConfig: { | ||
swcMinify: false, | ||
}, | ||
}, | ||
({ next }) => { | ||
it('should work using cheerio', async () => { | ||
const $ = await next.render$('/') | ||
expect($('p').text()).toBe('hello world') | ||
nextConfig: {}, | ||
}) | ||
|
||
it('should work using cheerio', async () => { | ||
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') | ||
}) | ||
) | ||
}) | ||
} | ||
) | ||
}) |